Skip to content

ShayanShahrabi/Pac-Man

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Introduction

The final project of my Basic Programming course. The goal was to make a clone of the famous Pac-Man arcade game using C++.

Implemented Features :

  • Randomly Generated Map
  • Custom Colors
  • Leader Board
  • Easter Eggs

The Code In A Nutshell

How the game works

The maze is randomly generated (based on the dimensions that the user enters) using DFS algorithm. Ghosts are able to track the player through using a BFS algorithm that finds the path to Pac-Man or a block near it, this is done for sake of randomness in their behavior, otherwise they would all choose the same path and stick together! The algorithm uses a vector to queue / push_back and dequeue / pop_back the cells of the map to search for the location of Pac-Man. Since every time Pac-Man moves the coordinations of it only change by one cell updating the BFS algorithm doesn't really matter because the ghost will be in the general direction of Pac-Man. So to conclude, only the red ghost -Blinky- tracks the exact position of Pac-Man and is the most aggressive one among the 3 ghosts! The other two aim for 2 blocks ahead or 2 blocks behind Pac-Man.

Graphics

All the visuals are either ASCII art that were either drawn or copied from google and changed a bit to suit the rest of the game. I shall mention that the Unicode used is Noto Sans Canadian Aboriginal.

Saving Data

The 3 files scoreBorad.txt, maze.txt and creature.txt are used to store the data of the game. scoreBorad.txt stores the 10 highest records of players, maze.txt and creature.txt are used as checkpoints, so you can save your progress and continue playing later!
It shall be pointed out that the code checks whether these files exist, if not, it creates them. So the program will run fine if the files get deleted, the only thing that happens is that there won't be any pre-loaded data.

How To Run The Code

It's worthy of mention that the code uses libraries like windows.h which is only available in Windows operating system, so be sure to run the code on an appropriate device. When your environment is ready, either clone the repo or download it as a zip file. Now you can either run the code manually through opening the pacman.cpp file or just run the ‍‍‍‍‍‍‍‍‍‍‍‍‍‍pacpac.exe file. Be Careful that the GUI is designed using Unicode characters, so use an appropriate terminal that shows them correctly (something like Msys2 or the built-in terminal of VScode worked for me).

Resources

BFS algorithm
Maze generation
Understanding Ghosts behavior
Some inspirations
Noto Sans Canadian Aboriginal Font

Credits

Course Instructor: Dr. Kheradpisheh
Project Mentor: Mobin Nesari
Teammate: Farid Karimi