Вы находитесь на странице: 1из 11

Pacman Game in C

Posted by: Rajendra Bohara May 30, 2014 in C Projects, Gaming Projects Leave a comment
Pacman Game in C is a simple console application or a mini clip game designed for the purpose of
entertainment. It resembles the snake game 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 the
Integrated Development Environment (IDE) in which the project was developed is Code::Blocks
using GCC compiler. You can download the source code, application files plus other files for this
project from the link below.
Download Pacman Game in C
The .c files of Pacman Game have been listed as follows:
main.c
map.c
move_guide.c
accessories.h
The user defined header file created in the source code of the game is header.h. The C files of the
game are for controlling the motion & direction of Pacman as well as to create the path. Pacman
Game in Cgives the clear concept of use of file handling, the use of user defined header files,
combination of number of C files in a single project etc.
The Pacman Game in C is so simple to stat, play and terminate. In order to play the game, you
should just click on the application file (.exe file) of the game. Then, you will see the game window in
which you will have to drive the Pacman along the thick blue lines in rectangular format.
The direction of Pacman is controlled with the navigation keys (up, down, left and right keys) of the
key board. Space bar pauses the movement of Pacman. If you are able to drive the Pacman along all
the lines so that Pacman eats all, you will be winner.
Output Screen for Pacman Game in C:
Download
Pacman Game in C
You can use this Pacman Game in C as your semester project or you can use it to learn C
programming and application or simply you can use it as a game for entertainment. Try making
modifications to the project if you are going to submit as your college/school project.
See Projects in C and C++
The source code and other files of the Pacman Game in C have been tried to make bug free as far
as it was possible. It has been coded in project format which consists of four c files (i.e .c files) and a
user defined header file ( i.e. .h file). In order to make the source code user friendly, a number of
comments are included in the source code of game. If you find any error or imperfections, your
feedbacks and suggestions are warmly welcomed.


Captcha program in c
This program generates captcha, a captcha is a random code generated using some
algorithm. We will use random function in our code. These are used in typing tutors and in
website to check whether a human is operating on a website.
C programming code
#include<stdlib.h>
#include<dos.h>
#include<graphics.h>

main()
{
int i = 0, key, num, midx, gd = DETECT, gm;
char a[10];

initgraph(&gd,&gm,"C:\\TC\\BGI");

midx = getmaxx()/2;

settextstyle(SCRIPT_FONT,HORIZ_DIR,5);
settextjustify(CENTER_TEXT,CENTER_TEXT);
setcolor(GREEN);
outtextxy(midx,20,"CAPTCHA");
settextstyle(SCRIPT_FONT,HORIZ_DIR,2);
outtextxy(midx,125,"Press any key to change the generated random code
\"captcha\"");
outtextxy(midx,150,"Press escape key to exit...");

setcolor(WHITE);
setviewport(100,200,600,400,1);
setcolor(RED);
randomize();

while(1)
{
while(i<6)
{
num = random(3);

if ( num == 0 )
a[i] = 65 + random(26); /* 65 is the ASCII value of A */
else if ( num == 1)
a[i] = 97 + random(26); /* 97 is the ASCII value of a */
else
a[i] = 48 + random(10); /* 48 is the ASCII value of 0 */
i++;
}
a[i] = '\0';
outtextxy(210,100,a);
key = getch();

if( key == 27 ) /* escape key*/
exit(0);
clearviewport();
i = 0;
}
}

Web browser project in c, c program
to open a website/url
This program opens a website entered by the user. User can open any website .It will launch
Mozilla Firefox web browser to open a website so it should be installed on your computer, if
you are using an another web browser then you can change the path in the program.
C programming code
#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
#include <graphics.h>
#include <dos.h>
#include <string.h>

void initialize_graphics_mode();
int get_key();
void draw();

union REGS i, o;

main()
{
int key, i = 0, xpos, ypos, button;
char arr[200], temp[5], *ptr;
char a[] = "C:\\Progra~1\\Mozill~1\\firefox ";

strcpy(arr,a);

i = strlen(a);

initialize_graphics_mode();

draw();

while(1)
{
if(kbhit())
key = get_key();

if((key>=97&&key<=122)||(key>=65&&key<=90)||key==46||key==47||key==63)
{
arr[i] = key;
sprintf(temp,"%c",arr[i]);
outtext(temp);
if(getx()>470)
{
clearviewport();
moveto(5,2);
}
i++;
}
else if ( key == 13 )
{
arr[i] = '\0';
system(arr);
break;
}
else if ( key == 27 )
{
closegraph();
exit(EXIT_SUCCESS);
}
if(button==1&&xpos>=150&&xpos<=480&&ypos>=300&&ypos<=330)
{
system("C:\\Progra~1\\Mozill~1\\firefox programmingsimplified.com");
break;
}
key = -1;
}

closegraph();
return 0;
}

void initialize_graphics_mode()
{
int gd = DETECT, gm, errorcode;

initgraph(&gd,&gm,"C:\\TC\\BGI");
errorcode = graphresult();

if( errorcode != grOk )
{
printf("Graphics error : %s\n",grapherrormsg(errorcode));

printf("Press any key to exit...\n");
getch();
exit(EXIT_FAILURE);
}
}

int get_key()
{
i.h.ah = 0;
int86(22,&i,&o);

return( o.h.al );
}

void draw()
{
settextstyle(SANS_SERIF_FONT,HORIZ_DIR,2);
outtextxy(275,11,"Web Browser");
outtextxy(155,451,"<a
href="http://www.programmingsimplified.com"">www.programmingsimplified.com"
</a>);
outtextxy(5,105,"Enter URL : ");
rectangle(120,100,600,130);
setviewport(121,101,599,129,1);
moveto(5,1);
}



