/Pac-Man

This project is a simplified version of Pac-Man with randomly generated maps, custom colors, and a leaderboard. It uses DFS for maze generation and BFS for ghost behavior. The visuals use ASCII art and Unicode characters, and progress is saved in a text file.

Primary LanguageC++MIT LicenseMIT

Introduction

Pac-Man is a Japanese video game franchise published in the 1980s. It is one of the longest-running, best-selling, and highest-grossing video game franchises in history. For my final project in the Basic Programming course, I aimed to build a simple and functional version of Pac-Man.

pacman

Project Plans

Project Declaration:

As mentioned earlier, my goal was to create a simplified version of Pac-Man using C++ and implementing graphics with Unicode and ASCII characters.

Project Goals:

The main objective of this project was to implement all the features of the original game while adding a touch of creativity, without compromising the speed and functionality of the program. Additionally, it was crucial to meet all the requirements set by the judges in order to achieve the highest score among the other projects.

Additional Features:

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

Implementations

Maze Generation

The map is randomly generated based on the dimensions entered by the user, utilizing the Depth-First Search (DFS) algorithm. This functionality has been implemented using a class named maze. To achieve randomness in map generation, I utilized the C++ random library:

random_device rd;
mt19937 eng(rd());
uniform_int_distribution<mt19937::result_type> random(1,4);
Orientation random_direction = Orientation(random(eng));

Ghosts Behavior

To enable the ghosts to track the player, I utilized a simple Breadth-First Search (BFS) algorithm that finds the path to Pac-Man or a nearby block. This was done to introduce randomness in the ghost behavior, as otherwise, they would all choose the same path and stick together. Notably, the red ghost, known as Blinky, tracks the exact position of the player and exhibits the most aggressive behavior.

The algorithm uses a vector to queue (push_back) and dequeue (pop_back) the cells of the map to search for Pac-Man's location. Since Pac-Man's coordinates change by only one cell each time it moves, updating the BFS algorithm doesn't significantly affect the ghost's position. Consequently, the ghost will be in the general direction of Pac-Man.

Graphics

All the visuals in the game consist of ASCII art, which I either created myself or modified from existing sources to suit the game's aesthetic. Additionally, Unicode characters from the Noto Sans Canadian Aboriginal font have been used.

Saving Data

To save game progress, track scores, and compete with other players, I implemented a mechanism to write and read data from a .txt file. The data is stored in a text file, which is utilized to construct the leaderboard and map as needed.

Compilation

To compile the program, follow these steps:

  1. Ensure you have a C++ compiler installed on your system. Popular options include GCC (GNU Compiler Collection) for Linux and MinGW (Minimalist GNU for Windows) for Windows.

  2. Open a terminal or command prompt and navigate to the directory containing the source code files.

  3. Run the following command to compile the program:

    g++ main.cpp -o game

    Replace g++ with the appropriate compiler command if you are using a different compiler.

  4. Once the compilation process completes without any errors, an executable file named game (or the name you specified after the -o option) will be created in the current directory.

    • On Windows, the file will have the .exe extension (game.exe).
    • On Linux, the file will have no extension (game).
  5. You can now run the game by executing the generated executable from the terminal or by double-clicking it in the file explorer.

    ./game      # Linux
    game.exe    # Windows

It's worth noting that the compilation process may vary depending on your operating system and the specific compiler you are using. Make sure to adjust the compilation commands accordingly.

Future Plans

This game possesses substantial potential for further growth and improvement. Some potential future enhancements include adding a graphical user interface (GUI), refining the chase and escape algorithms, and implementing a difficulty-based and time-based leaderboard for enhanced precision.

Resources

Credits

Course Instructor: Dr. Kheradpisheh
Project Mentor: Mobin Nesari
Teammate: Shayan Shahrabi