Difference between revisions of "Main Section"

From TRCCompSci - AQA Computer Science
Jump to: navigation, search
(Explanation)
 
(3 intermediate revisions by 2 users not shown)
Line 1: Line 1:
 
==The Code==
 
==The Code==
 
 
== YOU HAVE BEEN VISITED BY SHULK, AND HE WAS REALLY FEELING YOUR POST ==
 
[[File:feeling.jpg]]
 
 
 
<tabber>
 
<tabber>
 
C#=
 
C#=
Line 63: Line 58:
  
 
=Explanation=
 
=Explanation=
 
He really felt your post and thought it was worth sharing on his facebook page and status.
 
 
 
The main program declares an instance of the Simulation Class.  
 
The main program declares an instance of the Simulation Class.  
  

Latest revision as of 13:36, 17 December 2016

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 declares 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 is selected the variables will be assigned their default value, however if 2 is selected the values entered by the use will be assigned to the variables.


The instance of the Simulation Class will be assigned the values predefined or entered by the user. This will obviously start the simulation and run the code within that class.