Skip to content

Mohitlikestocode/JavaProject_WhackAMole_Game

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

3 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

Whack-a-Mole โ€” Java Swing Game

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.

image

๐ŸŽฎ Features

  • 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

๐Ÿงฑ Project Structure

src/ โ”œโ”€โ”€ GameController.java โ”œโ”€โ”€ HoleGrid.java โ”œโ”€โ”€ GridOccupant.java โ”œโ”€โ”€ RegularMole.java โ”œโ”€โ”€ GoldenMole.java โ”œโ”€โ”€ TrapBomb.java โ”œโ”€โ”€ HoleSlot.java โ””โ”€โ”€ LeaderboardManager.java

yaml Copy code


โš™๏ธ How It Works

Object-Oriented Design

All board objects extend the abstract GridOccupant class and implement:

  • whack()
  • getIcon()

This makes adding new entity types extremely easy.

Concurrency Model

  • 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.


๐Ÿ How to Run

  1. Compile the project: javac *.java

markdown Copy code 2. Run the game: java Main

yaml Copy code

Make sure you have Java 17+ installed.


๐Ÿ“Š UML Diagram

The full UML class diagram is included in the project files.


๐Ÿ’ก Future Improvements

  • Sound effects
  • Difficulty levels
  • Animated mole sprites
  • Mobile version (JavaFX / Kotlin)

๐Ÿ‘ค Author

Mohit

About

A fun java Fx based game based upon OOP's Principles that can turn your boring day into some fun nostalgia

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published