In the Maze Game, the player moves a character around the game board in an effort to pick up all of the colored squares. The different colored squares are worth different points: red squares are worth 100, green squares are worth 40, and blue squares are worth 10. The game will track the user's score as they move around the game board.
1. Start by downloading the NetBeans project from the lecture notes for the second version of the Maze Drawing program.
2. Run the Maze Drawing program and use it to construct your map. Put walls and treasure in the map. To switch back and forth from the wall drawing mode to the treasure placing mode, press the 'p' key on the keyboard. To change the colors used for treasure, press the 'r', 'g', and 'b' keys. After you have drawn your map, use the File/Save command to save your map to a text file.
3. To construct the game program you are going to use the Maze Drawing project code as a starting point. You can remove the code in the MazePane constructor that draws the grid of red guide points. You can also remove the save()
method from the MazePane class and also remove the write()
methods from the Maze and Treasure classes.
4. You should add code to the MazePane constructor that opens the maze.txt file to read the contents of the maze. The first line in the maze.txt file is the number of wall segments. The wall segments then follow, with each wall segment in the form of the x and y coordinates for both ends of the wall segment. The next line after the wall segments contains the number of treasure objects. The treasure objects follow, with each line giving the x and y coordinates for the top left corner of the Treasure rectangle followed by the color to use for the object.
5. Your game program will not be using mouse interaction, so you can also remove the methods in the MazePane, Wall, and Treasure classes that handle mouse interaction. Before you remove the endDrag()
method from the MazePane class you may want to retain the code in the comment. That code shows how to determine whether or not a Line intersects with one of the Wall objects. You will need this code in step 8.
6. Add a Player class to the project to represent the player object. The player object will appear on the game board as a colored circle. Add code to the MazePane constructor that places a single Player object on the game board.
7. Replace the code in the MazePane.keyPress()
method. The game program will only respond to the arrow keys, whose key codes are LEFT
, UP
, DOWN
, and RIGHT
. When the user presses one of the arrow keys your program should move the Player object 40 pixels in the direction of the arrow. If the player enters one of the treasure objects on a move you should remove that object from the game board and give the player the points for the object they just picked up.
8. Add logic to the key handling code that keeps the player from moving off the edge of the map or through a wall on any move. To see whether or not a move would have the player passing through a wall, construct a Line object that has one endpoint where the player is currently located and a second end point at the location the player wants to move to. Temporarily add this new Line object to the MazePane's child list. You can then run the code from the comment in the MazePane.endDrag()
method to determine whether or not that Line would intersect with any of the existing Wall segments. If it does, you should not move the Player object. (Remove the temporary Line object from the MazePane's child list after running the test.) Likewise, if a move would take the Player off the edge of the map you should not do that move either.
For this project you will be working with a partner. You are welcome to either work with the same partner you had for the previous homework, or you can choose a new partner for this assignment.
When you submit the assignment for grading only one partner needs to upload the project to Canvas. Be sure to attach a comment telling me who your partner was for this project.