User Tools

Site Tools


cs498gd:java_console_minesweeper

Java Console Minesweeper : Possible Implementation


Classes and Data Structure(s)

  • class Cell
  • 2D array of Cells; call it grid
    • Cell[][] grid = new Cell[ ROWS_IN_GRID ][ COLUMNS_IN_GRID ];

Steps

  • Create Cell class (Cell.java)
  • Seed random number generator.
  • Declare 2D grid of Cells.
  • Toggle visibility of all Cells to OFF.
  • Determine number of mines to plant.
    • About 10 mines for every 81 Cells.
  • (method) Plant mines randomly.
    • Toggle mined status of a number of Cells to ON.
  • (method) Calculate number of surrounding mines for all Cells.
    • Set mineCount number for all Cells.
  • (method) Display game grid to player.
  • Loop to get player input. (o, f, ?, c, q) and row, col
    • o: toggle visibility of Cell(row, col) to ON
      • If player hit mine at row, col, LOSE.
        • Display end game grid to player with LOSE message.
      • If Cell(row, col) has mineCount==0, call clearZero() method.
    • f: toggle flagged status of Cell(row, col) to ON
    • ?: toggle questioned status of Cell(row, col) to ON
    • c: toggle flagged, questioned status of Cell(row, col) to OFF
    • q: QUIT
    • End of Loop:
      • (method) Check for WIN.
        • Did player flag all mined Cells and not flag any unmined Cells?
          • If yes, display end game grid to player with WIN message.
      • Display game grid to player, and continue game.

cs498gd/java_console_minesweeper.txt · Last modified: by jchung

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki