Difference between revisions of "Add code to have Severe Flood in SimulateAutumn"

From TRCCompSci - AQA Computer Science
Jump to: navigation, search
(Created page with "<syntaxhighlight lang = CSharp line> static void SimulateAutumn(char[,] Field) { int PlantCount = 0; bool Flood = false; for (int Row = 0; Row <...")
 
 
Line 1: Line 1:
 +
Add the bool Flood code to the start of the SimulateAutumn subroutine.
 +
 
<syntaxhighlight lang = CSharp line>
 
<syntaxhighlight lang = CSharp line>
 
static void SimulateAutumn(char[,] Field)
 
static void SimulateAutumn(char[,] Field)
 
     {
 
     {
 +
        bool Flood = false;
  
        int PlantCount = 0;
+
</syntaxhighlight>
        bool Flood = false;
 
  
        for (int Row = 0; Row < FIELDLENGTH; Row++)
+
Add code to randomize the chance for a flood after initial field set up.
        {
 
            for (int Column = 0; Column < FIELDWIDTH; Column++)
 
            {
 
                if (Field[Row, Column] == PLANT)
 
                {
 
                    SeedLands(Field, Row - 1, Column - 1);
 
                    SeedLands(Field, Row - 1, Column);
 
                    SeedLands(Field, Row - 1, Column + 1);
 
                    SeedLands(Field, Row, Column - 1);
 
                    SeedLands(Field, Row, Column + 1);
 
                    SeedLands(Field, Row + 1, Column - 1);
 
                    SeedLands(Field, Row + 1, Column);
 
                    SeedLands(Field, Row + 1, Column + 1);
 
                }
 
            }
 
        }
 
  
            CountPlants(Field);
+
<syntaxhighlight lang = CSharp line>
  
 
             Random RandomInt = new Random();
 
             Random RandomInt = new Random();

Latest revision as of 13:38, 10 March 2017

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         }