PacmanGUI is a Pac-Man clone developed entirely with Java Swing, built around real-time rendering and algorithmic maze generation. This project was originally a university assignment but evolved into a personal challenge in object-oriented design, algorithmic thinking, and GUI programming.
Instead of using ready-made components like JList
or JTable
, the game board is rendered directly on a JPanel. Every frame is manually drawn via paintComponent(Graphics g)
, with character sprites, maze cells, and animations refreshed continuously. This approach required managing frame timing, collision logic, and optimized repaint cycles. It was demanding, but it also provided deep insight into how graphical applications work under the hood. The project essentially became a miniature game engine within Swing.
- The maze is generated using Breadth-First Search (BFS) to ensure every tile is reachable, creating a new playable layout every time. At the start of each session, the player is prompted to enter the desired board size, which dynamically determines the maze dimensions. This user-defined size is then used by the BFS-based maze generator to create a fully navigable layout.
- Player and enemies are animated using sprite sheets, and movements are updated through a continuous loop.
- Power-ups add dynamic gameplay: extra life ❤️, speed ⚡, bonus 🍓, and ghost elimination 🔪.
- The interface includes a live HUD for score, time, and remaining lives.
- High scores are persisted locally via file I/O.
If the GIF doesn’t display properly, open it in a new tab to see the animation.
The project follows an MVC-inspired structure, ensuring clean separation of logic, rendering, and interaction:
BoardModel
: The core game logic — manages maze generation, player/enemy updates, power-ups, and score tracking. It acts as the central state manager of the game.Cell
,CellType
,CellRenderer
: Define the visual and logical structure of each grid cell.CellRenderer
draws the game board usingGraphics2D
, ensuring smooth updates during gameplay.GameCharacter
: An abstract base class for all movable entities (Pac-Man and ghosts). Handles position, direction, and animation cycles.Enemy
: Inherits fromGameCharacter
. Implements simple AI pathfinding logic, using BFS to navigate toward the player.Pacman
: The player class that responds to keyboard input and interacts with items and ghosts.Direction
: An enum representing movement directions and their effects on game state.ExtraLifeUpgrade
(and other item classes): Manage temporary gameplay bonuses and time-limited effects.
- Written in pure Java (JDK 8+) using only Swing and AWT — no external libraries.
- Render loop relies on a timer-based update system to maintain smooth animation.
- High scores are stored in
highscores.dat
and loaded when the game starts. - The code structure promotes extensibility — adding new items, enemies, or maze types requires minimal changes.
Requirements: Java 8+ (JDK) Recommended IDE: IntelliJ IDEA
-
Open the project in IntelliJ IDEA (it will detect configuration automatically).
-
Run the class containing the
main
method to launch the game. -
Alternatively, compile manually:
javac -d out -sourcepath src $(find src -name "*.java") java -cp out <MainClassName>
Building PacmanGUI taught me how to:
- Implement BFS for procedural maze generation.
- Manage custom rendering, timing, and real-time updates using only Swing.
- Structure a medium-scale project using OOP and MVC design principles.
- Handle event-driven logic with multiple entities interacting simultaneously.
This project reflects my ability to write structured, maintainable, and performance-aware Java code. It demonstrates both technical competence and creative problem-solving — qualities I aim to bring into any professional software development environment.