Difference between revisions of "Selection - 2017"

From TRCCompSci - AQA Computer Science
Jump to: navigation, search
Line 1: Line 1:
L34 - L68, 'Simulation':
+
L34 - L68, 'Simulation':<br />
 +
 
 +
 
 +
Simple selection for the menu system<br />
 +
Takes the menuOption input in a do ... while loop where a console application requests an integer input<br />
  
Simple selection for the menu system
 
Takes the menuOption input in a do ... while loop
 
 
<syntaxhighlight lang="csharp">  
 
<syntaxhighlight lang="csharp">  
 +
      do
 +
      {
 +
        Console.WriteLine();
 +
        Console.WriteLine("1. Advance to next time period showing detail");
 +
        Console.WriteLine("2. Advance to next time period hiding detail");
 +
        Console.WriteLine("3. Inspect fox");
 +
        Console.WriteLine("4. Inspect warren");
 +
        Console.WriteLine("5. Exit");
 +
        Console.WriteLine();
 +
        Console.Write("Select option: ");
 +
        menuOption = Convert.ToInt32(Console.ReadLine());
 
if (menuOption == 1)
 
if (menuOption == 1)
 
         {
 
         {
Line 39: Line 52:
 
           }
 
           }
 
         }
 
         }
 +
      } while (((WarrenCount > 0) || (FoxCount > 0)) && (menuOption != 5));
 +
      Console.ReadKey();
 
</syntaxhighlight>
 
</syntaxhighlight>

Revision as of 12:10, 7 February 2017

L34 - L68, 'Simulation':


Simple selection for the menu system
Takes the menuOption input in a do ... while loop where a console application requests an integer input

 
      do
      {
        Console.WriteLine();
        Console.WriteLine("1. Advance to next time period showing detail");
        Console.WriteLine("2. Advance to next time period hiding detail");
        Console.WriteLine("3. Inspect fox");
        Console.WriteLine("4. Inspect warren");
        Console.WriteLine("5. Exit");
        Console.WriteLine();
        Console.Write("Select option: ");
        menuOption = Convert.ToInt32(Console.ReadLine());
if (menuOption == 1)
        {
          TimePeriod++;
          ShowDetail = true;
          AdvanceTimePeriod();
        }
        if (menuOption == 2)
        {
          TimePeriod++;
          ShowDetail = false;
          AdvanceTimePeriod();
        }
        if (menuOption == 3)
        {
          x = InputCoordinate('x');
          y = InputCoordinate('y');
          if (Landscape[x, y].Fox != null)
          {
            Landscape[x, y].Fox.Inspect();
          }
        }
        if (menuOption == 4)
        {
          x = InputCoordinate('x');
          y = InputCoordinate('y');
          if (Landscape[x, y].Warren != null)
          {
            Landscape[x, y].Warren.Inspect();
            Console.Write("View individual rabbits (y/n)?");
            viewRabbits = Console.ReadLine();
            if (viewRabbits == "y") {
              Landscape[x, y].Warren.ListRabbits();
            }
          }
        }
      } while (((WarrenCount > 0) || (FoxCount > 0)) && (menuOption != 5));
      Console.ReadKey();