A classic Pacman game implementation that runs in the terminal, built in C as an APSC 142 engineering programming project.
Navigate Pacman through a maze, collect all the dots, and avoid the two ghosts hunting you down! The game features intelligent ghost AI that can spot you when you're in their line of sight.
- Terminal-based gameplay - Runs entirely in your command line
- WASD controls - Simple and intuitive keyboard navigation
- 2 Ghost enemies - Ghosts move randomly but will chase you if they see you
- Dynamic game map - Customizable maze layout via
map.txt - Win/Loss conditions - Collect all dots to win, don't get caught by ghosts!
- Color-coded display - Enhanced visual experience with colored characters
| Key | Action |
|---|---|
W |
Move Up |
A |
Move Left |
S |
Move Down |
D |
Move Right |
- GCC compiler (C99 standard or later)
- CMake (version 3.26 or higher)
- A terminal that supports ANSI color codes
- Clone or download this repository
- Navigate to the project directory
- Create a build directory and compile:
mkdir build
cd build
cmake ..
cmake --build .Alternatively, if using CLion or another IDE with CMake support, simply open the project and build.
After building, run the executable from the build directory:
./projectImportant: Make sure to run the game in a terminal that emulates output properly. If using an IDE like CLion, enable "Emulate terminal in the output console" in your run configuration.
project/
├── apsc142project.c # Main game loop and entry point
├── colours.c/h # Terminal color output and input handling
├── defines.h # Game constants and character definitions
├── game.c/h # Core game logic (win/loss conditions, movement)
├── ghost.c/h # Ghost AI and behavior
├── map.c/h # Map loading and rendering
├── map.txt # Game map layout file
├── CMakeLists.txt # Build configuration
├── doctest.h # Testing framework header
└── tests.cpp # Unit tests
The map is defined in map.txt using the following characters:
P- Pacman starting positionG- Ghost starting positions (exactly 2 required).- Collectible dotsW- Walls (impassable)(space) - Empty walkable space
Collect all the dots on the map without being caught by the ghosts.
If Pacman occupies the same position as a ghost, you lose the game.
- Ghosts move randomly by default
- When a ghost has line of sight to Pacman (horizontal or vertical), it will chase directly toward you
- Ghosts respect walls and cannot pass through them
- Dots reappear after ghosts move over them
You can create your own maps by editing map.txt. Follow these rules:
- Use the characters defined above (
P,G,.,W,) - Include exactly 1 Pacman (
P) - Include exactly 2 Ghosts (
G) - Create interesting maze patterns with walls (
W) - Place dots (
.) for Pacman to collect
The project includes unit tests built with doctest:
./testsThe project follows modular design principles:
- Separation of concerns: Map handling, game logic, and ghost AI are in separate modules
- Global state management: Map dimensions and data are stored as global variables for easy access
- Dynamic memory allocation: Maps are loaded dynamically based on file contents
- Language: C (C99 standard)
- Compiler Flags: Strict error checking with
-Wall,-pedantic,-Werror - Memory Management: Dynamic allocation with proper cleanup
- Input Handling: Non-blocking character input using
getch() - Display: ANSI color codes for terminal output
The program returns specific error codes:
0(NO_ERROR) - Game completed successfully1(ERR_NO_MAP) - Map file not found2(ERR_NO_PACMAN) - No Pacman found on map3(ERR_NO_GHOSTS) - Fewer than 2 ghosts found on map
- Requires terminal with ANSI color support
- Input is processed one character at a time (no buffering)
- Map must be rectangular and well-formed
- No save/load game functionality
- Project Framework: APSC 142 Engineering Programming
- Copyright: Sean Kauffman 2024
This is an educational project for APSC 142. Check with your institution regarding usage and distribution policies.
Enjoy playing Terminal Pacman! 👻🟡