Add code to have Severe Flood in SimulateAutumn

From TRCCompSci - AQA Computer Science
Jump to: navigation, search

Add the bool Flood code to the start of the SimulateAutumn subroutine.

1 static void SimulateAutumn(char[,] Field)
2     {
3         bool Flood = false;

Add code to randomize the chance for a flood after initial field set up.

 1             Random RandomInt = new Random();
 2 
 3             if (RandomInt.Next(0, 2) == 1)
 4             {
 5                 Flood = true;
 6             }
 7 
 8             else
 9             {
10                 Flood = false;
11             }
12 
13             if (Flood)
14             {
15                 PlantCount = 0;
16                 for (int Row = 0; Row < FIELDLENGTH; Row++)
17                 {
18                     for (int Column = 0; Column < FIELDWIDTH; Column++)
19                     {
20                         if (Field[Row, Column] == PLANT)
21                         {
22                             PlantCount++;
23                             if (PlantCount % 3 == 0)
24                             {
25                                 Field[Row, Column] = SOIL;
26                             }
27                         }
28                     }
29                 }
30                 Console.WriteLine("There has been a flood, this has effected plant growth:");
31                 CountPlants(Field);
32             }
33         }