A Minesweeper-inspired puzzle game built with Java Swing, where players navigate a golf course grid to locate hidden gophers before they can tee off.
Find the Gopher reimagines the classic Minesweeper formula with a golf course theme. Players are presented with an 8×8 grid of hidden tiles, each concealing either a gopher or a numeric hint indicating how many gophers occupy adjacent cells. The objective is to identify and flag all gopher locations without accidentally digging one up. Successfully marking every gopher clears the course for a round of golf — but reveal a gopher, and you fall into the hole.
- Interactive 8×8 Grid Board — A dynamically generated game board with randomized gopher placement on every new game.
- Three-State Tile Cycling — Each tile cycles through hidden, flagged (question mark), and reveal-ready states, giving players full control over their decisions.
- Adjacency Number Hints — Tiles adjacent to gophers display numeric indicators (1–8) calculated across all eight neighboring cells, including diagonals.
- Recursive Auto-Reveal — Revealing an empty tile (zero adjacent gophers) automatically cascades and uncovers all connected safe tiles, accelerating gameplay.
- Confirmation Prompt on Reveal — A dialog box asks players to confirm before committing to a tile reveal, preventing accidental losses.
- Win/Loss Validation — A submit button evaluates the board state, checking that all gophers are correctly flagged and no safe tiles are incorrectly marked.
- Post-Game Board Reveal — After submission or a loss, the full board is uncovered so players can review gopher positions and learn from their strategy.
| Component | Technology |
|---|---|
| Language | Java |
| GUI Framework | Java Swing (AWT) |
| Layout | GridLayout, FlowLayout |
| Architecture | Event-driven MVC |
project3Main (Entry Point)
└── JFrame
└── GUISetup (JPanel — View + Controller)
├── JButton[8][8] grid — User interaction layer
├── TileListener — Event handler for clicks and submission
└── board (Model)
├── tile[8][8] — Individual cell state management
├── setGophers() — Random gopher placement
├── setNumbers() — Adjacency calculation engine
├── reveal() — Recursive flood-fill for empty regions
└── isWon() — Win condition evaluator
Data Flow:
project3Maininitializes the JFrame window and mounts theGUISetuppanel.GUISetupconstructs the 8×8 button grid and delegates game logic to theboardmodel.boardrandomly places 8 gophers, then computes adjacency numbers for all non-gopher tiles (handling corners, edges, and interior cells).- Player clicks trigger
TileListener, which cycles tile states and, on confirmed reveal, invokes the recursivereveal()method on the model. - If the revealed tile is a gopher, the game ends with a full board reveal. If empty (0 neighbors), flood-fill exposes all connected safe tiles.
- The submit button calls
isWon()to verify that all flagged tiles are gophers and no non-gopher tiles are incorrectly flagged.
- Java Development Kit (JDK) 8 or higher
- A terminal or IDE that supports Java compilation
# Clone the repository
git clone https://github.com/samie-mirghani/find-the-gopher.git
cd find-the-gopher
# Compile all source files
javac *.java
# Launch the game
java project3MainThe game expects the following image files in the project root directory:
| File | Purpose |
|---|---|
back.png |
Default hidden tile face |
Question_mark.png |
Flagged tile indicator |
caddyshack-gopher.jpg |
Gopher reveal image |
num1.jpg – num8.jpg |
Adjacency number tile images |
Note: Image assets are not included in the repository. You will need to provide your own images matching the filenames above.
- Click a tile once to flag it with a question mark (marking it as a suspected gopher).
- Click again to enter reveal mode — a confirmation dialog will appear.
- Confirm the reveal to uncover the tile:
- If it's a number, it shows how many gophers are in the 8 surrounding cells.
- If it's empty (0 neighbors), all connected safe tiles auto-reveal.
- If it's a gopher, you fall in the hole and the game ends.
- Click "Submit" when you believe all gophers are flagged to check your answer.
java · swing · minesweeper · puzzle-game · desktop-game · gui-application · grid-game
A Minesweeper-style puzzle game built in Java Swing where players locate hidden gophers on a golf course grid using adjacency hints and recursive tile reveals.
This project was developed as part of a CPSC 220 course assignment.