Mini project Banking Record System in C++
Mini project Banking Record System is a simple database project in C++. It is done
using file handling mechanism in C++. The record of the customer can be added,
updated, searched and deleted. It is simple project made using console application of
C++. This means, no graphics component are added. The main target user of this
project are the C++ beginners who want to make the project in C++ and especially those
who are interested in File handling. This projects is complete package to learn how to
use file as database. The complete source code for the project is given below:
/*********************************************************************************
*

Program Name : Banking Record System

Language Used : C++

by Bibek Subedi

Tribhuvan University, Nepal

**********************************************************************************
*/


#include<iostream>
#include<fstream>
#include<cstdlib>
using std::cout;
using std::cin;
using std::endl;
using std::fstream;
using std::ofstream;
using std::ifstream;
using std::ios;
class account_query
{
private:
char account_number[20];
char firstName[10];
char lastName[10];
float total_Balance;
public:
void read_data();
void show_data();
void write_rec();
void read_rec();
void search_rec();
void edit_rec();
void delete_rec();
};
void account_query::read_data()
{
cout<<"\nEnter Account Number: ";
cin>>account_number;
cout<<"Enter First Name: ";
cin>>firstName;
cout<<"Enter Last Name: ";
cin>>lastName;
cout<<"Enter Balance: ";
cin>>total_Balance;
cout<<endl;
}
void account_query::show_data()
{
cout<<"Account Number: "<<account_number<<endl;
cout<<"First Name: "<<firstName<<endl;
cout<<"Last Name: "<<lastName<<endl;
cout<<"Current Balance: Rs. "<<total_Balance<<endl;
cout<<"-------------------------------"<<endl;
}
void account_query::write_rec()
{
ofstream outfile;
outfile.open("record.bank", ios::binary|ios::app);
read_data();
outfile.write(reinterpret_cast<char *>(this), sizeof(*this));
outfile.close();
}
void account_query::read_rec()
{
ifstream infile;
infile.open("record.bank", ios::binary);
if(!infile)
{
cout<<"Error in Opening! File Not Found!!"<<endl;
return;
}
cout<<"\n****Data from file****"<<endl;
while(!infile.eof())
{
if(infile.read(reinterpret_cast<char*>(this), sizeof(*this))>0)
{
show_data();
}
}
infile.close();
}
void account_query::search_rec()
{
int n;
ifstream infile;
infile.open("record.bank", ios::binary);
if(!infile)
{
cout<<"\nError in opening! File Not Found!!"<<endl;
return;
}
infile.seekg(0,ios::end);
int count = infile.tellg()/sizeof(*this);
cout<<"\n There are "<<count<<" record in the file";
cout<<"\n Enter Record Number to Search: ";
cin>>n;
infile.seekg((n-1)*sizeof(*this));
infile.read(reinterpret_cast<char*>(this), sizeof(*this));
show_data();
}
void account_query::edit_rec()
{
int n;
fstream iofile;
iofile.open("record.bank", ios::in|ios::binary);
if(!iofile)
{
cout<<"\nError in opening! File Not Found!!"<<endl;
return;
}
iofile.seekg(0, ios::end);
int count = iofile.tellg()/sizeof(*this);
cout<<"\n There are "<<count<<" record in the file";
cout<<"\n Enter Record Number to edit: ";
cin>>n;
iofile.seekg((n-1)*sizeof(*this));
iofile.read(reinterpret_cast<char*>(this), sizeof(*this));
cout<<"Record "<<n<<" has following data"<<endl;
show_data();
iofile.close();
iofile.open("record.bank", ios::out|ios::in|ios::binary);
iofile.seekp((n-1)*sizeof(*this));
cout<<"\nEnter data to Modify "<<endl;
read_data();
iofile.write(reinterpret_cast<char*>(this), sizeof(*this));
}
void account_query::delete_rec()
{
int n;
ifstream infile;
infile.open("record.bank", ios::binary);
if(!infile)
{
cout<<"\nError in opening! File Not Found!!"<<endl;
return;
}
infile.seekg(0,ios::end);
int count = infile.tellg()/sizeof(*this);
cout<<"\n There are "<<count<<" record in the file";
cout<<"\n Enter Record Number to Delete: ";
cin>>n;
fstream tmpfile;
tmpfile.open("tmpfile.bank", ios::out|ios::binary);
infile.seekg(0);
for(int i=0; i<count; i++)
{
infile.read(reinterpret_cast<char*>(this),sizeof(*this));
if(i==(n-1))
continue;
tmpfile.write(reinterpret_cast<char*>(this), sizeof(*this));
}
infile.close();
tmpfile.close();
remove("record.bank");
rename("tmpfile.bank", "record.bank");
}
int main()
{
account_query A;
int choice;
cout<<"***Acount Information System***"<<endl;
while(true)
{
cout<<"Select one option below ";
cout<<"\n\t1-->Add record to file";
cout<<"\n\t2-->Show record from file";
cout<<"\n\t3-->Search Record from file";
cout<<"\n\t4-->Update Record";
cout<<"\n\t5-->Delete Record";
cout<<"\n\t6-->Quit";
cout<<"\nEnter your choice: ";
cin>>choice;
switch(choice)
{
case 1:
A.write_rec();
break;
case 2:
A.read_rec();
break;
case 3:
A.search_rec();
break;
case 4:
A.edit_rec();
break;
case 5:
A.delete_rec();
break;
case 6:
exit(0);
break;
default:
cout<<"\nEnter corret choice";
exit(0);
}
}
system("pause");
return 0;
}

Вам также может понравиться