Main Section

From TRCCompSci - AQA Computer Science
Revision as of 13:28, 30 November 2016 by Admin (talk | contribs) (Created page with "==The Code== <syntaxhighlight lang="csharp" line> static void Main(string[] args) { Simulation Sim; int MenuOption; int LandscapeSize; int InitialW...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

The Code

 1 static void Main(string[] args)
 2     {
 3       Simulation Sim;
 4       int MenuOption;
 5       int LandscapeSize;
 6       int InitialWarrenCount;
 7       int InitialFoxCount;
 8       int Variability;
 9       bool FixedInitialLocations;
10       do
11       {
12         Console.WriteLine("Predator Prey Simulation Main Menu");
13         Console.WriteLine();
14         Console.WriteLine("1. Run simulation with default settings");
15         Console.WriteLine("2. Run simulation with custom settings");
16         Console.WriteLine("3. Exit");
17         Console.WriteLine();
18         Console.Write("Select option: ");
19         MenuOption = Convert.ToInt32(Console.ReadLine());
20         if ((MenuOption == 1) || (MenuOption == 2))
21         {
22           if (MenuOption == 1)
23           {
24             LandscapeSize = 15;
25             InitialWarrenCount = 5;
26             InitialFoxCount = 5;
27             Variability = 0;
28             FixedInitialLocations = true;
29           }
30           else
31           {
32             Console.Write("Landscape Size: ");
33             LandscapeSize = Convert.ToInt32(Console.ReadLine());
34             Console.Write("Initial number of warrens: ");
35             InitialWarrenCount = Convert.ToInt32(Console.ReadLine());
36             Console.Write("Initial number of foxes: ");
37             InitialFoxCount = Convert.ToInt32(Console.ReadLine());
38             Console.Write("Randomness variability (percent): ");
39             Variability = Convert.ToInt32(Console.ReadLine());
40             FixedInitialLocations = false;
41           }
42           Sim = new Simulation(LandscapeSize, InitialWarrenCount, InitialFoxCount, Variability, FixedInitialLocations);
43         }
44       } while (MenuOption != 3);
45       Console.ReadKey();
46     }

Explanation

The main program declares an instance of the Simulation Class.

It creates variables for the key information required for the simulation.

The option is to start with the predefined values or to enter the values yourself. If option 1 or 2 are selected the instance of the Simulation Class will be assigned the values predefined or entered by the user.