Class Minesweeper

java.lang.Object
net.flectone.pulse.module.command.minesweeper.model.Minesweeper

public class Minesweeper extends Object
A minesweeper board. Mines are laid only after the first click, so the opening move is always safe.
  • Constructor Details

    • Minesweeper

      public Minesweeper(int rows, int columns, int mineCount, int seed)
      Creates an unrevealed board.
      Parameters:
      rows - how many rows
      columns - how many columns
      mineCount - how many mines to lay
      seed - the seed that fixes where they go
  • Method Details

    • reveal

      public Minesweeper.RevealResult reveal(int row, int column)
      Reveals a cell, opening the surrounding empty area when the cell has no neighbouring mines.
      Parameters:
      row - the row
      column - 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 row
      column - the column
    • render

      public String render(String line, Function<Minesweeper.CellView, String> function)
      Renders the board into text.
      Parameters:
      line - what separates the rows
      function - 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 row
      column - 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

      public Random 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

      public Minesweeper.GameState getState()
    • getRevealedSafeCellCount

      public int getRevealedSafeCellCount()
    • getFlaggedCellCount

      public int getFlaggedCellCount()
    • setFlagMode

      public void setFlagMode(boolean flagMode)