The Pac-Man Game is a arcade-style maze game recreated in Java using the Swing/AWT GUI framework. The player controls Pac-Man through a maze, collecting dots for points while avoiding four AI-controlled ghosts.
This project demonstrates core Object-Oriented Programming (OOP) concepts — encapsulation, reusable classes, and event-driven design — combined with real-time game logic such as collision detection, movement handling, and a game loop driven by Java's Timer class.
- Recreate the Pac-Man gameplay experience using Java.
- Apply object-oriented design principles to game development.
- Implement real-time collision detection and movement mechanics.
- Simulate basic ghost AI behavior using randomized movement.
- Demonstrate event-driven programming using keyboard input handling.
- Real-time Pac-Man movement using arrow key controls.
- Collision detection between Pac-Man, walls, ghosts, and food.
- Randomized ghost movement for unpredictable gameplay.
- Score tracking — 10 points awarded per dot collected.
- Lives system — 3 lives, with position reset on ghost collision.
- Game Over detection and restart functionality.
- Automatic maze reload once all dots are collected.
| Technology | Purpose |
|---|---|
| Java | Core game logic and application |
| Swing / AWT | GUI rendering and window management |
javax.swing.Timer |
Game loop and frame updates |
KeyListener |
Keyboard input handling |
The system consists of:
- A
Blockclass representing Pac-Man, ghosts, walls, and food items. - A tile-map based maze layout (
String[]grid) defining walls, paths, and starting positions. - A game loop (
Timer) that continuously updates positions and repaints the board. - Collision-detection logic that governs movement, scoring, and life loss.
- The maze is loaded from a tile map into wall, food, and ghost objects.
- The player presses arrow keys to set Pac-Man's direction.
- The game loop updates Pac-Man's and each ghost's position every frame.
- Collisions are checked against walls, food, and ghosts.
- Score and lives are updated based on collisions.
- The game ends when lives reach zero, and can be restarted with a key press.
Pacman-Java-Game/
│
├── README.md
├── App.java
├── PacMan.java
└── Project_Report.pdf
Note: The game also requires a set of image assets at runtime (
wall.png,blueGhost.png,orangeGhost.png,pinkGhost.png,redGhost.png,pacmanUp.png,pacmanDown.png,pacmanLeft.png,pacmanRight.png), which should be placed alongsidePacMan.javabefore running the project.
- Clone the repository:
git clone https://github.com/<your-username>/<your-repo-name>.git cd <your-repo-name>
- Make sure the required image assets are placed alongside
PacMan.java. - Compile the project:
javac App.java PacMan.java
- Run the game:
java App
- Use the arrow keys to move Pac-Man around the maze.
| Key | Action |
|---|---|
| ⬆️ Up Arrow | Move up |
| ⬇️ Down Arrow | Move down |
| ⬅️ Left Arrow | Move left |
| ➡️ Right Arrow | Move right |
| Any key (after Game Over) | Restart the game |
- Smarter, pathfinding-based ghost AI (e.g., BFS/A* chasing behavior).
- Power pellets that let Pac-Man temporarily eat ghosts.
- Multiple levels with increasing difficulty.
- Sound effects and background music.
- High-score leaderboard with persistent storage.
- Pause/resume functionality.
Detailed project documentation is available in:
- [
Project_Report.pdf] --- Project Report.pdf
The report includes:
- Project overview and key features
- Game setup and maze rendering logic
- Player controls and collision detection
- Ghost movement logic
- Restart functionality
- Sample output/screenshots
This project is developed for educational and academic purposes.