Levels Tought:
Elementary,Middle School,High School,College,University,PHD
Teaching Since: | Apr 2017 |
Last Sign in: | 8 Weeks Ago, 3 Days Ago |
Questions Answered: | 4870 |
Tutorials Posted: | 4863 |
MBA IT, Mater in Science and Technology
Devry
Jul-1996 - Jul-2000
Professor
Devry University
Mar-2010 - Oct-2016
This is the assignment for Java that I do not understand. Can you please help me ?
Â
Thanks
Â
Task description
Â
In this assignment you will be designing a maze game.
You will have a maze board and a player moving around the board.
The player can step left, right, up or down.
However, you need to complete the maze within a given number of steps.
Â
As in any maze, there are walls that you cannot move through.
If you try to move through a wall, you lose a life.
There is also gold on the board that you can collect if you move ontop of it.
Â
The game can end in one of the following ways:
Â
1.
The player has completed the maze. That is, they have reached the destination.2.
The player has no lives.3.
The player has no remaining steps.
Please implement the methods provided, as some of the marking is making sure that these methods work as specified.
Â
You are also allowed to write your own methods.
Â
Please also read the entire specification - it is quite comprehensive.
Â
Â
Implementation details
Â
Command line arguments
Â
The MazeGame takes 1 command line argument.
This is the file that we are going to be reading in the game configuration from.
For example:
Â
$ java MazeGame game_configuration.txt
Â
Â
The game configuration file
Â
The game configuration contains 5 pieces of information.
Â
1.
The number of lives remaining.2.
The number of steps remaining.3.
The players starting amount of gold.4.
The number of rows on the board. [ Must be at least 1. ]5.
The maze board itself.
The layout of the game configuration file is as follows:
Â
<number of lives> <number of steps> <amount of gold> <number of rows on the board> <BOARD>
Â
IMPORTANT:
You may assume that if the configuration file exists, that it is in the format given above.
Â
Characters on the maze board
Â
•
a ' ' is a space in the board.•
a '#' is a wall of the maze.•
a number 0-9 is the gold that you can collect on the board.•
a '.' is a place the player has been.•
the '@' is the destination that the player is trying to reach. Note: there is exactly one destination.•
the '&' is the person. Note: there is exactly one person.•
You may assume that there are no invalid characters on the board.
Here are some sample game configuration files.
Â
easy_board.txt
3 4 0 3 ###### #@ &2# ## ##
Â
DEFAULT
3 20 0 4 #@ ## &4# ## # ## # ### 3# ####### #
Â
Please note: the board is a grid.
This means, it has the same number of columns on each row.
Â
Â
Running the program
Â
The program can be run in 2 ways.
Â
1. Running the program by reading in from an input game configuration file.
Â
$ java MazeGame input_file_name.txt
Â
Â
2. Running the program by using the DEFAULT board provided above.
Â
$ java MazeGame DEFAULT
Â
Â
Error handling
Â
If there is an error initialising the board / program, print out the appropriate error message and exit the program.
Â
If no arguments are given:
$ java MazeGame Error: Too few arguments given. Expected 1 argument, found 0. Usage: MazeGame [<game configuration file>|DEFAULT]
Â
If too many arguments are given:
$ java MazeGame file1.txt file2.txt Error: Too many arguments given. Expected 1 argument, found 2. Usage: MazeGame [<game configuration file>|DEFAULT] $ java MazeGame file1.txt file2.txt file3.txt file4.txt Error: Too many arguments given. Expected 1 argument, found 4. Usage: MazeGame [<game configuration file>|DEFAULT]
Â
The file could not be found, read, etc.
$ java MazeGame invalid_file_here.txt Error: Could not load the game configuration from 'invalid_file_here.txt'.
Â
Â
List of commands
Â
Once the board is loaded, you can use the following commands in your program.
You need to implement the functionality for all of them.
Â
•
help Print the help message.•
board Print the current board.•
status Print the current status.•
left Move the player 1 square to the left.•
right Move the player 1 square to the right.•
up Move the player 1 square up.•
down Move the player 1 square down.•
save <file>Â Save the current game configuration to the given file.
Reading and running commands
Â
Reading in commands is case insensitive. If a line is entered and the line is
blank (i.e. only white space), do nothing.
Â
That is the following, for example, are valid commands:
•
help•
hElP•
SAVE file_name.txt•
UP•
board
The following commands are invalid as they have either have the wrong number of arguments next to the command, or don't match a given command:
•
help up•
up blah 123•
save file1.txt file2.txt•
chocolate•
h e l p•
save
Example with invalid command.
Â
$ java MazeGame DEFAULT help up Error: Could not find command 'help up'. To find the list of valid commands, please type 'help'. up blah 123 Error: Could not find command 'up blah 123'. To find the list of valid commands, please type 'help'.
Â
Â
Basic commands: Help, board and status
Â
Help command
Â
Prints out the following help message. Example below
$ java MazeGame DEFAULT help Usage: You can type one of the following commands. help Print this help message. board Print the current board. status Print the current status. left Move the player 1 square to the left. right Move the player 1 square to the right. up Move the player 1 square up. down Move the player 1 square down. save <file> Save the current game configuration to the given file.
Â
Â
Board command
Â
Prints out the current board. Example below.
$ java MazeGame DEFAULT board #@ ## &4# ## # ## # ### 3# ####### #
Â
Â
Status command
Â
Prints out the current status.
$ java MazeGame DEFAULT status Number of live(s): 3 Number of step(s) remaining: 20 Amount of gold: 0
Â
Â
Board Coordinates
Â
The x coordinate is the column number (starting from 0).
The y coordinate is the row number (starting from 0).
Â
For the following file:
Â
easy_board.txt
3 4 0 3 ###### #@ &2# ## ##
Â
The board coordinates for the easy board can be interpreted by the grid below.
Â
x 0 1 2 3 4 5 ------------------------- 0 | # | # | # | # | # | # | ------------------------- y 1 | # | @ | | & | 2 | # | ------------------------- 2 | # | # | | | # | # | -------------------------
Â
Interpreting this:
Â
•
The player is at (3, 1).•
The destination is at (1, 1).•
There is gold at (4, 1).•
There are 3 spaces, they are at (2, 1), (2, 2), (3, 2).
Â
Movement
Â
There are 4 movement commands.
They are left, right, up and down.
Â
If the player moves to a valid square (a ' ', '.' or a digit 0-9), the program
should print out "Moved to (x, y)." where x and y are the players new
coordinates on the board.
Â
If the player moves to a square with gold, they get all the gold in that square.
A message is printed out saying "Plus <number> gold."
Â
When they move away from the square, the square is changed to a '.'.
Â
If the player tries to move into a wall, the player loses a life and it still
uses a step.
Â
Example 1. Failed due to losing all their lives.
Â
DEFAULT game configuration
3 20 0 4 #@ ## &4# ## # ## # ### 3# ####### #
Â
$ java MazeGame DEFAULT board #@ ## &4# ## # ## # ### 3# ####### # status Number of live(s): 3 Number of step(s) remaining: 20 Amount of gold: 0 up Invalid move. One life lost. status Number of live(s): 2 Number of step(s) remaining: 19 Amount of gold: 0 down Invalid move. One life lost. status Number of live(s): 1 Number of step(s) remaining: 18 Amount of gold: 0 right Moved to (8, 0). Plus 4 gold. board #@ ## .&# ## # ## # ### 3# ####### # left Moved to (7, 0). board #@ ## &.# ## # ## # ### 3# ####### # status Number of live(s): 1 Number of step(s) remaining: 16 Amount of gold: 4 down Invalid move. One life lost. Oh no! You have no lives left. Better luck next time!
Â
Â
Example 2. Success.
Â
easy_board.txt game configuration
3 4 0 3 ###### #@ &2# ## ##
Â
$ java MazeGame easy_board.txt right Moved to (4, 1). Plus 2 gold. left Moved to (3, 1). left Moved to (2, 1). board ###### ## ## left Moved to (1, 1). Congratulations! You completed the maze! Your final status is: Number of live(s): 3 Number of step(s) remaining: 0 Amount of gold: 4
Â
Â
Example 3. Failed due to having no more steps.
Â
easy_board.txt game configuration
3 4 0 3 ###### #@ &2# ## ##
Â
$ java MazeGame easy_board.txt right Moved to (4, 1). Plus 2 gold. left Moved to (3, 1). down Moved to (3, 2). board ###### #@ ..# ## &## status Number of live(s): 3 Number of step(s) remaining: 1 Amount of gold: 4 left Moved to (2, 2). Oh no! You have no steps left. Better luck next time!
Â
Â
Â
Example 4. Failed due to having no more lives and no more steps.
Â
easy_board.txt game configuration
3 4 0 3 ###### #@ &2# ## ##
Â
$ java MazeGame easy_board.txt down Moved to (3, 2). status Number of live(s): 3 Number of step(s) remaining: 3 Amount of gold: 0 down Invalid move. One life lost. status Number of live(s): 2 Number of step(s) remaining: 2 Amount of gold: 0 down Invalid move. One life lost. status Number of live(s): 1 Number of step(s) remaining: 1 Amount of gold: 0 down Invalid move. One life lost. Oh no! You have no lives and no steps left. Better luck next time!
Â
Â
Saving the game
Â
To save the game, we write out the current game configuration to a file.
Â
If there is an error saving the game configuration to the given file, print out the error message as shown below.
That is, if the file does not exist and it cannot be created, or if it is not writable etc.
Â
easy_board.txt game configuration
3 4 0 3 ###### #@ &2# ## ##
Â
$ java MazeGame easy_board.txt right Moved to (4, 1). Plus 2 gold. status Number of live(s): 3 Number of step(s) remaining: 3 Amount of gold: 2 board ###### #@ .&# ## ## save current_board.txt Successfully saved the current game configuration to 'current_board.txt'. left Moved to (3, 1). save . Error: Could not save the current game configuration to '.'. left Moved to (2, 1). left Moved to (1, 1). Congratulations! You completed the maze! Your final status is: Number of live(s): 3 Number of step(s) remaining: 0 Amount of gold: 4
Â
The contents of current_board.txt after the above is:
3 3 2 3 ###### #@ .&# ## ##
Â
Â
Ending the game without finishing / losing.
Â
If there is no more input from the user. That is, you reach EOF in System.in
and the game has not ended, print out "You did not complete the game."
Â
For example, if after starting, the user hit CTRL+D, the following would happen:
Â
$ java MazeGame DEFAULT You did not complete the game.
-----------