CIS200: Assignment 7
10 points. Due Saturday, April 25, 10:00pm

We will C# to build a simple maze game, where the player maneuvers a marker around barriers through the maze.

The game appears as a 5-by-5 board, where one "X" barrier is randomly placed on each row of the board. The player's "*"-marker is placed on the upper left square of the board. (Obviously, the barrier placed in the top row of the board must not be in the same leftmost square!) The object of the game is to move the "*"-marker to the board's lower right corner in as few moves as possible. A square can be occupied at most once, and once the "*"-marker leaves a square, the square is filled by an "X". The game ends either when the player ``wins'' by moving the "*" to the lower right corner or when the player ``loses'' when the "*" is blocked and cannot move further. The program must announce when the player wins, but it is not required that the program announce when a player is blocked and loses.

Here is an example of the initial state of the maze:

$ Maze
Moves: 0
* _ X _ _
_ X _ _ _
_ X _ _ _
_ _ _ X _
_ _ X _ _
Type a move (l,r,u,d): 
Perhaps the player types d to moves down:
Type a move (l,r,u,d): d

Moves: 1                                       Moves: 2
X _ X _ _               and then down again:   X _ X _ _ 
* X _ _ _                                      X X _ _ _
_ X _ _ _                                      * X _ _ _
_ _ _ X _                                      _ _ _ X _
_ _ X _ _                                      _ _ X _ _
Type a move (l,r,u,d): d                       Type a move (l,r,u,d): d
and again:
Moves: 3                                       Moves: 4
X _ X _ _               and then right:        X _ X _ _ 
X X _ _ _                                      X X _ _ _
X X _ _ _                                      X X _ _ _
* _ _ X _                                      X * _ X _
_ _ X _ _                                      _ _ X _ _
Type a move (l,r,u,d): r                       Type a move (l,r,u,d):
The game must prohibit illegal moves (e.g., from the last configuration, a move upwards ("u") is illegal, and it must announce when the player wins.

Designing the data structure and algorithm

There are two data structures that you might use to model the maze. The first is a one-dimensional array of string:
string[] maze = new string[MAZE_SIZE];
This data structure uses the techniques you developed in lab. (See the sample solution posted on the CIS200 Assignments web page.) The second choice is a two-dimensional array:
string[,] maze = new string[ROW_SIZE,ROW_SIZE];

To generate random numbers in C#, do this:

Random ran = new Random()  // construct the random-number generator object
 ...
int LOWER = 1;
int UPPER = 10;
 ...
int random_num = ran.Next(LOWER, UPPER);  // assign to  random_num  a randomly
                           // generated int in the range,  LOWER..(UPPER-1).
                           // Reuse this command as often as needed.

Testing and submitting your program

Remember to compile your program with the command, csc /debug+ Maze.cs. Test the program by merely typing its name, Maze. Insert Console.WriteLine commands to generate execution traces. (Or, you are welcome to use the debugger tool within Visual Studio to test.)

Use the web page at http://www.cis.ksu.edu/~schmidt/200s08/Assign to submit your program, Maze.cs.