Difference between revisions of "Simulation - AS 2017"
(Created page with "==The Code== <syntaxhighlight lang=Csharp> </syntaxhighlight> ==Explanation==") |
|||
Line 2: | Line 2: | ||
<syntaxhighlight lang=Csharp> | <syntaxhighlight lang=Csharp> | ||
− | + | private static void Simulation() | |
+ | { | ||
+ | int YearsToRun; | ||
+ | char[,] Field = new char[FIELDLENGTH, FIELDWIDTH]; | ||
+ | bool Continuing; | ||
+ | int Year; | ||
+ | string Response; | ||
+ | YearsToRun = GetHowLongToRun(); | ||
+ | if (YearsToRun != 0) | ||
+ | { | ||
+ | InitialiseField(Field); | ||
+ | if (YearsToRun >= 1) | ||
+ | { | ||
+ | for (Year = 1; Year <= YearsToRun; Year++) | ||
+ | { | ||
+ | SimulateOneYear(Field, Year); | ||
+ | } | ||
+ | } | ||
+ | else | ||
+ | { | ||
+ | Continuing = true; | ||
+ | Year = 0; | ||
+ | while (Continuing) | ||
+ | { | ||
+ | Year++; | ||
+ | SimulateOneYear(Field, Year); | ||
+ | Console.Write("Press Enter to run simulation for another Year, Input X to stop: "); | ||
+ | Response = Console.ReadLine(); | ||
+ | if (Response == "x" || Response == "X") | ||
+ | { | ||
+ | Continuing = false; | ||
+ | } | ||
+ | } | ||
+ | } | ||
+ | Console.WriteLine("End of Simulation"); | ||
+ | } | ||
+ | Console.ReadLine(); | ||
+ | } | ||
</syntaxhighlight> | </syntaxhighlight> | ||
==Explanation== | ==Explanation== |
Latest revision as of 10:39, 3 March 2017
The Code
private static void Simulation()
{
int YearsToRun;
char[,] Field = new char[FIELDLENGTH, FIELDWIDTH];
bool Continuing;
int Year;
string Response;
YearsToRun = GetHowLongToRun();
if (YearsToRun != 0)
{
InitialiseField(Field);
if (YearsToRun >= 1)
{
for (Year = 1; Year <= YearsToRun; Year++)
{
SimulateOneYear(Field, Year);
}
}
else
{
Continuing = true;
Year = 0;
while (Continuing)
{
Year++;
SimulateOneYear(Field, Year);
Console.Write("Press Enter to run simulation for another Year, Input X to stop: ");
Response = Console.ReadLine();
if (Response == "x" || Response == "X")
{
Continuing = false;
}
}
}
Console.WriteLine("End of Simulation");
}
Console.ReadLine();
}