Due: September 12
Write a simple adventure game program with a text interface. Part 1 is more of a game skeleton than an actual game, but we will be adding to the game in several later assignments.
The main class for your program should be called Adventure. When the program starts it prints a prompt for a command. It then reads a line of input, parses the input into a command and parameters, and then executes the command. The command and its parameters (if it has any parameters) should be in the same line of input. If the command or parameters are incorrect the program should print an error message. The program should continue to print a prompt for a command, get input, and execute the input until the user enters the quit command.
Commands are not case sensitive. The user can enter go, GO, Go, or gO for the go command.
Here are the commands that your program should accept and execute:
brass lantern rope rations staff
Commands are recognized by the first letter, so any word that starts with the letter g (upper or lower case) should be interpreted as the go command.
Your program should keep track of the player character's location and print the location after each valid command. The location is a pair of coordinates, with the first coordinate telling what row of the map the character is in and the second telling what column the character is in.
The character starts in location 0,0, which is at the top left corner of the map. The go command will change the character's location as follows:
|east||Add one to the column (second coordinate)|
|west||Subtract one from the column (second coordinate)|
|north||Subtract one from the row (first coordinate)|
|south||Add one to the row (first coordinate)|
For this assignment we are using a 5x5 map that has five rows and five columns. The row and column coordinates must not be negative, and must not have a value greater than four. Your program should not allow a command that moves the character to a location outside these bounds, and it should print a message if the user enters a command that would take the character out of bounds.
You will probably only need one class for this assignment. Your class should not be part of a package. Some Java IDEs will automatically create a package for each new project, so if yours does that you will need to remove the package declarations.
Here is a sample class file that you can try to see what the program does: Adventure.class
Here is a sample transcript: transcript.txt (plain text) transcript.html (highlighted HTML)
Even though this is a simple program, think about how you can write your code to make it easy to modify later. We will have several assignments that modify and build on the Adventure class.
The easiest way to do input is to use java.util.Scanner. You should not make more than one scanner for a stream, and since we are using only one stream (the standard input stream) you should not make more than one scanner in your program. I will deduct points from your score on this assignment if your program has more than one scanner on the same input stream.
A good way to break up an input line into words is to use the String.split method. (The String class is part of the java.lang package.)
You will find a lot of useful information for this assignment in Chapters 2 and 3 of the book, including help with compiling and running Java programs, using the Scanner class, and working with strings and arrays.
Here are some additional notes to help you get started on this assignment: notes
Make sure that your program compiles and runs from the command line:
You won't get credit for your program if your program doesn't compile from the command line or can't be run from the command line.
Put your source files into a zip file and turn the zip file in on Canvas. Your files should not be inside a folder in the zip file, and there should not be any files other than source files and an optional README.txt file.