Question: Need help coding this. Project Description This first project is meant to ensure that you are able to apply and extend your prerequisite knowledge as
Need help coding this.
























Project Description This first project is meant to ensure that you are able to apply and extend your prerequisite knowledge as well as introduce you to developing and testing a Java application in a Linux environment (i.e. the Odin development server). You should be familiar with the majority of aspects of this project through your introductory programming course and the class exercises from 1302. However, you may also be asked to do things that you have never been given explicit directions for before. This is just a part of software development. Sometimes you need to research how to solve a problem in order to implement a solution. That being said, the material included in this document should hopefully answer the majority of your questions. Your goal is to develop a non-recursive, non-GUI (GUI = Graphical User Interface) version of the game called Minesweeper. The code for this game will be organized in such a way that the recursive elements of Minesweeper can be added at a later point in time, if desired. It will also be organized so that you can add a GUI to it later as well. Interestingly, the organization of some of the classes in this project will also introduce you to some elementary aspects of game programming. If you are not familiar with Minesweeper as a game, then please consult the Wikipedia entry for the game, ignoring any mentions of recursion. Once you're familiar with the basic gameplay, then continue reading this project description. Note Concerning "No Recursion" In a traditional game of Minesweeper, when the player "reveals" a square that does not contain a mine, two things happen: 1. A number representing the number of mines in the (up to) eight adjacent squares is placed in the revealed square; and 2. If the number of adjacent mines is zero, then game goes ahead and "reveals" all of the (up to) eight adjacent squares. The second part mentioned above can cause one reveal made by the user to result in multiple reveals in the minefield. This behavior is what the literature is referring to when it talks about recursion in Mineweeper. Your game should not support this behavior. If the user reveals one square, then, at most, one square is revealed in the minefield. Minesweeper Overview In your Minesweeper, the player is initially presented with a grid of undifferentiated squares. Either some randomly selected squares or seed- selected squares (more on seeds later) are designated to contain mines. The size of the grid and the number of mines are set in advance by a seed file that the user specifies as a command-line argument to your program. The ratio of the number of mines to the grid size is often used as a measure of an individual game's difficulty. The grid size can also be represented in terms of the number of rows and columns in the grid. In this project description, we may refer to the grid or to the minefield. Both of these terms mean the same thing. Furthermore, we will use the term square to denote a location in the minefield, even in situations where a location may be visually rectangular instead of perfectly square. The game is played in rounds. During each round, the player is presented with the grid, the number of rounds completed so far, as well as a prompt. The player has the option to do 6 different things, each of which is briefly listed below and explained in great detail in later sections: 1. Reveal a square on the grid. After the player correctly entered the command r 1 2, the state of the game updates (e.g., number of rounds completed, the grid, etc.), and the next round happens. Since there was no mine in square (1,2), the player does not lose the game. Also, since the total number of mines in the 8 cells directly adjacent to square (1,2) is 2, the number 2 is now placed in that cell. If the player reveals a square containing a mine, then the following message should be displayed and the program should exit gracefully (as defined near the end of this section): Oh no... You revealed a mine! TUITIVI I CIT CITT|||| \/ || LILLI LILILI U LII Yeah, that's old school ASCII art. Please note that the first and last lines are blank. Also note that the second line (containing "oh no...") begins with a single white space. A copy of this game over text, excluding the first and last blank lines, is contained in resources/gameover.txt. Graceful Exit: When we say that a program should exit gracefully, we mean that the exit status code used in the call to System.exit is a (i.e., zero). If a graceful exit is expected and your program exits for any reason with an exit status other than o (e.g., if your game crashes), then some points will be deducted from your grade. Immediately after any program terminates and returns to the terminal shell, a user can inspect what exit code was used by executing the following command: $ echo $? Note that using echo $? a second time would show the exit status of the first echo command; you would need to rerun your program and cause it to exit in order to check the exit status again. Mark Command In order to mark a square as definitely containing a mine, the mark or m command is used. The syntax format for this command is as follows: - ["mark"/"m" ] - [ (int)]-[(int)]- . The second and third tokens indicate the row and column indices, respectively, of the square to be revealed. 1. Reveal a square on the grid. 2. Mark a square as potentially containing a mine. 3. Mark a square as definitely containing a mine. 4. Lift the fog of war (cheat code). 5. Display help information. 6. Quit the game. When the player reveals a square of the grid, different things can happen: If the revealed square contains a mine, then the player loses the game. If the revealed square does not contain a mine, then a digit is instead displayed in the square, indicating how many adjacent squares contain mines. Typically, there are 8 squares adjacent to any given square, unless the square lies on an edge or corner of the grid. The player uses this information to deduce the contents of other squares, and may perform any of the first three options in the list presented above. When the player marks a square as potentially containing a mine, a ? is displayed in the square. This provides the user with a way to note those places that they believe may contain a mine but are not sure enough to mark as definitely containing a mine. When the player marks a square as definitely containing a mine, a flag, denoted by the character F, is displayed in the square. To simplify the game mechanics, the player may mark, guess, or reveal any square in the grid, even squares that have already been marked or revealed. In other words, the player may issue a command to mark, guess, or reveal a square, regardless of its current state. The logic for determining what happens to the square is always the same. For example, if a square has been revealed and the user marks it as definitely containing a mine then a round is consumed and the square should be marked. The user would then have to reveal this square again later. This may not be consistent with how you've played Minesweeper in the past but it will make it easier to code. We will leave it up to the user to be smart about how they play! The game is won only when both of the following conditions are met: All squares containing a mine are marked as definitely containing a mine; and All squares not containing a mine are revealed. At the end of the game, the player is presented with a score. Let rows , cols, and rounds denote the number of rows in the grid, columns in the grid, and number of rounds completed, respectively. A round is defined as one successful iteration of the main game loop. Therefore, only valid commands result in a round being consumed. To be clear, rounds is not quite the same as the number of commands entered (some may be invalid); however, it should be less than or equal to that number. The player's score is calculated as follows: The player's score is calculated as follows: score = 100.0 * rows * cols / rounds; A score of 100 would denote a perfect game. In this version of Mineweeper, it should not be possible for the player to win the game in less than (rows * cols) -many rounds (take a second to convince yourself of this fact). Therefore, any game in which the player exceeds that many rounds would result in a score that is less than 100 . When displaying the score, the number should always be printed with two digits following the decimal point. The Grid and Interface When the game begins, the following welcome banner should be displayed to the player once and only once: M (F) 1 VI-V-VIINI_V_I_V IMIT || AVV JIJI V VII LILIUM LILI LILI ALPHA EDITION |_| V2021.sp WEEDE Take care when printing this message out to the screen. Depending on how you implement this part, you may need to escape some of the characters in order for them to show up correctly. A copy of this welcome banner is contained in this README.md file and in resources/welcome.txt. In this Minesweeper game, the initial game configuration is loaded from a seed file; the player provides the path to a seed file when as a command line argument to the program. Two pieces of of information that are read from the seed file are the number of rows and the number of columns which together specify the grid size (i.e., the size of the minefield). The number of rows and the number of columns need not be the same. Rows and columns are indexed starting at @. Therefore, in a 10 -by- 10 (rows-by-columns), the first row is indexed as a and the last row is indexed as 9 (similarly for columns). In a 5-by- 8 game, the row indices are from o to 4, while the column indices are from a to 7, respectively. The Grid Let's assume we are playing a 5-by- 5 game of Minesweeper. When the game starts, the interface should look like this: Rounds Completed: 0 1 2 3 4 1 1 1 1 1 1 1 1 1 1 1 2 3 4 minesweeper-alpha: Let's assume we are playing a 10 -by- 10 game of Minesweeper. When the game starts, the interface should look like this: Rounds Completed: 0 | 1 1 1 1 1 1 1 1 | 1 21 3 4 5 6 7 | 8 9 1 1 1 1 1 1 1 1 | 1 1 2 3 4 5 6 7 8 9 minesweeper-alpha: Please note that the in either example, the first, third, and second-to-last lines are blank (the lines before and after "Rounds Completed" and the line before the prompt). All other lines, except the last line containing the prompt, start with one blank space. The line containing the prompt contains an extra space after the : so that when the user types in a command, the text does not touch the : . Multiple output examples are provided in the Appendix of this project description for your convenience. The User Interface The possible commands that can be entered into the game's prompt as well as their syntax are listed in the subsections below. Commands with leading or trailing whitespace are to be interpreted as if there were no leading or trailing whitespace. For example, the following two examples should be interpreted the same: minesweeper-alpha: help minesweeper-alpha: help Although it's hard to see in the example above, trailing whitespace should also be ignored. That is, if the user types one or more times before pressing the RET (return) key, then those extra whitespaces should be ignored. The different parts of a command are known as tokens. The help command, for example, only has one token. Other commands, such as the mark (seen below) have more than one token because other pieces of information are needed in order to interpret the command. As a quick example (which will be explored in more depth below), the player can mark the square at coordinate (0,0) using mark as follows: minesweeper-alpha: mark oo In the above example, you can see that the mark command has three tokens. A command with more than one token is still considered syntactically correct if there is more than one white space between tokens. For example, the following four examples should be interpreted the same: minesweeper-alpha: mark om minesweeper-alpha: mark minesweeper-alpha: mark @ @ minesweeper-alpha: mark 0 As a reminder, trailing whitespace is ignored. Advice on Reading Commands All valid game commands are entered on a single line. Implementers should always use the nextLine() method of their one and only standard input Scanner object to retrieve an entire line of input for a command as a string. Once an entire line is retrieved, it can be parsed using various methods; however, implementers may find it useful to construct a new Scanner object using the line as its source so that they can scan over the individual tokens. To put this into perspective, taking the "make a Scanner from the line" approach would make it so you can handle all four examples at the end of the last sub-section with one set of code. Here's some example code: // Assume you have have a Scanner object that reads from System.in called stdin String fullCommand = stdin.nextLine(); // reads the full command from the user (Ex: command may contain "reveal 1 3") // Create a new Scanner to parse the tokens from the given command Scanner commandScan = new Scanner (fullCommand); // Neat! A new use of Scanner. :) // Now, we can call our regular Scanner methods to get each part of the assigned command String command = commandScan.next(); // command would contain "reveal" from if given the command above. // Continue to call additional Scanner methods (nextInt(), etc.) to parse out the other tokens from the full command. Command Syntax Format In the sections below, we describe the syntax format that each command must adhere to in order to be considered correct. Unknown commands and commands that are known but syntactically incorrect are considered invalid. Information about displaying errors related to invalid commands is contained in a later section in this document. Please do not confuse this syntax with regular expressions, a topic that will not be covered in this course. You are NOT meant to put this weird looking syntax into any code. It is purely meant to convey to you, the reader, what is and what is not valid input for a given command. In a syntax format string, one or more non-new-line white space is represented as a - .Command tokens are enclosed in [] braces. If the contents of a token are surrounded by" marks, then that token can only take on that literal value. If more than one literal value is accepted for a token, then the quoted literals are separated by /. If the contents of a token are surrounded by () marks, then that token can only take on a value of the type expressed in parentheses. Note: the literal values are case-sensitive. So, "Reveal" is not the same as "reveal". Revealing a Square In order to reveal a square, the reveal or r command is used. The syntax format for this command is as follows: - ["reveal"/"r"]-[(int)]- [(int)]- . The second and third tokens indicate the row and column indices, respectively, of the square to be revealed. Let's go back to our 10 -by- 10 example. Suppose that we secretly know that there is a mine in squares (1,1) and (1,3). Now suppose that the player wants to reveal square (1, 2). Here is an example of what that might look like. Let's go back to our 10 -by- 10 example. Suppose that we secretly know that there is a mine in squares (1,1) and (1,3). Now suppose that the player wants to reveal square (1, 2). Here is an example of what that might look like. Rounds Completed: 1 | 1 | 1 1 | | 1 1 1 1 1 | 1 1 IT 1 | 21 31 4 5 6 7 8 | 9 1 1 TT 1 | 1 1 1 1 1 | 0 1 2 3 4 6 7 9 minesweeper-alpha: r 1 2 Rounds Completed: 1 | | | | 2 | 1 | 1 1 1 1 1 1 1 21 31 41 5 6 71 8 9 1 1 1 1 1 1 1 1 1 1 1 | 1 1 1 6 7 8 9 1 2 3 4 5 minesweeper-alpha: After the player correctly entered the command r 1 2, the state of the game updates (e.g., number of rounds completed, the grid, etc.), and the next round happens. Since there was no mine in square (1,2), the player does not lose the game. Also, since the total number of mines in the 8 cells directly adjacent to square (1,2) is 2, the number 2 is now placed in that cell. If the player reveals a square containing a mine, then the following message should be displayed and the program should exit gracefully (as defined near the end of this section): Oh no... You revealed a mine! III ICICLIT LILLI I IVI | UU LII Yeah, that's old school ASCII art. Please note that the first and last lines are blank. Also note that the second line (containing "oh no...") begins with a single white space. A copy of this game over text, excluding the first and last blank lines, is contained in resources/gameover.txt. Graceful Exit: When we say that a program should exit gracefully, we mean that the exit status code used in the call to System.exit is a (i.e., zero). If a graceful exit is expected and your program exits for any reason with an exit status other than o (e.g., if your game crashes), then some points will be deducted from your grade. Immediately after any program terminates and returns to the terminal shell, a user can inspect what exit code was used by executing the following command: $ echo $? Note that using echo $? a second time would show the exit status of the first echo command; you would need to rerun your program and cause it to exit in order to check the exit status again. Mark Command In order to mark a square as definitely containing a mine, the mark or m command is used. The syntax format for this command is as follows: - ["mark"/"m"]-[(int)]-[(int)]- . The second and third tokens indicate the row and column indices, respectively, of the square to be revealed. Let's go back to our 18 -by- 10 example. Suppose that the player wants to mark square (1, 2). Here is an example of what that might look like. Rounds Completed: 1 | 1 1 | 1 | 1 1 1 1 1 1 1 2 31 4 | 5 6 7 8 9 1 1 | 1 1 1 1 1 1 1 1 2 3 4 5 6 7 8 9 minesweeper-alpha: m 1 2 Rounds Completed: 1 1 1 | FI 1 | 1 1 1 1 1 1 11 2 31 4 5 | 6 | 7 | 81 9 1 1 1 1 1 1 1 1 1 1 1 2 3 4 5 6 7 8 9 minesweeper-alpha: After the player correctly entered the command m 1 2, the state of the game updates (e.g., number of rounds completed, the grid, etc.), and the next round happens. Guess Command In order to mark a square as potentially containing a mine, the guess or g command is used. The syntax format for this command is as follows: - ["guess"/"g"]-[(int)]-[(int)]- . The second and third tokens indicate the row and column indices, respectively, of the square to be revealed. Let's go back to our 10 -by- 10 example. Suppose that the player wants to guess square (1, 2). Here is an example of what that might look like. Rounds Completed: 0 1 1 1 1 1 1 1 1 1 1 1 2 3 4 5 61 7 81 9 1 1 1 1 1 1 1 1 1 1 0 1 2 3 4 5 6 7 8 9 minesweeper-alpha: g 12 Rounds Completed: 1 1 1 | 1 1 1 1 1 1 11 1 2 31 4 5 6 7 81 9 1 | 1 1 1 | 1 1 1 7 8 0 1 2 3 4 5 6 9 minesweeper-alpha: After the player correctly entered the command g 1 2, the state of the game updates (e.g., number of rounds completed, the grid, etc.), and the next round happens. No Fog Command This command removes, for the next round only, what is often referred to as the, "fog of war." All squares containing mines, whether unrevealed, marked, or guessed, will be displayed with less than and greater than symbols on either side of the square's center (as opposed to white space). Using the nofog command does use up a round. In order to issue this command, the nofog command is used. The syntax format for this command is as follows: - ["nofog"]- . Let's go back to our 10 -by- 10 example. Suppose that in this example, there are only two mines in the entire board which are located in squares (1,1) and (1,3). If the player marked square (1,1) during the first round and then used the nofog command during the second round, then here is an example of what that scenario might look like: Rounds Completed: 2 | 1 1 1 1 | | | 1 1 | 1 1 1 1 1 |
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
