Skip to content

EaintMM/Pop-Bob

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 

Repository files navigation

Pop & Bob (Whack-a-Mole Game)

Description

An interactive game where the user must hit as many moles as possible within a set timeframe. The game uses Java and Java Swing for the graphical user interface (GUI).

Requirements

Features

  • Game UI: A 4x4 grid of holes where moles randomly appear.
  • Random Mole Appearance: Moles pop up from random holes every 2 seconds.
  • Timeframe Options: Players can select from three game durations:
    • 1 minute
    • 2 minutes
    • 3 minutes
  • User Interaction: Players hit the moles using mouse clicks.
  • Score Tracking: Each successful hit earns 10 points.

Gameplay Mechanics

Timeframe Mole Speed (sec) Total Moles Maximum Points
1 min 2 secs 30 300
2 mins 2 secs 60 600
3 mins 2 secs 90 900

Future Enhancements (Post-MVP)

  • Difficulty Settings:
    • Grid size variations: 3x3, 4x4, 5x5
    • Adjustable mole speed: 2 secs, 1.5 secs, 1 sec

MVP Version

  • 4x4 grid
  • 2-minute game duration
  • Constant mole speed (2 seconds per appearance)

Technologies Used

  • Java for game logic
  • Java Swing for UI development

How to Run

  1. Extract the ZIP file containing the source code.
  2. Open the folder in Visual Studio Code.
  3. Make sure you have the Java and Java Extension Pack installed in VS Code.
  4. Open the App.java file — this is the main entry point.
  5. Run the program using the "Run" button in VS Code or via the terminal:
    javac App.java
    java App
    

Known Issues

  • No major bugs found during testing.

UML Diagram

classDiagram
direction LR
    class App {
        +static void main(String[] args)
    }

    class GameController {
        -int timeFrame
        -int score
        -int totalMoles
        -int maxPoints
        -boolean isRunning
        -Timer gameTimer
        -Timer moleTimer
        -Grid grid
        -GameUI gameUI
        -Random random
        -int moleSpeed
        -static GameController gameInstance
        -int currentTime
        +GameController()
        +void initialize()
        +static synchronized GameController getInstance()
        -int calculateTotalMoles(int timeInSeconds, int moleSpeed)
        -void initTimers()
        +void placeMoleRandomly()
        +void removeAllMoles()
        +void adjustMoleSpeed(int newSpeed)
        +void startGame()
        +void endGame()
        +void resetGame()
        +boolean isRunning()
        +void updateScore(int points)
        +int getScore()
        +int getMaxPoints()
        +int getTimeRemaining()
        +void setTimeFrame(int timeFrame)
    }

    class GameUI {
        -JFrame frame
        -JPanel gridPanel
        -JPanel elementPanel
        -JLabel scoreLabel
        -JLabel timeLabel
        -JButton startButton
        -JComboBox~String~ timeSelector
        -GameController gameController
        -Grid grid
        +GameUI(GameController gameController, Grid grid)
        +void initializeUI()
        -void setupHolesGrid()
        -int getSelectedTimeInSeconds()
        -void updateSelectedTime()
        +void updateScore(int score)
        +void updateTime(int timeRemaining)
        +void showGameOver(int finalScore)
        +JButton getStartButton()
        +JComboBox~String~ getTimeSelector()
    }

    class Grid {
        -int rows
        -int columns
        -Hole[][] holes
        +Grid(int rows, int columns)
        +Hole getHole(int row, int col)
        +List~Hole~ getAllHoles()
        +int getRows()
        +int getColumns()
    }

    class Hole {
        -int row
        -int column
        -boolean hasMole
        -boolean isHit
        -JButton button
        -Mole mole
        +Hole(int row, int column)
        +void placeMole()
        +void removeMole()
        +boolean hit()
        +boolean hasMole()
        +int getRow()
        +int getColumn()
        +JButton getButton()
    }

    class Mole {
        -boolean isVisible
        +Mole()
        +void show()
        +void hide()
        +boolean isVisible()
    }

    class ResourceManager {
        +static ImageIcon loadImage(String imageName)
    }

    class UIConstants {
        +static final Color BACKGROUND_COLOR
        +static final Color GRID_BACKGROUND
        +static final Color TITLE_COLOR
        +static final Color TIME_COLOR
        +static final Color SCORE_COLOR
        +static final String TITLE_FONT
        +static final String TIME_FONT
        +static final String SCORE_FONT
        +static final int HOLE_SIZE
    }

    class GameConstants {
        +static final int DEFAULT_TIME_FRAME
        +static final int DEFAULT_MOLE_SPEED
        +static final int POINTS_PER_HIT
        +static final int DEFAULT_GRID_ROWS
        +static final int DEFAULT_GRID_COLS
        +static final String RESOURCE_PATH
        +static final String HOLE_IMAGE
        +static final String MOLE_IMAGE
    }

    class GameException {
        +GameException(String message)
        +GameException(String message, Throwable cause)
        +GameException(Throwable cause)
    }

    App --> GameController : creates
    GameController "1" *-- "1" Grid : contains
    GameController "1" *-- "1" GameUI : creates and uses
    Grid "1" *-- "*" Hole : contains
    Hole "0..1" o-- "0..1" Mole : may contain
    Hole ..> GameController : references via getInstance
    GameUI ..> UIConstants : uses
    Hole ..> ResourceManager : uses
    GameController ..> GameConstants : uses
    GameController ..> GameException : may throw
    ResourceManager ..> GameConstants : uses
    ResourceManager ..> UIConstants : uses
    
    <<singleton>> GameController
Loading

About

A java based Whack-a-Mole game

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages