Create the following basis using the Scene Builder:
In a BorderPane the top area is to be filled with a menu. Use the Control MenuBar and the Menuu and MenuItem elements. Create a menu with which the game can be restarted or the program can be terminated. The Button Info is created by adding a button to the second menu.
In the middle aread of the BorderPane anchor a GridPane with 7x7 cells. The GridPane requires a fx:id to use it in the code. Place a TextField under the GridPane. The text field should get a fx:id as well, so it can output status messages from the program.
The class Cell contains
1. an enum DisplayState with three elements for covered, suspected and uncovered
2. an ImageView
3. the DisplayState
4. if it contains a bomb
5. the number of bombs on the 8 neighboring cells
one constructor each
- with an ImageView and hasBomb as parameter
- only with hasBomb as parameter and
- without parameter
at least one public method each
- for uncovered/revealing the content of a cell (changes the display state)
- for toggling the state suspected <-> covered
- for displaying the related pictures (only here the ImageView is accessed)
- for overwriting toString()
- the name of the pictures files to be loaded
- the characters to be used for the presentation at toString()
The class Board contains as much as possible of the game logic:
- Constants are the number of rows and columns, as well as the probability of encountering a bomb
- Attribute is two-dimensional array of cells of the class Cell
- The constructor is given an array of ImageViews and the hit probability
- This is where the cell array is created, each cell is given “its” ImageView and possibly a bomb is placed.
- A second constructor for testing gets passed boolean array that identifies the bomb locations.
As public methods exist at least one each which
- reacts to the left mouse click on a cell (leftClick(int x, int y))
- reacts to the right mouse click on cell (rightClick(int x, int y))
- returns the number of bombs hidden on the field
determines, if the game is won
- determines, if by clicking on x/y the game is lost
- overwrites toString() and builds string representation of the board in correct orientation
In FXMLDocumentController the following have to exist:
a GridPane and a TextField, which have been created in the SceneBuilder through assigning a fx:id
as a constant the hit probability, since in a later version this specification should be able to be changed via the UI
the attribute board is an instance of the class Board
as method exists at least
- initImages() returns a two-dimensional array of ImageViews, which are all children of -
gridPane and where each is assigned to a cell of the gridPane. The size of an ImageView correlates to a cell of the gridPane and changes according to the change in size of the cell (see tips).
- createBoard() assign a new instance of Board with the array of ImageViews created by initImages() to the attribute board. Before that, existing children of the GridPane must be removed with [url removed, login to view]().clear();
- initialize(..) simply calls createBoard()
- onClickBtnInfo(..) is the event that is triggered when the InfoButton is clicked. Here an Information dialog is displayed, which explain the rules for the game.
- onClickMnItmNew(..) is the event that is triggered when the menu item “New” is selected. Here createBoard() is called.
- onClickMnItmClose(..) is the event that is triggered when the menu item “Close” is selected. Here the program is terminated.
- reactOnGameEnd(boolean won) is called, when the game is won or lost and outputs an appropriate message. The user can decide if he wants to uncover a new field or terminate the program (see tips)
- onClickGridPane(..) is the event, which is triggered by a click on the GridPane. Here, you must determine which mouse button was clicked on which cell (see tips) and then react accordingly.