Difference between revisions of "SimulateSummer - AS 2017"
(Created page with "==The Code== <syntaxhighlight lang=Csharp> </syntaxhighlight> ==Explanation==") |
|||
Line 2: | Line 2: | ||
<syntaxhighlight lang=Csharp> | <syntaxhighlight lang=Csharp> | ||
− | + | static void SimulateSummer(char[,] Field) | |
+ | { | ||
+ | Random RandomInt = new Random(); | ||
+ | int RainFall = RandomInt.Next(0, 3); | ||
+ | int PlantCount = 0; | ||
+ | if (RainFall == 0) | ||
+ | { | ||
+ | PlantCount = 0; | ||
+ | for (int Row = 0; Row < FIELDLENGTH; Row++) | ||
+ | { | ||
+ | for (int Column = 0; Column < FIELDWIDTH; Column++) | ||
+ | { | ||
+ | if (Field[Row, Column] == PLANT) | ||
+ | { | ||
+ | PlantCount++; | ||
+ | if (PlantCount % 2 == 0) | ||
+ | { | ||
+ | Field[Row, Column] = SOIL; | ||
+ | } | ||
+ | } | ||
+ | } | ||
+ | } | ||
+ | Console.WriteLine("There has been a severe drought"); | ||
+ | CountPlants(Field); | ||
+ | } | ||
+ | } | ||
</syntaxhighlight> | </syntaxhighlight> | ||
==Explanation== | ==Explanation== |
Latest revision as of 10:34, 3 March 2017
The Code
static void SimulateSummer(char[,] Field)
{
Random RandomInt = new Random();
int RainFall = RandomInt.Next(0, 3);
int PlantCount = 0;
if (RainFall == 0)
{
PlantCount = 0;
for (int Row = 0; Row < FIELDLENGTH; Row++)
{
for (int Column = 0; Column < FIELDWIDTH; Column++)
{
if (Field[Row, Column] == PLANT)
{
PlantCount++;
if (PlantCount % 2 == 0)
{
Field[Row, Column] = SOIL;
}
}
}
}
Console.WriteLine("There has been a severe drought");
CountPlants(Field);
}
}