Difference between revisions of "SimulateSpring - AS 2017"

From TRCCompSci - AQA Computer Science
Jump to: navigation, search
(Created page with "==The Code== <syntaxhighlight lang=Csharp> </syntaxhighlight> ==Explanation==")
 
 
Line 2: Line 2:
  
 
<syntaxhighlight lang=Csharp>
 
<syntaxhighlight lang=Csharp>
 
+
static void SimulateSpring(char[,] Field)
 +
{
 +
    int PlantCount = 0;
 +
    bool Frost = false;
 +
    for (int Row = 0; Row < FIELDLENGTH; Row++)
 +
    {
 +
        for (int Column = 0; Column < FIELDWIDTH; Column++)
 +
        {
 +
            if (Field[Row, Column] == SEED)
 +
            {
 +
                Field[Row, Column] = PLANT;
 +
            }
 +
        }
 +
    }
 +
    CountPlants(Field);
 +
    Random RandomInt = new Random();
 +
    if (RandomInt.Next(0, 2) == 1)
 +
    {
 +
        Frost = true;
 +
    }
 +
    else
 +
    {
 +
        Frost = false;
 +
    }
 +
    if (Frost)
 +
    {
 +
        PlantCount = 0;
 +
        for (int Row = 0; Row < FIELDLENGTH; Row++)
 +
        {
 +
            for (int Column = 0; Column < FIELDWIDTH; Column++)
 +
            {
 +
                if (Field[Row, Column] == PLANT)
 +
                {
 +
                    PlantCount++;
 +
                    if (PlantCount % 3 == 0)
 +
                    {
 +
                        Field[Row, Column] = SOIL;
 +
                    }
 +
                }
 +
            }
 +
        }
 +
        Console.WriteLine("There has been a frost");
 +
        CountPlants(Field);
 +
    }
 +
}
 
</syntaxhighlight>
 
</syntaxhighlight>
  
 
==Explanation==
 
==Explanation==

Latest revision as of 09:32, 3 March 2017

The Code

static void SimulateSpring(char[,] Field)
{
    int PlantCount = 0;
    bool Frost = false;
    for (int Row = 0; Row < FIELDLENGTH; Row++)
    {
        for (int Column = 0; Column < FIELDWIDTH; Column++)
        {
            if (Field[Row, Column] == SEED)
            {
                Field[Row, Column] = PLANT;
            }
        }
    }
    CountPlants(Field);
    Random RandomInt = new Random();
    if (RandomInt.Next(0, 2) == 1)
    {
        Frost = true;
    }
    else
    {
        Frost = false;
    }
    if (Frost)
    {
        PlantCount = 0;
        for (int Row = 0; Row < FIELDLENGTH; Row++)
        {
            for (int Column = 0; Column < FIELDWIDTH; Column++)
            {
                if (Field[Row, Column] == PLANT)
                {
                    PlantCount++;
                    if (PlantCount % 3 == 0)
                    {
                        Field[Row, Column] = SOIL;
                    }
                }
            }
        }
        Console.WriteLine("There has been a frost");
        CountPlants(Field);
    }
}

Explanation