PAC-NAM is a retro-style arcade game clone developed in C++ using the legacy Borland Graphics Interface (graphics.h). The project replicates the core mechanics of Pac-Man, including player movement, coin collection, and ghost behaviors.
What sets this implementation apart is its inclusion of selectable difficulty levels that determine the Artificial Intelligence (AI) of the ghosts. While the easy mode uses random movement, the hard mode implements a Breadth-First Search (BFS) algorithm to calculate the shortest path to the player in real-time.
- Dynamic Map Loading: Reads the game board layout from an external text file (
play_ground.txt), allowing for custom level designs. - Three Difficulty Levels:
- Easy: Ghosts move randomly.
- Medium: Ghosts move based on Euclidean distance estimation.
- Hard: Ghosts utilize a BFS Pathfinding algorithm to aggressively hunt the player.
- Classic Gameplay: Includes collision detection, score tracking, and the four classic ghosts (Blinky, Pinky, Inky, Clyde).
- Audio/Visual Effects: Uses
Beepfor sound effects and simple geometric primitives for rendering characters.
The core application source code.
- Graphics Initialization: Sets up the
graphics.hwindow (specifically configured for Turbo C++ directories). - Game Loop: Handles input capture (
getch()), movement logic, and rendering. - AI Logic: Contains the
Pathfindingfunction which implements a queue-based BFS to navigate the grid maze. - Ghost Logic: The
enemy_cioandmoveingfunctions determine the next coordinate for the ghosts based on the selected difficultylevel.
The configuration file for the level layout.
- Format: A 20x20 matrix of integers.
- Encoding:
0: Wall1: Empty Path2: Coin3: Ghost Spawn4: Player Spawn
Prerequisites:
This project relies on the legacy graphics.h library, which is native to Turbo C++. To run this on modern systems, you have two options:
Option A: Turbo C++ / DOSBox
- Install Turbo C++.
- Place the source files in the
BINdirectory. - Ensure the BGI path in the code (
c:\\turboc3\\bgi) matches your installation.
Option B: Modern GCC (MinGW) with WinBGIm
- Install MinGW.
- Download and install the WinBGIm library (a port of BGI for Windows).
- Update the include headers to
<graphics.h>and compile usingg++.
Important File Path Note:
The code currently looks for the map file at E://play_ground.txt. You must either place the file on your E: drive or modify line 550 in main.C to match your local file path:
fp = fopen("YOUR_PATH_HERE//play_ground.txt", "r");- Compile and run
main.C. - Upon launch, you will be prompted to select a difficulty level (1-3).
- Controls:
- Arrow Up: Move Up
- Arrow Down: Move Down
- Arrow Left: Move Left
- Arrow Right: Move Right
Developer Note:
"The game processes commands move-by-move, so please wait for the full execution of movements and visual/audio effects after pressing a key before pressing the next one. The game retrieves the playground from a text file, the default location of which is specified in line 550. This playground is included as a test in the form of a comment at the end of the code. Good luck!"
Default Map Layout:
You can copy this into your play_ground.txt:
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 1 1 1 1 1 1 1 1 2 2 1 1 1 1 1 1 1 1 0
0 1 1 1 4 1 1 2 2 2 2 1 1 1 1 1 1 1 1 0
0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 1 1 0
0 1 1 2 2 2 2 1 1 1 0 1 1 1 1 2 0 1 1 0
0 1 1 1 1 1 1 1 1 1 0 0 0 1 1 2 0 1 2 0
0 1 2 2 2 1 1 0 0 1 1 1 1 1 1 2 0 1 2 0
0 1 2 2 2 1 1 0 1 1 1 1 1 1 0 0 0 0 0 0
0 0 0 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0
0 1 1 1 1 1 1 1 1 1 1 2 2 2 1 1 1 1 1 0
0 1 1 1 2 2 2 2 1 1 1 2 1 1 1 1 1 2 2 0
0 1 1 1 1 1 1 1 1 0 1 2 1 1 1 1 1 2 2 0
0 1 1 1 1 1 1 1 1 0 1 1 1 1 1 0 0 0 0 0
0 1 1 2 1 0 0 0 0 0 1 1 1 1 1 1 1 1 1 0
0 1 1 2 1 1 1 1 1 1 1 1 1 0 0 0 0 1 1 0
0 1 1 2 2 2 2 1 1 1 1 0 0 0 1 2 1 1 1 0
0 1 1 2 1 1 1 1 0 0 0 0 1 1 1 2 1 1 1 0
0 1 1 2 1 3 1 1 0 1 1 1 1 2 2 2 2 2 1 0
0 1 1 1 1 1 1 1 0 1 1 1 1 1 1 2 1 1 1 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
Issues and Pull Requests are welcome. If you are porting this to a modern framework (like SFML or SDL), please create a new branch.
This project is open-source.
For any inquiries regarding the code logic, please open an issue in the repository.