Display a message when a cell with no fox is selected for fox inspection...Adding a loop too

From TRCCompSci - AQA Computer Science
Jump to: navigation, search

The problem

if you enter coordinates for a fox and no fox is at that location the current program does nothing. However maybe it should give a message to confirm, and maybe get the user to re-enter :

1 if (menuOption == 3)
2 {
3 	x = InputCoordinate('x');
4 	y = InputCoordinate('y');
5 	if (Landscape[x, y].Fox != null)
6 	{
7 		Landscape[x, y].Fox.Inspect();
8 	}
9 }

Solution

 1 if (menuOption == 3)
 2 {
 3 	x = InputCoordinate('x');
 4 	y = InputCoordinate('y');
 5 	if (Landscape[x, y].Fox != null)
 6 	{
 7 		Landscape[x, y].Fox.Inspect();
 8 	}
 9         else
10         {
11                Console.WriteLine("No fox found!! at these coordinates");
12         }
13 }