Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C++ project will let the user try to move through a maze. The user will be presented with a maze, which is read from a

C++ project will let the user try to move through a maze.

The user will be presented with a maze, which is read from a file. The maze has twice as many columns as rows. You should use constants. maze.txt has 10 rows and 20 columns.

The user always starts at the second row, first column. The user can move up, down, left, or right. If the user tries to move in a direction where there is a wall, tell the user that the move is illegal. The user wins the game when they make it to the exit of the maze which is always the next to last row and last column. Basically, the user has to move from the upper left to the lower right.

At any time the user can choose to quit the game.

MazePlay.cpp will contain main()

Maze.cpp and Maze.h will contain the Maze class. Recommendations for the class:

Constants for the size of the two-dimensional array dimensions.

Member variables for the maze (two-dimensional array), current x and y position.

Constructor to initialize member variables.

read method that accepts a filename. It should read the file into your two-dimensional array.

print method that prints the current picture of the maze.

get and set methods for x and y.

legalMove method that accepts an x and y. It returns true or false if the user can make that move.

won method returns true or false if the user has won the game.

One way of reading the file is to read it one character at a time. Some methods of reading skip over spaces and newline characters. If you have an input stream called, inFile, and you want to read the next character (space or not), you can use the lines:

char c;

inFile.get(c);

Sample Run #1: (the highlighted text is what the user types) user wins the game

Maze Filename? maze.txt

||||||||||||||||||||

* ||||||| ||

|||| ||| ||| ||||

||||| || ||||

| |||||| ||

| ||||||||| | ||

| ||| ||||| |

|||| || || |||

|||||| | |||

||||||||||||||||||||

Next move (u=Up, d=Down, r=Right, l=Left, q=Quit)? r

||||||||||||||||||||

* ||||||| ||

|||| ||| ||| ||||

||||| || ||||

| |||||| ||

| ||||||||| | ||

| ||| ||||| |

|||| || || |||

|||||| | |||

||||||||||||||||||||

Next move (u=Up, d=Down, r=Right, l=Left, q=Quit)? r

||||||||||||||||||||

* ||||||| ||

|||| ||| ||| ||||

||||| || ||||

| |||||| ||

| ||||||||| | ||

| ||| ||||| |

|||| || || |||

|||||| | |||

||||||||||||||||||||

Next move (u=Up, d=Down, r=Right, l=Left, q=Quit)? r

||||||||||||||||||||

* ||||||| ||

|||| ||| ||| ||||

||||| || ||||

| |||||| ||

| ||||||||| | ||

| ||| ||||| |

|||| || || |||

|||||| | |||

||||||||||||||||||||

Next move (u=Up, d=Down, r=Right, l=Left, q=Quit)? r

||||||||||||||||||||

*||||||| ||

|||| ||| ||| ||||

||||| || ||||

| |||||| ||

| ||||||||| | ||

| ||| ||||| |

|||| || || |||

|||||| | |||

||||||||||||||||||||

Next move (u=Up, d=Down, r=Right, l=Left, q=Quit)? d

****** SEVERAL MORE MOVES ******

||||||||||||||||||||

||||||| ||

|||| ||| ||| ||||

||||| || ||||

| |||||| ||

| ||||||||| | ||

| ||| ||||| |

|||| || || |||

|||||| | ||| *

||||||||||||||||||||

Next move (u=Up, d=Down, r=Right, l=Left, q=Quit)? r

||||||||||||||||||||

||||||| ||

|||| ||| ||| ||||

||||| || ||||

| |||||| ||

| ||||||||| | ||

| ||| ||||| |

|||| || || |||

|||||| | ||| *

||||||||||||||||||||

Congratulations! You won!

Press any key to continue . . .

Sample Run #2: (the highlighted text is what the user types) user loses the game and does illegal move

Maze Filename? maze.txt

||||||||||||||||||||

* ||||||| ||

|||| ||| ||| ||||

||||| || ||||

| |||||| ||

| ||||||||| | ||

| ||| ||||| |

|||| || || |||

|||||| | |||

||||||||||||||||||||

Next move (u=Up, d=Down, r=Right, l=Left, q=Quit)? d

That move is illegal -- try again

||||||||||||||||||||

* ||||||| ||

|||| ||| ||| ||||

||||| || ||||

| |||||| ||

| ||||||||| | ||

| ||| ||||| |

|||| || || |||

|||||| | |||

||||||||||||||||||||

Next move (u=Up, d=Down, r=Right, l=Left, q=Quit)? q

Sorry, you lost

Press any key to continue . . .

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Modern Database Management

Authors: Jeffrey A. Hoffer Fred R. McFadden

9th Edition

B01JXPZ7AK, 9780805360479

More Books

Students also viewed these Databases questions