A clean and responsive Whack-a-Mole game built using Java Swing, featuring a fully object-oriented design, thread-safe UI updates, and persistent leaderboard support.
- Multiple mole types:
- RegularMole โ normal points
- GoldenMole โ high bonus
- TrapBomb โ penalty
- Smooth gameplay using a dedicated engine thread
- UI rendering on the Swing Event Dispatch Thread (EDT)
- Clean separation between:
- GameController (logic)
- HoleGrid (UI)
- Custom exceptions for robust error handling
- UML class diagram included
src/ โโโ GameController.java โโโ HoleGrid.java โโโ GridOccupant.java โโโ RegularMole.java โโโ GoldenMole.java โโโ TrapBomb.java โโโ HoleSlot.java โโโ LeaderboardManager.java
yaml Copy code
All board objects extend the abstract GridOccupant class and implement:
whack()getIcon()
This makes adding new entity types extremely easy.
- Game Engine Thread handles game timing, spawning, ticking.
- EDT updates icons, labels, and board cells safely via
SwingUtilities.invokeLater().
This ensures the UI never freezes.
- Compile the project: javac *.java
markdown Copy code 2. Run the game: java Main
yaml Copy code
Make sure you have Java 17+ installed.
The full UML class diagram is included in the project files.
- Sound effects
- Difficulty levels
- Animated mole sprites
- Mobile version (JavaFX / Kotlin)
Mohit