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

From TRCCompSci - AQA Computer Science
Revision as of 23:14, 13 February 2017 by Admin (talk | contribs) (Created page with "==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 mayb...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
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 }