The method newMineMap() can be used to generate a new mine map for a new game.Īll the classes are kept under a package called minesweeper. MineMap: A class called MineMap is designed to hold the mines in a 2D boolean array.MineSweeperMain: We further customize the JFrame, by creating a subclass called MineSweeperMain, to hold the GameBoardPanel ( JPanel) in its ContentPane. Similar to Cell, the GameBoardPanel has its own methods to paint() itself. GameBoardPanel: We also customize the JPanel, by creating a subclass called GameBoardPanel, to hold the grid of 9x9 Cells ( JButtons).The Cell has its own methods to paint() itself. Cell: We customize the JButton, by creating a subclass called Cell, with additional variables row, col and its states ( isMined, isRevealed, isFlagged), to model each cell of the game board.MineSweeperConstants: to store the named constants such as ROWS and COLS, which can be referred to as MineSweeperConstants.ROWS and MineSweeperConstants.COLS.However, it is hard to identify the row and column of the JButton triggering an event.įor better OO and modular design, we design FIVE classes (in a package called minesweeper) as shown in the above class diagram: We could simply use 10x10 JButtons arranged in 10x10 GridLayout on a JPanel/ JFrame's ContentPane. You win if all the cells not containing mines are revealed you lose if you reveal a cell containing a mine. You left-click to reveal a cell and right-click on a cell to plant/remove a flag marking suspicious mine. The objective is to clear a rectangular mine field containing hidden "mines" without detonating any of them, with help from clues about the number of neighboring mines in the revealed cells. Mine Sweeper is a single-player mind game. You could wiki "Mine Sweeper" to understand the rules of the game. Do TODO 1 and run the program (2/10 points).The pre-requsite for this assignment is: You shall be able to program "SwingPhoneApp" in the "Exercises: Graphics Programming". Unfortunately, you have only little time to complete this mini-assignment.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |