Project Details

Pacman Game in Console C++ - Free Download

C++ Project

Playing Pacman is easy to learn and hard to master (like all classic games). Simply score as many points as you can eating the small dots all around the maze. 1 point per dot.

Pacman Game in C++ is a simple console application or a mini clip game.

This game is designed for the purpose of entertainment.

It resembles the snake game in c++ to some extent in which the Pacman should be driven in such a way that it moves along the predefined blue path so that the path is erased or eaten by Pacman. More you erase the path, more score you gain; the game is easy to play.

Here, I have presented the source code and output screens for this project.

The source code of the Pacman Game in C++ has been written in C++ programming language and we used DEV C++ for developing this game. You can download the source code for this project from the link below.

In this project First you have to select game level.

After selecting game level you will have to play the game.

In game eater is shown by using letter , letter represents the pacman.

Below you can see source code of this project and you can also see screenshots of this mini c++ project.

Source Code :

Packman Game project is a game application which is developed in C++ platform. This C++ project with tutorial and guide for developing a code. Packman Game is a open source you can Download zip and edit as per you need. If you want more latest C/C++ projects here. This is simple and basic level small project for learning purpose. Also you can modified this system as per your requriments and develop a perfect advance level project. Zip file containing the source code that can be extracted and then imported into C. This Source code for BE, BTech, MCA, BCA, Engineering, Bs.CS, IT, Software Engineering final year students can submit in college. This script is developed by Muhammad Yazdan Haider. This game application is 100% working smooth without any bug. It is developed using C++. This software code helpful in academic projects for students. We have a great collection of C/C++ projects.

Below is Source Code of Pacman in C++.

#include <iostream>
#include <stdio.h>
#include<windows.h>
#include<string>
#include<vector>
//******welcome to the pacman game made by muhammad yazdan haider*********
using namespace std;
char tmp_map[18][32];

char map[18][32] = {
	"+___________ YAZDAN __________+",
	"|    #                        |",
	"|         /|         |        |",
	"|### ## ###|   ####  |# ## ###|",
	"|                             |",
	"|  ###  ##|         #     |   |",
	"|         |           #####   |",
	"| |  # |  | #####     |       |",
	"| |    |  |     #     |  # #  |",
	"| ######  |     #     |       |",
	"|           #####     |       |",
	"|  #### ##        #####       |",
	"|                             |",                             
	"| ###  ##     ##       ### ## |",
	"|      |         T   T  |     |",
	"|# # ##|# ## ## #|   |  |     |",
	"|      |         #####     # #|",
	"+_____________________________+"
	};

void ShowMap()
{
	for(int i = 0; i < 18; i++) {
		printf("%s\n",map[i] );
	}
}

void gotoxy( short x, short y )
{
    HANDLE hStdout = GetStdHandle(STD_OUTPUT_HANDLE) ;
    COORD position = { x, y } ;
    SetConsoleCursorPosition( hStdout, position ) ;
}

class entity {
public:
	entity( int x, int y ){
		this ->x = x;
		this ->y = y;
	}

	void move_x( int p ){
		if( map[y][x+p] == ' ' ) x += p;
	}

	void move_y( int p ){
		if( map[y+p][x] == ' ' ) y += p;
	}

	void move( int p, int q ){
		x += p;
		y += q;
	}

	int get_x(){ return x; }
	int get_y(){ return y; }

	void draw( char p ){
		map[x][y] = p;
		gotoxy( x, y ); printf( "%c", p );
	}

private:
	int x;
	int y;
};

struct walk {
	short walk_count;
	short x;
	short y;
	short back;
};

struct target {
	short x;
	short y;
};

vector<target> walk_queue;

vector<walk> BFSArray;

void AddArray( int x, int y, int wc , int back ){
	if( tmp_map[y][x] == ' ' || tmp_map[y][x] == '.' ){
		tmp_map[y][x] = '#';
		walk tmp;
		tmp.x = x;
		tmp.y = y;
		tmp.walk_count = wc;
		tmp.back = back;
		BFSArray.push_back( tmp );
	}
}

void FindPath( int sx, int sy, int x, int y ){
	memcpy( tmp_map, map, sizeof(map) );
	BFSArray.clear();
	walk tmp;
	tmp.x = sx;
	tmp.y = sy;
	tmp.walk_count = 0;
	tmp.back = -1;
	BFSArray.push_back( tmp );

	int i = 0;
	while( i < BFSArray.size() ){
		if( BFSArray[i].x == x && BFSArray[i].y == y ){
			walk_queue.clear();
			target tmp2;
			while( BFSArray[i].walk_count != 0 ){
				tmp2.x = BFSArray[i].x;
				tmp2.y = BFSArray[i].y;
				walk_queue.push_back( tmp2 );

				i = BFSArray[i].back;
			}

			break;
		}

		AddArray( BFSArray[i].x+1, BFSArray[i].y, BFSArray[i].walk_count+1, i );
		AddArray( BFSArray[i].x-1, BFSArray[i].y, BFSArray[i].walk_count+1, i );
		AddArray( BFSArray[i].x, BFSArray[i].y+1, BFSArray[i].walk_count+1, i );
		AddArray( BFSArray[i].x, BFSArray[i].y-1, BFSArray[i].walk_count+1, i );

		
		i++;
	}

	BFSArray.clear();
}


int main()
{
	system("color F2");
	cout<<"Welcome to Pacman Game made By yazdan haider\n";
    bool running = true;
	int x = 15; // hero x
	int y = 16; // hero y
	int old_x;
	int old_y;

	int ex = 1;
	int ey = 1;


	int pts = 0;

	printf("Instruction:\n1. Arrow Keys to move pacman\n2. Eat the dots produced by the Eater to gain poins\n3. Don't get caught by the Eater\n\n");
	printf("H -> Hard\nN -> Normal\nE -> Easy\n\nInput : ");

	char diffi;
	int speedmod = 3;

	cin >> diffi;

	if( diffi == 'N' ){
		speedmod = 2;
	}else if( diffi == 'H' ){
		speedmod = 1;
	}

	system("cls");
    ShowMap();

	gotoxy( x, y ); cout << "H";

	int frame = 0;

	FindPath( ex,ey,x,y );

	while( running ){
		gotoxy( x, y ); cout << " ";

		old_x = x;
		old_y = y;

		if ( GetAsyncKeyState( VK_UP ) ){
			if( map[y-1][x] == '.' ){ y--; pts++; } else
			if( map[y-1][x] == ' ' ) y--;
		}
		if ( GetAsyncKeyState( VK_DOWN ) ){
			if( map[y+1][x] == '.' ){ y++; pts++; } else
			if( map[y+1][x] == ' ' ) y++;
		}
		if ( GetAsyncKeyState( VK_LEFT ) ){
			if( map[y][x-1] == '.' ){ x--; pts++; } else
			if( map[y][x-1] == ' ' ) x--;
		}
		if ( GetAsyncKeyState( VK_RIGHT ) ){
			if( map[y][x+1] == '.' ){ x++; pts++; } else
			if( map[y][x+1] == ' ' ) x++;
		}

		if( old_x != x || old_y != y ){
			FindPath( ex,ey,x,y );
		}

		gotoxy( x,y ); cout << "H";

		map[ey][ex] = '.';
		gotoxy( ex, ey ); cout << ".";

		if( frame%speedmod == 0 && walk_queue.size() != 0 ){
			ex = walk_queue.back().x;
			ey = walk_queue.back().y;
			walk_queue.pop_back();
		}

		gotoxy( ex, ey ); cout << "E";

		if( ex == x && ey == y ){
			break;
		}


		gotoxy( 32, 18 );
		gotoxy( 32, 1 ); cout << pts;
		Sleep( 100 );
		frame++;
	}

	system("cls");
	printf("You Lose and your score is : %i", pts );
	cin.get();
	cin.get();
	cin.get();
	cin.get();
	cin.get();
	cin.get();
	cin.get();
	cin.get();

	return 0;
}

Screenshots:

Here are some of the screenshots of this mini pacman c++ project , that are given below.

Download pacman game for free and enjoy playing it.

You can dowlnoad it by use for learning pupose that will much help you to learn you c++.

Playing Screen :

End Game Screen :

Level Selecting Screen :

Login to Download

Our Services

Below is the list of other services that we are providing to our valuable customers.

If you want to Grab any of our Service you can contact us on given contacts

  • Website Development
  • Software Development
  • Android Apps Development
  • Hosting + Domain
  • Search Engine Marketing (SEM)
  • Search Engine Optimization (SEO)
  • Social Media Marketing (SMM)
  • SMS Marketing
  • Email Marketing
  • Wordpress Development
  • PHP Open Cart Development
  • Digital Media Marketing
  • Digital Brand Promotion
  • Graphic Designing
  • Video Animation

Search Projects

Enter some keywords to search

Other Projects / Scripts

WHMCS Free Download - Hosting.....


PHP / MYSQL Project

WHMCS is an all-in-one client management, billing and support solution for online hosting businesses. WHMCS handles everything from signup to termina.....

View Details

Time Ago System in PHP


PHP Project

In this tutorial we will talk about how we can convert time to time ago system , as in many other websites you can see time as : One hour ago , or two.....

View Details

University Management System -.....


PHP / MYSQL Project

University management system in PHP and MSQL that make a bridge between admin , teachers and parents.

View Details

Ecommerce website in PHP / MyS.....


Open Cart Project

Free download Ecommerce Website in php / mysql framework Opencart, Free download ecommerce website in php, Ecommerce website in php free download , On.....

View Details

Online Book Store Project in P.....


PHP / MYSQL Project

Online Book Store Project in PHP and MySQL, Online Book Store Project is a Web-Based Online e-book Shopping Project. It is the graphical user interfac.....

View Details