This is a programming project for my freshman year at college. It is a maze game that has to follow the instructions provided below.
This is the text file of the maze for the program.
maze.txtthis is what the maze is suposed to look like
+-+-+-+-+-+-+-+-+-+-+ |h | | D | | +-+ +-+ + +-+-+ + + + | | | | | | | + + + + + + + +-+-+-+ | | | | | | | +-+-+ +-+ + + + +-+ + | | | | | | | + + + + +-+ +-+-+ +-+ |P| | | F +-+-+-+-+-+-+-+-+-+-+
program2 CS 110 Introduction to Computer Science Project 2 – Dragon Maze Maximum Possible Points: 30 Objectives: • To gain experience with Object-Oriented Programming. • To gain experience with ArrayLists. • To gain experience with command line arguments. • To gain experience with random numbers. • To solve a complicated problem by breaking it into manageable pieces. Overview: ASCII based games are just good old school fun. For this program, you are to implement a dungeon-crawling maze game called “Dragon Maze”. The game consists of a maze with a start and a finish point. Your hero will have to traverse the maze to rescue the princess, and then escape the dungeon without incurring the wrath of the dragon lurking inside. If the hero gets too close to the dragon, they are incinerated to a pile of ashes (some imagination necessary) and it is GAME OVER. Specifications: Your Java program must implement the game as follows: • The maze is specified in the attached ASCII file “maze.txt”. It consists of walls represented by the characters “+”, “-”, and “|”, and representations of the hero, dragon, princess, and exit. • Your hero is represented by the letter “h” or “H”. The hero will make one move every turn, which will be inputted by the player. • The hero can either move up, down, left, right, or wait when the player enters the text “w”, “s”, “a”, “d”, or “f“, respectively. • The hero cannot move into a wall, and player input should be validated until a valid move is made. • The princess is represented by the letter “P”. They are static and await the hero. • When the hero moves into the space occupied by the princess, the princess disappears from the board and the hero is now designated by the letter “H”. • When the hero reaches the exit with the princess (marked as “F” in the maze), YOU WIN! • The dragon is represented by the letter “D”, and moves in a random direction every turn. If the move is into a wall, the dragon simply stays put. If the dragon gets into a space adjacent to the hero, GAME OVER. • Every turn, the maze will be redrawn on the screen, showing any moves made and prompting the user for the next move. The maze is to be represented as a class called “DragonMaze” with 5 private member variables representing the game board, pieces, and a random number generator. The class should also have 4 public methods that allow playing the game and 2 private methods used to manipulate the game board. There will be an additional class called GamePiece that will represent the positions on the board of several pieces. The GamePiece class will consist of 3 private fields, two indicating the position of the piece on the board (represented as integer values for row index and column index), and one for representing the character displayed on the board by the piece. The DragonMaze class should have the following fields: • One GamePiece instance to represent the hero, • One GamePiece instance to represent the dragon, • One GamePiece instance to represent the princess, • One Random Number Generator, and • An ArrayList of Strings to hold the gameboard. The DragonMaze class should have the following methods: • loadMazeFile – to read a file from a given filename (passed as a string parameter from a command line argument) and populate the gameboard, hero, and dragon positions. • printMaze – a constant method to output the contents of the gameboard and position of the pieces to the console. • moveHero – gets the desired move from the player, with validation to ensure that the move is into a valid space. A valid space is determined by checking the hero’s position in the maze array, and determining if the space being entered contains a “ “, “P”, or “F”. If the move is valid, the board and the hero’s GamePiece will be updated to reflect the move. If the hero moves onto the “P”, the “P” will become an “H” and the “h” will be removed. If the hero moves onto the “F”, assuming they are still alive, the method returns true to signify a win condition has been met. • moveDragon – will generate a random number between 0 and 3, representing the dragon attempting to move up, down, left, or right. If the move is valid (not a wall, “H”, “P”, or “F”), the dragon and maze arrays will be updated to reflect the move. If the move is invalid, the dragon will bide his time counting treasure for the duration of the turn. Finally, at the end of moveDragon(), you will check to see if the dragon is adjacent to the hero. If it is…. a GAME OVER message will display and the program will exit. • getCharAt – is passed a GamePiece parameter and returns the character on the board at that piece’s location, or returns “z” if the position passed is off the board. • setCharAt – is passed a GamePiece and character as parameters and sets the board at the piece’s location equal to the character passed. The GamePiece class should have the following fields: • An integer to represent the row index of the piece on the board, • An integer to represent the column index of the piece on the board, • A character to represent the symbol the piece appears as on the board. The GamePiece should have the following methods: • A default constructor initializing all fields to -1 or the empty character, • A constructor with parameters for the row, column, and symbol of the piece being created, • moveUp – reduces the row index by one, • moveDown – increases the row index by one, • moveLeft – reduces the column index by one, • moveRight – increases the column index by one, • Getters only for row and column indices, • A getter and setter for the symbol field, • adjacentTo – a method that receives another GamePiece as a parameter and returns true or false based on whether that piece is adjacent to this piece on the board. The game will create the appropriate logical variables and initialize all data structures and then enter into the loop (in main) that will control every turn. The loop will call several methods. Every turn, printMaze() will be used first output the contents of the maze array to the console, with the game piece’s coordinates in the maze. The method moveHero() will then be invoked to allow the user to move the hero and returns a Boolean value representing if they have won the game. Finally, moveDragon() should be called to determine the dragon’s next move and returns a Boolean value representing if the hero has met their demise. Instructions: • This will be an individual programming project. • Organize your code in GamePiece.java, GaDragonMaze.java, and Project2.java. • Use meaningful variable names, helpful comments, and a consistent coding style. • Each program file should have the appropriate comment block at the top: /* Name: Your Name * File Name: Project2.java * Date: Day Month, Year */ Program Description: brief description of the program • All methods and classes should have a header comment block describing the purpose of the function, input, and output: /********************************************************** * Name of the method. * Description of why the method/class exists and * how it accomplishes its goal. * @param Parameter list with descriptions * @return Return value with description **********************************************************/ Deliverables: You will need to submit the following in eCampus by 11:59 PM on November 27th. • The files GamePiece.java, DragonMaze.java, Project2.java, and a few screenshots of your program executing in Eclipse. Grading: This project is worth 30 points distributed as follows: • Coding (25 pts) o Implementation of the fields for GamePiece and DragonMaze (2 pts) o Implementation of the methods for GamePiece (3 pts) o Implementation of the loadMazeFile and the printMaze methods (5 pts) o Full implementation of moveHero (5 pts) o Successful implementation of moveDragon (5 pts) o Successful implementation of main (5 pts) • Program Style (5 pts) o Meaningful variable names (1 pt) o Proper indentation (1 pt) o Sufficient comments (3 pts) Sample Executions: Execution #1: +-+-+-+-+-+-+-+-+-+-+ |h | | D | | +-+ +-+ + +-+-+ + + + | | | | | | | + + + + + + + +-+-+-+ | | | | | | | +-+-+ +-+ + + + +-+ + | | | | | | | + + + + +-+ +-+-+ +-+ |P| | | F +-+-+-+-+-+-+-+-+-+-+ Hero: 1, 1 Dragon: 1, 15 Princess: 9, 1 Make your move! Valid moves are w, a, s, d, f (to wait) d +-+-+-+-+-+-+-+-+-+-+ | h | | D | | +-+ +-+ + +-+-+ + + + | | | | | | | + + + + + + + +-+-+-+ | | | | | | | +-+-+ +-+ + + + +-+ + | | | | | | | + + + + +-+ +-+-+ +-+ |P| | | F +-+-+-+-+-+-+-+-+-+-+ Hero: 1, 2 Dragon: 1, 16 Princess: 9, 1 Make your move! Valid moves are w, a, s, d, f (to wait) … +-+-+-+-+-+-+-+-+-+-+ | | |