Class Minesweeper
java.lang.Object
net.flectone.pulse.module.command.minesweeper.model.Minesweeper
A minesweeper board. Mines are laid only after the first click, so the opening move is always safe.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final recordOne cell as the renderer sees it.static enumWhether the game is still running, won or lost.static final recordWhat one reveal did to the board. -
Constructor Summary
ConstructorsConstructorDescriptionMinesweeper(int rows, int columns, int mineCount, int seed) Creates an unrevealed board. -
Method Summary
Modifier and TypeMethodDescriptionbooleancheckBounds(int row, int column) Whether a position is on the board.int[][]intboolean[][]intboolean[][]getMine()intboolean[][]intintgetRows()intgetSeed()getState()intbooleanbooleanrender(String line, Function<Minesweeper.CellView, String> function) Renders the board into text.reveal(int row, int column) Reveals a cell, opening the surrounding empty area when the cell has no neighbouring mines.voidrevealAll(boolean clearFlags) Reveals the whole board, which ends the game.voidsetFlagMode(boolean flagMode) voidtoggleFlag(int row, int column) Flags or unflags a cell.
-
Constructor Details
-
Minesweeper
public Minesweeper(int rows, int columns, int mineCount, int seed) Creates an unrevealed board.- Parameters:
rows- how many rowscolumns- how many columnsmineCount- how many mines to layseed- the seed that fixes where they go
-
-
Method Details
-
reveal
Reveals a cell, opening the surrounding empty area when the cell has no neighbouring mines.- Parameters:
row- the rowcolumn- the column- Returns:
- what the move opened, and whether it hit a mine
-
revealAll
public void revealAll(boolean clearFlags) Reveals the whole board, which ends the game.- Parameters:
clearFlags- whether to drop the flags the player placed
-
toggleFlag
public void toggleFlag(int row, int column) Flags or unflags a cell.- Parameters:
row- the rowcolumn- the column
-
render
Renders the board into text.- Parameters:
line- what separates the rowsfunction- renders one cell- Returns:
- the rendered board
-
checkBounds
public boolean checkBounds(int row, int column) Whether a position is on the board.- Parameters:
row- the rowcolumn- the column- Returns:
- true if the cell exists
-
getRows
public int getRows() -
getColumns
public int getColumns() -
getMineCount
public int getMineCount() -
getSeed
public int getSeed() -
getTotalSafeCellCount
public int getTotalSafeCellCount() -
getRandom
-
getMine
public boolean[][] getMine() -
getAdjacentMineCount
public int[][] getAdjacentMineCount() -
getRevealed
public boolean[][] getRevealed() -
getFlagged
public boolean[][] getFlagged() -
isFlagMode
public boolean isFlagMode() -
isMinesPlaced
public boolean isMinesPlaced() -
getState
-
getRevealedSafeCellCount
public int getRevealedSafeCellCount() -
getFlaggedCellCount
public int getFlaggedCellCount() -
setFlagMode
public void setFlagMode(boolean flagMode)
-