Add code to have Severe Flood in SimulateAutumn

From TRCCompSci - AQA Computer Science
Revision as of 12:30, 10 March 2017 by LilyDunn (talk | contribs) (Created page with "<syntaxhighlight lang = CSharp line> static void SimulateAutumn(char[,] Field) { int PlantCount = 0; bool Flood = false; for (int Row = 0; Row <...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search
 1 static void SimulateAutumn(char[,] Field)
 2     {
 3 
 4         int PlantCount = 0;
 5         bool Flood = false;
 6 
 7         for (int Row = 0; Row < FIELDLENGTH; Row++)
 8         {
 9             for (int Column = 0; Column < FIELDWIDTH; Column++)
10             {
11                 if (Field[Row, Column] == PLANT)
12                 {
13                     SeedLands(Field, Row - 1, Column - 1);
14                     SeedLands(Field, Row - 1, Column);
15                     SeedLands(Field, Row - 1, Column + 1);
16                     SeedLands(Field, Row, Column - 1);
17                     SeedLands(Field, Row, Column + 1);
18                     SeedLands(Field, Row + 1, Column - 1);
19                     SeedLands(Field, Row + 1, Column);
20                     SeedLands(Field, Row + 1, Column + 1);
21                 }
22             }
23         }
24 
25             CountPlants(Field);
26 
27             Random RandomInt = new Random();
28 
29             if (RandomInt.Next(0, 2) == 1)
30             {
31                 Flood = true;
32             }
33 
34             else
35             {
36                 Flood = false;
37             }
38 
39             if (Flood)
40             {
41                 PlantCount = 0;
42                 for (int Row = 0; Row < FIELDLENGTH; Row++)
43                 {
44                     for (int Column = 0; Column < FIELDWIDTH; Column++)
45                     {
46                         if (Field[Row, Column] == PLANT)
47                         {
48                             PlantCount++;
49                             if (PlantCount % 3 == 0)
50                             {
51                                 Field[Row, Column] = SOIL;
52                             }
53                         }
54                     }
55                 }
56                 Console.WriteLine("There has been a flood, this has effected plant growth:");
57                 CountPlants(Field);
58             }
59         }