private void DrawComplteForest(Graphics G) { var settingsData = SettingsData.GetInstance(); SolidBrush myBrush = new SolidBrush(myForest.ForestColor); G.FillRectangle(myBrush, 0, 0, settingsData.forestWidth * mySquare.Height, settingsData.forestHeight * mySquare.Width); foreach (Square mySquare in squareMap) { SolidBrush myBrush1 = new SolidBrush(mySquare.SquareColor); G.FillRectangle(myBrush1, mySquare.PositionX, mySquare.PositionY, mySquare.Height - 2, mySquare.Width - 2); } }
private void button1_Click(object sender, EventArgs e) { SettingsData settingsData = SettingsData.GetInstance(); if ((int)numericUpDownForestHeight.Value * (int)numericUpDownForestWidth.Value < (int)numericUpDownNumberOfRocks.Value + (int)numericUpDownNumberOfTrees.Value + (int)numericUpDownNumberOfPlants.Value + (int)numericUpDownNumberOfMaleElephants.Value + (int)numericUpDownNumberOfFemaleElephants.Value + (int)numericUpDownNumberOfMaleLions.Value + (int)numericUpDownNumberOfFemaleLions.Value + (int)numericUpDownNumberOfMaleDeers.Value + (int)numericUpDownNumberOfFemaleDeers.Value) { MessageBox.Show("The numbers of elements inside the forest exceeds its size \n Kindly review your input"); return; } settingsData.timerTick = (int)numericUpDownTimerTicks.Value; settingsData.forestHeight = (int)numericUpDownForestHeight.Value; settingsData.forestWidth = (int)numericUpDownForestWidth.Value; settingsData.numberOfRocks = (int)numericUpDownNumberOfRocks.Value; settingsData.numberOfTrees = (int)numericUpDownNumberOfTrees.Value; settingsData.numberOfPlants = (int)numericUpDownNumberOfPlants.Value; settingsData.numberOfMaleElephants = (int)numericUpDownNumberOfMaleElephants.Value; settingsData.numberOfFemaleElephants = (int)numericUpDownNumberOfFemaleElephants.Value; settingsData.ElephantLifeTime = (int)numericUpDownElephantsLifeTime.Value; settingsData.ElephantStarvationPeriod = (int)numericUpDownElephantsStarvationPeriod.Value; settingsData.ElephantGestationPeriod = (int)numericUpDownElephantsGestationPeriod.Value; settingsData.numberOfMaleLions = (int)numericUpDownNumberOfMaleLions.Value; settingsData.numberOffemaleLions = (int)numericUpDownNumberOfFemaleLions.Value; settingsData.LionsLifeTime = (int)numericUpDownLionsLifeTime.Value; settingsData.LionsStarvationPeriod = (int)numericUpDownLionsStarvationPeriod.Value; settingsData.LionsGestationPeriod = (int)numericUpDownLionsGestationPeriod.Value; settingsData.numberOfMaleDeers = (int)numericUpDownNumberOfMaleDeers.Value; settingsData.numberOfFemaleDeers = (int)numericUpDownNumberOfFemaleDeers.Value; settingsData.DeersLifeTime = (int)numericUpDownDeerLifeTime.Value; settingsData.DeersStarvationPeriod = (int)numericUpDownDeersStarvationPeriod.Value; settingsData.DeersGestationPeriod = (int)numericUpDownDeerGestationPeriod.Value; this.Close(); }
private void pictureBox1_Paint(object sender, PaintEventArgs e) { if (counter1 <= 1) { var settingsData = SettingsData.GetInstance(); timer1.Interval = settingsData.timerTick; myForest = new Forest(); myForest.ForestHeight = settingsData.forestHeight; myForest.ForestWidth = settingsData.forestWidth; mySquare = new Square(); squareMap = new Square[myForest.ForestHeight, myForest.ForestWidth]; Random randomNumber = new Random(); myForest.CreateEmptyForest(mySquare, squareMap); MapObjectCreation.PlaceObjectonMap <MaleElephant>(settingsData.numberOfMaleElephants, randomNumber, squareMap, Color.Gray); MapObjectCreation.PlaceObjectonMap <FemaleElephant>(settingsData.numberOfFemaleElephants, randomNumber, squareMap, Color.LightGray); MapObjectCreation.PlaceObjectonMap <MaleLion>(settingsData.numberOfMaleLions, randomNumber, squareMap, Color.Yellow); MapObjectCreation.PlaceObjectonMap <FemaleLion>(settingsData.numberOffemaleLions, randomNumber, squareMap, Color.LightYellow); MapObjectCreation.PlaceObjectonMap <MaleDeer>(settingsData.numberOfMaleDeers, randomNumber, squareMap, Color.Pink); MapObjectCreation.PlaceObjectonMap <FemaleDeer>(settingsData.numberOfFemaleDeers, randomNumber, squareMap, Color.LightPink); MapObjectCreation.PlaceObjectonMap <Rock>(settingsData.numberOfRocks, randomNumber, squareMap, Color.Black); MapObjectCreation.PlaceObjectonMap <Tree>(settingsData.numberOfTrees, randomNumber, squareMap, Color.Fuchsia); MapObjectCreation.PlaceObjectonMap <Plant>(settingsData.numberOfPlants, randomNumber, squareMap, Color.Orange); DrawComplteForest(e.Graphics); bmp = new Bitmap(pictureBox1.ClientSize.Width, pictureBox1.ClientSize.Height); if (counter == 0) { pictureBox1.Image = bmp; counter++; } } counter1++; }