SlideShare a Scribd company logo
Page1
TABLE OF CONTENTS
S.NO TOPICS PAGE.NO
1. INTRODUCTION 2
2.
SYSTEM OBJECTIVES & AIM OF THE
PROJECT
3
3.
HARDWARE & SOFTWARE
REQUIREMENTS
4
4. THEORY 5-7
5. HEADER FILES INCLUDED 8
6. SOURCE CODE 9-23
7. OUTPUT SCREENS 24-26
8. BIBLIOGRAPHY 27
Page2
INTRODUCTION
Pac-Man[a]
is a maze arcade game developed and released by Namco in 1980.[7]
Outside Japan, the game was
published by Midway Games as part of its licensing agreement with Namco America. The player controls Pac-
Man, who must eat all the dots inside an enclosed maze while avoiding four colored ghosts. Eating large flashing
dots called power pellets causes the ghosts to turn blue, allowing Pac-Man to eat them for bonus points. It is the
first game to run on the Namco Pac-Man arcade board.
GAME PLAY:
The player navigates Pac-Man through a maze with no dead ends. The maze is filled with Pac-Dots, and
includes four roving multi-colored ghosts: Blinky, Pinky, Inky, and Clyde. There is a passageway from the left
side of the screen to the right side, one energizer in each of the four quadrants, and bonus fruits that appear in
each level.
What this game does include:
- Proper display of score and lives
- When the player gets a game over, the hi score is kept so that the player may try to beat it
- The player gains an extra life for every 10000 points earned
- All four ghosts; Blinky, Pinky, Inky, and Clyde
- Proper timing for the ghosts to first exit the ghost house
- The player and the ghosts may travel through the tunnel
- Pellets are worth 10 points while Super Pellets are worth 50 points
- Super Pellets and Super Pacman mode
- The ghosts intelligently chase/run from the player
- The ghosts move just slightly slower than Pacman when they are chasing
- The ghosts move almost half as fast as Pacman when they are blue and running away
- After a ghost is eaten, it turns white and zips back to the ghost house and then re-exits
- When the player is Super Pacman, the ghosts flash before returning to normal
- Proper animations upon completing a level, dying, or getting a game over
Page3
SYSTEM OBJECTIVES & AIM OF THE PROJECT
AIM :
The aim of pacman is to eat all of dots. It may seems easy, but it is not as simple as it seems – the task is
made difficult because of four ghosts – (pink one – Pinky, blue – Inky, red – Blinky and orange – Clyde).
They are trying to catch Pacman, and when one of them touches Pac-Man, a life is lost.
Page4
HARDWARE REQUIREMENT
COMPONENTS REQUIREMENTS
Processor Intel(R) Pentium(R) CPU N3520
@ 2.16GHz
Ram 2 GB
Hard disk drive 465 GB
Graphics memory 775 MB
SOFTWARE ENVIRONMENT
COMPONENTS REQUIREMENTS
Os 64-bit operating
system(WINDOWS 7)
Graphics Intel(R) HD Graphics
Programming Language TURBO C7 (C++)
FILES GENERATED
Text file: thepacman.txt
Programme file: thepacman.cpp
Object file: thepacman.obj
Execution file: thepacman.exe
Page5
C++ OVERVIEW
C++ is a multi-paradigm programming language that supports object-oriented programming
(OOP), created by Bjarne Stroustrup in 1983 at Bell Labs, C++ is an extension(superset) of C
programming and the programs are written in C language can run in C++ compilers.
C++ is used by programmers to create computer software. It is used to create general systems
software, drivers for various computer devices, software for servers and software for specific
applications and also widely used in the creation of video games.
USES:
C++ is used by many programmers of different types and coming from different fields. C++ is
mostly used to write device driver programs, system software, and applications that depend on
direct hardware manipulation under real-time constraints. It is also used to teach the basics of
object-oriented features because it is simple and is also used in the fields of research. Also, many
primary user interfaces and system files of Windows and Macintosh are written using C++. So,
C++ is a popular, strong and frequently used programming language of this modern programming
era.
FEATURES:
The main focus remains on data rather
than procedures.
Object-oriented programs are
segmented into parts called objects.
Data structures are designed to
categorize the objects.
Data member and functions are tied
together as a data structure.
Data can be hidden and cannot be
accessed by external functions using
access specifier.
Objects can communicate among
themselves using functions.
New data and functions can be easily
added anywhere within a program
whenever required.
Page6
Object Oriented Programming in C++
Object Oriented programming is a programming style that is associated with
the concept of Class, Objects and various other concepts revolving around
these two, like Inheritance, Polymorphism,
Abstraction, Encapsulation etc.
Encapsulation
Encapsulation is a process of combining data and
function into a single unit like capsule. This is to
avoid the access of private data members from outside the class. To achieve
encapsulation, we make all data members of class private and create public
functions, using them we can get the
values from these data members or set
the value to these data members.
Abstraction:
Abstraction is a process of hiding
irrelevant details from user.
Inheritance
Inheritance is a feature using which an object of child class
acquires the properties of parent class.
Page7
Polymorphism
Function overloading and Operator overloading are examples
of polymorphism. Polymorphism is a feature using which an
object behaves differently in different situation.
Modularity: the written program can be splitted up in to modules
by using classes and each class can be considered as a module.
File Handling using File Streams in C++
File represents storage medium for storing data or information. Streams refer to sequence of
bytes. In Files we store data i.e. text or binary data permanently and use these data to read or
write in the form of input output operations by transferring bytes of data. So we use the term File
Streams/File handling. We use the header file <fstream>
 ofstream: It represents output Stream and this is used for writing in files.
 ifstream: It represents input Stream and this is used for reading from files.
 fstream: It represents both output Stream and input Stream. So it can read from files and
write to files.
Operations in File Handling:
 Creating a file: open()
 Reading data: read()
 Writing new data: write()
 Closing a file: close()
SPECIAL OPERATIONS IN A FILE
There are few important functions to be used with file streams
like:
Page8
 tellp() - It tells the current position of the put pointer.
Syntax: filepointer.tellp()
 tellg() - It tells the current position of the get pointer.
Syntax: filepointer.tellg()
 seekp() - It moves the put pointer to mentioned location.
Syntax: filepointer.seekp(no of bytes,reference mode)
 seekg() - It moves get pointer(input) to a specified location.
Syntax: filepointer.seekg((no of bytes,reference point)
 put() - It writes a single character to file.
 get() - It reads a single character from file.
Header files included
#include<graphics.h> C graphics using
graphics.h functions can be used to draw
different shapes, display text in different fonts,
change colors and many more.
#include<stdlib.h> Perform standard utility
functions like dynamic memory allocation.
#include<ctype.h> header file of the C
Standard Library declares several functions
that are useful for testing and mapping
characters.
#include<dos.h> header file of C language
contains functions for handling interrupts,
producing sound, date and time functions etc.
#include<time.h> The time.h header defines
Page9
four variable types, two macro and various functions for manipulating date
and time.
#include<stdio.h> the header file for standard input and output.
#include<conio.h> Perform console input and console output operations like
clrscr() to clear the screen and getch() to get the character from the keyboard.
#include<iostream.h> Used as a stream of Input and Output.
#include<fstream.h> Contains function prototypes for functions that perform
input from files on disk and output to files on disk.
SOURCE CODE
#include<graphics.h>
#include<stdlib.h>
#include<ctype.h>
#include<dos.h>
#include<time.h>
#include<stdio.h>
#include<conio.h>
#include<iostream.h>
#include<fstream.h>
#define RIGHT0
#define LEFT1
#define UP2
#define DOWN 3
char name[30];
voidinitialise(void);
char endscreen(void);
voidstartscreen(void);
voidmusic(int);
Page10
voidvline(unsignedchar,int,int,int,int);
voidhline(unsignedchar,int,int,int,int);
voiddrawbox (int,int,int,int,char);
voidgamescreen(void);
voidsize (int,int);
voidwritechar(char,int,int,int);
voidmonitor(void);
voidgetkeyhit(void);
inttestkeys(void);
voidreadchar(int,int,unsignedchar*);
voidbug(int*,int*,int*,unsignedchar*);
voidmovebugright(int*,int*,unsignedchar*);
voidmovebugleft(int*,int*,unsignedchar*);
voidmovebugup(int*,int*,unsignedchar*);
voidmovebugdown(int*,int*,unsignedchar*);
voidkilleater(void);
intmaze[25][80],score,row,col,ascii,scan,liveslost,delayfactor;
intgd=DETECT,gm,midx,midy,maxx,maxy;
intbugnumber, r[5],c[5],dir[5];
unsigned charcharbelow[5];
char far *vid_mem=(char far *) 0xB8000000L ;
voidmain(void)
{
char ans ;
clrscr();
cout<<"entername:";
cin>>name;
fstreamfile;
file.open("thepacman.txt",ios::app);
file<<name;
file.close();
/* intialize randonmnumbergeneratorwiharandomvalue */
randomize ();
startscreen();
while (1)
{
/* Initializevariablesatthee4startof eachgame*/
/*create openingscreen*/
initialise();
/* Draw ther screenforthe game*/
gamescreen();
/* monitorthe movementof the bugsandthe eater*/
monitor();
/*create endingscreen*/
ans=endscreen();
Page11
/*check whetherthe userwishestocontinue playing*/
if(ans=='N')
break;
}
}
voidstartscreen(void)
{
char ch;
inti;
/* Intialize the graphicessystem*/
initgraph(&gd,&gm,"C:tcbgi");
/* get maximumx andy screencoordinates*/
maxx = getmaxx();
maxy=getmaxy();
/* calculate the centerof the screen*/
midx=maxx/2;
midy=maxy/2;
/* draw a double-linedbox*/
setcolor(GREEN);
rectangle (0,0,maxx,midy);
setcolor(BLUE);
rectangle (2,2,maxx-2,maxy-2);
setcolor(YELLOW);
/* Draw two vertical lines*/
line (55,1,55,maxy-2);
line (maxx-55,1,maxx-55,maxy-2);
/*displaythe string "EATER" ,horizontally*/
setcolor(6);
settextjustify(CENTER_TEXT,CENTER_TEXT);
settextstyle (4,HORIZ_DIR,8);
outtextxy(midx,midy,"The PACMAN");
/* Place the eatercharacter at randomon the start screen*/
intloop;
randomize();
for(loop=0;loop<40;loop++)
{
gotoxy(rand() %80,rand()%25);
music(1);
printf("%c",2);
delay(100);
}
nosound();
/*playthe startingmusic*/
Page12
/* Clearthe area enclosedbythe double-linedboundry*/
setviewport(0,0,maxx,maxy,1);
clearviewport();
/* Draw the screenfordisplayinstructions*/
setcolor(BLUE);
rectangle(30,0,maxx-33,maxy);
setcolor(YELLOW);
for (i=15;i<=maxy-15;i+=15)
{
ellipse(15,i,0,360,6,3);
ellipse(maxx-15,i,0,360,6,3);
}
setcolor(5);
settextjustify(CENTER_TEXT,TOP_TEXT);
settextstyle(4,HORIZ_DIR,5);
outtextxy(midx,60,"INSTRUCTION");
/*displayinstruction*/
settextstyle(2,HORIZ_DIR,5);
outtextxy(midx,110,"Yougoal:- Toeatupall the CRUNCHY MUNCHY ");
outtextxy(midx,130,"UNDAYscatteredthroughtoutthe BHOOLBHULLYIAN");
outtextxy(midx,170,"Yourtaskisnot a HALWA! There are 5 Rascalschasingyou ");
outtextxy(midx,210,"The Eater.Youhave towatchout for the bugs");
outtextxy(midx,250,"THISGAME IS CREATED BY HINIA MIRZHA OF CLASSXII");
outtextxy(midx,290,"COMPUTERINVESTIGATORYPROJECT");
outtextxy(midx,330,"If youare readyto start,pressany key");
setcolor(GREEN);
settextstyle (DEFAULT_FONT,HORIZ_DIR,3);
outtextxy(midx,400,"We wishyouBestof luck");
/*Wait forkeypress*/
while(!kbhit());
/*Flushthe keyboardbuffer*/
if (getch()==0)
getch();
/*Draaw the screenfor askinguser level*/
setviewport(0,0,maxx,maxy,1);
clearviewport();
rectangle(midx-200,midy-60,midx+200,midy+60);
settextstyle (DEFAULT_FONT,HORIZ_DIR,2);
outtextxy(midx,60,"SelectSpeed");
Page13
settextstyle (DEFAULT_FONT,HORIZ_DIR,1);
outtextxy(midx,90,"Slow(S)");
outtextxy(midx,105,"Medium(M)");
outtextxy(midx,120,"Fast(F)");
/*Get userlevel*/
/*flushthe keyboardbuffer*/
if ((ch=getch())==0)
getch();
/*Setthe value of variable delayfactoraccordingtolevel selected*/
switch(toupper(ch))
{
case'S':
delayfactor=100;
break;
case'M':
delayfactor=50;
break;
case'F':
delayfactor=20;
break;
default:
delayfactor=100;
}
if(delayfactor==100)
outtextxy(midx,midy,"Slow(S)");
if(delayfactor==50)
outtextxy(midx,midy,"Medium(M)");
if(delayfactor==20)
outtextxy(midx,midy,"Fast(F)");
/*Change overto textmode*/
while(!kbhit());
closegraph();
restorecrtmode();
}
voidmusic(inttype)
{
floatoctave[7]={130.81,146.83,164.81,174.61,196,220,246.94};
intn,i;
switch(type)
{
case 1:
n=random(6);
sound(octave[n]*4);
Page14
delay(50);
break;
case 2:
for(i=6;i>=0;i--){
sound(octave[i]);
delay(54);}
nosound();
break;
case 3:
sound(octave[6]*2);
delay(50);
nosound();
}}
char endscreen()
{
char ans;
initgraph(&gd,&gm,"C:TCbgi");
rectangle(0,0,maxx,maxy);
rectangle(2,2,maxx-2,maxy-2);
settextjustify(CENTER_TEXT,CENTER_TEXT);
settextstyle(TRIPLEX_FONT,HORIZ_DIR,3);
if(liveslost==3)
{
outtextxy(midx,midy-30,"BadLuck!!");
outtextxy(midx,midy,"TryAgain");}
else
{
outtextxy(midx,midy/2,"Youreallyare a");
settextstyle(DEFAULT_FONT,HORIZ_DIR,6);
outtextxy(midx,midy,"GENIUS!!");
}
settextstyle(TRIPLEX_FONT,HORIZ_DIR,3);
outtextxy(midx,midy+midy/2,"Anothergame(Y?N)...");
while(!(ans=='Y'||ans=='N'))
{
fflush(stdin);
ans=getch();
ans=toupper(ans);
}
closegraph();
restorecrtmode();
return(ans);
}
voidinitialise(void)
{
intj;
/*initialise rowandcolumnof EATere*/
row=12;
col=40;
Page15
r[0]=3;c[0]=76;
r[1]=3;c[1]=12;
r[2]=12;c[2]=4;
r[3]=14;c[3]=62;
score=0;
liveslost=0;
bugnumber=0;
for(j=0;j<4;j++)
{
dir[j]=0;
charbelow[j]=250;
}
}
voidgamescreen(void)
{
inti ;
size(32,0);/*hide cursor*/
/*Fill the screenwiththe specifiedcolor*/
drawbox (0,0,16,79,12);
//drawthe horizontal linesof the maze
/*Draw the titbits*/
hline(205,1,0,0,79);
hline(205,1,2,2,20);
hline(205,1,2,22,38);
hline(205,1,2,42,61);
hline(205,1,2,63,77);
hline(205,1,4,2,20);
hline(205,1,4,22,61);
hline(205,1,4,63,77);
hline(205,1,17,0,79);
hline(205,1,15,2,38);
hline(205,1,15,42,77);
hline(205,1,13,0,12);
hline(205,1,13,65,78);
hline(205,1,13,16,61);
hline(205,1,11,2,14);
hline(205,1,11,62,77);
hline(205,1,8,16,61);
hline(205,1,6,2,38);
hline(205,1,6,42,77);
hline(205,1,7,63,77);
hline(205,1,9,63,78);
hline(205,1,7,2,14);
hline(205,1,9,1,14);
/*Draw the columnsof the titbits*/
vline(186,1,0,0,16);
vline(186,1,79,0,16);
vline(186,1,40,0,2);
Page16
vline(186,1,40,4,6);
vline(186,1,14,12,14);
vline(186,1,40,13,15);
vline(186,1,63,12,14);
vline(186,1,40,9,11);
vline(202,1,14,15,15);
vline(202,1,63,15,15);
vline(203,1,40,0,0);
vline(203,1,40,4,4);
vline(203,1,40,8,8);
vline(203,1,40,13,13);
vline(187,1,79,0,0);
vline(201,1,0,0,0);
vline(188,1,79,17,17);
vline(200,1,0,17,17);
vline(204,1,0,9,9);
vline(204,1,0,13,13);
vline(185,1,79,9,9);
vline(185,1,79,13,13);
for(intvlin=16;vlin<=60;vlin+=2)
vline(186,1,vlin,10,11);
gotoxy(51,24);
printf("PressEscto stopthe game");
gotoxy(2,24);
printf("Point:%3d",score);
/*Place the five bugsat strategicPositions*/
writechar(2,3,76,15);
writechar(2,3,12,15);
writechar(2,12,4,15);
writechar(2,14,62,15);
/*PlayMusic*/
music(2);
}
/*Draw a box fillingthe requiredarea*/
voiddrawbox (intsr,intsc,inter,intec,charattr)
{
intr,c;
char far *v;
for(r=sr;r<=er;r++)
{for(c=sc;c<=ec;c++){
v=vid_mem+(r*160)+(c*2);
*v=250 ;
v++;
*v=attr;}}}
/* Write character and itsattributesintomemeory*/
Page17
voidwritechar(charch,intr,intc,intattr)
{
char far *v ;
/*calculate address*/
v=vid_mem+(r*160)+c*2;
*v=ch;/*store ascii code*/
v++;
*v=attr;/*store attribute */
}
/*drawshorizantal line*/
voidhline(unsignedcharch,intattr,intr,intc1,intc2)
{
intc;
for(c=c1;c<=c2;c++)
{
writechar(ch,r,c,attr);
/*if tibitplacedat rowr andcolumnc, set correspondingelementof
array maez[][]to1*/
maze[r][c]=1;
}
}
/*draws vertical line */
voidvline(unsignedcharch,intattr,intc,intr1,intr2)
{
intr;
for(r=r1;r<=r2;r++)
{
writechar(ch,r,c,attr);
/*if tibitplacedat rowr andcolumnc, set correspondingelementof
array maez[][]to1*/
maze[r][c]=1;
}
}
voidsize(intssl,intesl)
{
unionREGS i,o;
i.h.ah=1;
i.h.ch=ssl;
i.h.cl=esl;
i.h.bh=0;
int86(16,&i,&o);
}
voidmonitor(void)
{
intkey;
unsignedcharch;
while(1)
{
/*place eaterat specifiedrowandcolumn*/
writechar(1,row,col,14);
/*move bugsarounduntil a key ishit */
getkeyhit();
Page18
/*if all 3 livesof the eaterare lost*/
if(liveslost==3)
break;
/*place a space inthe positioncurrentlyoccupedbythe eater*/
writechar('',row,col,1);
/*update the positionof the eater*/
key=testkeys();
/*if invalidkeypressed*/
if(key==0)
{
/*write backeaterinitsorignal position*/
writechar(1,row,col,14);
}
else
{
/*readcharacter at the positionwhixhthe eateristooccupy */
readchar(row,col,&ch);
/*if character read istibit,incrementscore andsoundmusic*/
if(ch==250)
{
score++;
music(3);
}
if(ch==2)
killeater();
/*if character read isbug , kill the eater*/
if(liveslost==3)
break;
/*printthe latestscore*/
gotoxy(2,24);
printf("points:%3d",score);
/*if all the tibitsare eatenup*/
if(score>=692)
{
/*erase the lasttibit*/
writechar('',row,col,1);
break;
}
}
}
}
/*movesthe bugsaroubnduntil a keyishit*/
voidgetkeyhit()
{
unionREGS i,o;
intcount;
/*unti a playerhitsa key,move eachbug inturn*/
while(!kbhit())
{
/*introduce delay*/
delay(delayfactor);
bug(&r[bugnumber],&c[bugnumber],&dir[bugnumber],&charbelow[bugnumber]);
Page19
/*if all 3 livesof the eater are lost*/
if (liveslost==3)
return;
/*goto nextbug*/
bugnumber++;
/*start withthe firstbug if allfive bugs have beenmoved*/
if(bugnumber==4)
bugnumber=0;
}
/*issue interrupttoreadthe ascii code and scan code od the kay
pressed*/
i.h.ah=0;/*store service no*/
int86(22,&i,&o);/*issueinterrupt*/
ascii=o.h.al;
scan=o.h.ah;
}
/*reportswhichkeyhasbenhit*/
inttestkeys(void)
{
switch(scan)
{
case 72:/*up arrow*/
/*if path is notpresentinthe specifieddirection*/
if(maze[row-1][col]==1)
return(0);
/*update rowof eater*/
row--;
break;
case 80:/*downarrow*/
if(maze[row+1][col]==1)
return(0);
row++;
break;
case 77:/*right arrow*/
if(maze[row][col+1]==1)
return(0);
col++;
break;
case 75:/*leftarrow*/
if(maze[row][col-1]==1)
return(0);
col--;
break;
case 1:/*esckey*/
exit(0);/*terminatethe programm*/
default:
return(0);
}
Page20
}
/*readsthe character presenntatthe rowr and volumncintoch*/
voidreadchar(intr,intc,unsignedchar*ch)
{
char far *v;
/*calculate addresss*/
v=vid_mem+(r*160) +c*2;
*ch=*v;
}
/*movesthe specefybuginthe appropriate direction*/
voidbug(int*r,int*c,int*dir,unsignedchar*ch)
{
inttrials=1,flag=0;
char temp;
/*selectavaliddirectionwhichtakesthe bugclosertoeater
in eachif statementthe 1st conditioncheckswhetherthe movementin
that directionwouldmove the bugclosertothe eater, whereasthe 2nd
conditionchecksif the maze permitsamovementinthatdirection*/
if(abs(*r-1-row)<abs(*r-row)&&maze[*r-1][*c]!=1)
*dir=UP;
else
if(abs(*r+1-row)<abs(*r-row)&&maze[*r+1][*c]!=1)
*dir=DOWN;
else
if(abs(*c+1-col)<abs(*c-col)&&maze[*r][*c+1]!=1)
*dir=RIGHT;
else
if(abs(*c-1-col)<abs(*c-col)&&maze[*r][*c-1]!=1)
*dir=LEFT;
/*checkwhetherthe directionchosencontainsanotherbug,if so find
an
alternate direction*/
while(1)
{
switch(*dir)
{
case RIGHT:
/*if there isa pathto right of bug*/
if(maze[*r][*c+1]!=1)
{
/* readthe character to the right of the bug*/
readchar(*r,*c+1,&temp);
if(temp==2)
{
/*if the character is againa bug findalternate direction*/
if(maze[*r][*c-1]!=1)
*dir=LEFT;
else
{
/*if patch existstothe top of the bug*/
if (maze[*r-1][*c]!=1)
*dir=UP;
Page21
else
{
/*if path existbelow the bug*/
if(maze[*r+1][*c]!=1)
*dir=DOWN;
}
}
}
else
{
/*if there isno bugto the right of the bugbeing
considered,move the bugright*/
movebugright(r,c,ch);
flag=1;
}
}
else
{
/*since there isnopat in the RIGHT directio,
try anotherpath*/
*dir=random(4);
}
break;
case LEFT:
/*if there isa pathto the LEFT of the bug*/
if(maze[*r][*c-1]!=1)
{
/*readthe character to the ;eftof the bug*/
readchar(*r,*c-1,&temp);
if(temp==2)
{
if(maze[*r][*c+1]!=1)
*dir=RIGHT;
else
{
if(maze[*r-1][*c]!=1)
*dir=UP;
else
{
if(maze[*r+1][*c]!=1)
*dir=DOWN;
}
}
}
else
{
movebugleft(r,c,ch);
flag=1;
}
Page22
}
else
{
*dir=random(4);
}
break;
case UP:
if(maze[*r-1][*c]!=1)
{
readchar(*r-1,*c,&temp);
if(temp==2)
{
if(maze[*r][*c+1]!=1)
*dir=RIGHT;
else
{
if(maze[*r][*c-1]!=1)
*dir=LEFT;
else
{
if(maze[*r+1][*c]!=1)
*dir=DOWN;
}
}
}
else
{
movebugup(r,c,ch);
flag=1;
}
}
else
*dir=random(4);
break;
case DOWN:
if(maze[*r+1][*c]!=1)
{
readchar(*r+1,*c,&temp);
if (temp==2)
{
if(maze[*r][*c+1]!=1)
*dir=RIGHT;
else
{
if(maze[*r][*c-1]!=1)
*dir=LEFT;
else
{
if(maze[*r-1][*c]!=1)
*dir=UP;
}
}
}
else
{
movebugdown(r,c,ch);
Page23
flag=1;
}
}
else
*dir=random(4);
break;
}
if(flag==1)
break;
trials++;
if(trials>15)
break;
}
if(*r==row&&*c==col)
killeater();
}
voidmovebugleft(int*row,int*colm,unsignedchar *ch)
{
if( *ch==0)
*ch=0;
writechar(*ch,*row,*colm,12);
*colm=*colm-1;
readchar(*row,*colm,ch);
if(*ch==1)
*ch=' ';
writechar(2,*row,*colm,15);
}
voidmovebugright(int*row,int*colm,unsigned char*ch)
{
if( *ch==0)
*ch=0;
writechar(*ch,*row,*colm,12);
*colm=*colm+1;
readchar(*row,*colm,ch);
if(*ch==1)
*ch=' ';
writechar(2,*row,*colm,15);
}
voidmovebugup(int *row,int*col,unsignedchar*ch)
{
if( *ch==0)
*ch=0;
writechar(*ch,*row,*col,12);
*row=*row-1;
readchar(*row,*col,ch);
if(*ch==1)
*ch=' ';
writechar(2,*row,*col,15);
}
voidmovebugdown(int*row,int*col,unsignedchar*ch)
{
Page24
if( *ch==0)
*ch=0;
writechar(*ch,*row,*col,12);
*row=*row+1;
readchar(*row,*col,ch);
if(*ch==1)
*ch=' ';
writechar(2,*row,*col,15);
}
voidkilleater(void){
intr,c;
r=row;
c=col;
writechar(1,row,col,112);
writechar(1,23,15+liveslost*3,14);
music(2);
liveslost++;
if(liveslost==3)
return;
row=12;
col=40;
writechar(1,row,col,14);
}
OUTPUT SCREEN
Page25
Page26
Page27
Page28
BIBLIOGRAPHY
http://www.sourcecodesworld.com/source/show.asp?ScriptID=1035 (source
code)
https://www.w3schools.com/cpp/cpp_getstarted.asp (c++ introduction)
https://www.tutorialspoint.com/cplusplus/cpp_polymorphism.html
(polymorphism)
https://www.geeksforgeeks.org/inheritance-in-c/ (inheritance)
https://beginnersbook.com/2017/09/cpp-encapsulation/ (encapsulation)
https://www.studytonight.com/cpp/file-streams-in-cpp.php (file streams)
https://www.quora.com/How-is-modularity-introduced-in-c++ (modularity)
https://www.w3schools.in/cplusplus-tutorial/data-abstraction/ (abstraction)
https://en.wikipedia.org/wiki/Pac-Man (pac-man game)

More Related Content

What's hot

Tic tac toe game with graphics presentation
Tic  tac  toe game with graphics presentationTic  tac  toe game with graphics presentation
Tic tac toe game with graphics presentation
Prionto Abdullah
 
Zombi - Shoot for Survive
Zombi - Shoot for SurviveZombi - Shoot for Survive
Zombi - Shoot for Survive
Divy Singh Rathore
 
Project presentation on Phone Book
Project presentation on Phone BookProject presentation on Phone Book
Project presentation on Phone Book
Sp Gurjar
 
Car Game - Final Year Project
Car Game - Final Year ProjectCar Game - Final Year Project
Car Game - Final Year ProjectVivek Naskar
 
Final Year Game Project Report - Riko: The Aventurer
 Final Year Game Project Report - Riko: The Aventurer  Final Year Game Project Report - Riko: The Aventurer
Final Year Game Project Report - Riko: The Aventurer
Nusrat Jahan Shanta
 
report on snake game
report on snake game report on snake game
report on snake game
azhar niaz
 
Fantasy cricket game using python(intershala project)
Fantasy cricket game using python(intershala project)Fantasy cricket game using python(intershala project)
Fantasy cricket game using python(intershala project)
Rr
 
Tic Tac Toe ppt
Tic Tac Toe pptTic Tac Toe ppt
Tic Tac Toe ppt
SanchitRastogi15
 
Python games
Python gamesPython games
Python games
molw
 
Tic tac toe game code
Tic tac toe game codeTic tac toe game code
Tic tac toe game code
Upendra Sengar
 
Final project report Snake Game in Python
Final project report Snake Game in PythonFinal project report Snake Game in Python
Final project report Snake Game in Python
Muhammad Aziz
 
OpenGL Mini Projects With Source Code [ Computer Graphics ]
OpenGL Mini Projects With Source Code [ Computer Graphics ]OpenGL Mini Projects With Source Code [ Computer Graphics ]
OpenGL Mini Projects With Source Code [ Computer Graphics ]
Daffodil International University
 
The complete srs documentation of our developed game.
The complete srs documentation of our developed game. The complete srs documentation of our developed game.
The complete srs documentation of our developed game.
Isfand yar Khan
 
Final Year Game Project Presentation
Final Year Game Project Presentation Final Year Game Project Presentation
Final Year Game Project Presentation
Nusrat Jahan Shanta
 
An Introduction To Game development
An Introduction To Game developmentAn Introduction To Game development
An Introduction To Game development
Ahmed
 
408372362-Student-Result-management-System-project-report-docx.docx
408372362-Student-Result-management-System-project-report-docx.docx408372362-Student-Result-management-System-project-report-docx.docx
408372362-Student-Result-management-System-project-report-docx.docx
santhoshyadav23
 
Software Engineer- A unity 3d Game
Software Engineer- A unity 3d GameSoftware Engineer- A unity 3d Game
Software Engineer- A unity 3d Game
Isfand yar Khan
 
Tic tac toe
Tic tac toeTic tac toe
Tic tac toe
Niloy Biswas
 
SRS For Online Store
SRS For Online StoreSRS For Online Store
SRS For Online Store
Ahsan Rizwan
 

What's hot (20)

Tic tac toe game with graphics presentation
Tic  tac  toe game with graphics presentationTic  tac  toe game with graphics presentation
Tic tac toe game with graphics presentation
 
Zombi - Shoot for Survive
Zombi - Shoot for SurviveZombi - Shoot for Survive
Zombi - Shoot for Survive
 
Project presentation on Phone Book
Project presentation on Phone BookProject presentation on Phone Book
Project presentation on Phone Book
 
Car Game - Final Year Project
Car Game - Final Year ProjectCar Game - Final Year Project
Car Game - Final Year Project
 
Final Year Game Project Report - Riko: The Aventurer
 Final Year Game Project Report - Riko: The Aventurer  Final Year Game Project Report - Riko: The Aventurer
Final Year Game Project Report - Riko: The Aventurer
 
report on snake game
report on snake game report on snake game
report on snake game
 
Fantasy cricket game using python(intershala project)
Fantasy cricket game using python(intershala project)Fantasy cricket game using python(intershala project)
Fantasy cricket game using python(intershala project)
 
Tic Tac Toe ppt
Tic Tac Toe pptTic Tac Toe ppt
Tic Tac Toe ppt
 
Python games
Python gamesPython games
Python games
 
Tic tac toe game code
Tic tac toe game codeTic tac toe game code
Tic tac toe game code
 
Final project report Snake Game in Python
Final project report Snake Game in PythonFinal project report Snake Game in Python
Final project report Snake Game in Python
 
Online news 365
Online news 365Online news 365
Online news 365
 
OpenGL Mini Projects With Source Code [ Computer Graphics ]
OpenGL Mini Projects With Source Code [ Computer Graphics ]OpenGL Mini Projects With Source Code [ Computer Graphics ]
OpenGL Mini Projects With Source Code [ Computer Graphics ]
 
The complete srs documentation of our developed game.
The complete srs documentation of our developed game. The complete srs documentation of our developed game.
The complete srs documentation of our developed game.
 
Final Year Game Project Presentation
Final Year Game Project Presentation Final Year Game Project Presentation
Final Year Game Project Presentation
 
An Introduction To Game development
An Introduction To Game developmentAn Introduction To Game development
An Introduction To Game development
 
408372362-Student-Result-management-System-project-report-docx.docx
408372362-Student-Result-management-System-project-report-docx.docx408372362-Student-Result-management-System-project-report-docx.docx
408372362-Student-Result-management-System-project-report-docx.docx
 
Software Engineer- A unity 3d Game
Software Engineer- A unity 3d GameSoftware Engineer- A unity 3d Game
Software Engineer- A unity 3d Game
 
Tic tac toe
Tic tac toeTic tac toe
Tic tac toe
 
SRS For Online Store
SRS For Online StoreSRS For Online Store
SRS For Online Store
 

Similar to Pacman game computer investigatory project

Python_Introduction_Good_PPT.pptx
Python_Introduction_Good_PPT.pptxPython_Introduction_Good_PPT.pptx
Python_Introduction_Good_PPT.pptx
lemonchoos
 
C++ project
C++ projectC++ project
C++ project
AjaibalajiP
 
Raspberry Pi introduction
Raspberry Pi introductionRaspberry Pi introduction
Raspberry Pi introduction
Lotfi Messaoudi
 
GDG-MLOps using Protobuf in Unity
GDG-MLOps using Protobuf in UnityGDG-MLOps using Protobuf in Unity
GDG-MLOps using Protobuf in Unity
Ivan Chiou
 
Linux basic
Linux basicLinux basic
Linux basic
Pragyagupta37
 
Python Course.docx
Python Course.docxPython Course.docx
Python Course.docx
AdnanAhmad57885
 
Up your data game: How to use R to wrangle, analyze, and visualize data faste...
Up your data game: How to use R to wrangle, analyze, and visualize data faste...Up your data game: How to use R to wrangle, analyze, and visualize data faste...
Up your data game: How to use R to wrangle, analyze, and visualize data faste...
Charles Guedenet
 
Game Studio
Game StudioGame Studio
Game Studio
MarinaOpera
 
python workshop(one of the 15 chapters)
python workshop(one of the 15 chapters)python workshop(one of the 15 chapters)
python workshop(one of the 15 chapters)Mehul shah
 
Rrw02 Week 1 Assignment
Rrw02 Week 1 AssignmentRrw02 Week 1 Assignment
Rrw02 Week 1 Assignment
Sheri Elliott
 
មេរៀនៈ Data Structure and Algorithm in C/C++
មេរៀនៈ Data Structure and Algorithm in C/C++មេរៀនៈ Data Structure and Algorithm in C/C++
មេរៀនៈ Data Structure and Algorithm in C/C++
Ngeam Soly
 
the productive programer: mechanics
the productive programer: mechanicsthe productive programer: mechanics
the productive programer: mechanicselliando dias
 
C++ advanced PPT.pdf
C++ advanced PPT.pdfC++ advanced PPT.pdf
C++ advanced PPT.pdf
DinashMaliya3
 
Getting Started with Python
Getting Started with PythonGetting Started with Python
Getting Started with Python
Sankhya_Analytics
 
carrow - Go bindings to Apache Arrow via C++-API
carrow - Go bindings to Apache Arrow via C++-APIcarrow - Go bindings to Apache Arrow via C++-API
carrow - Go bindings to Apache Arrow via C++-API
Yoni Davidson
 
fileop report
fileop reportfileop report
fileop reportJason Lu
 
MODULE 1.pptx
MODULE 1.pptxMODULE 1.pptx
MODULE 1.pptx
KPDDRAVIDIAN
 
Introduction to Machine Learning by MARK
Introduction to Machine Learning by MARKIntroduction to Machine Learning by MARK
Introduction to Machine Learning by MARK
MRKUsafzai0607
 

Similar to Pacman game computer investigatory project (20)

Python_Introduction_Good_PPT.pptx
Python_Introduction_Good_PPT.pptxPython_Introduction_Good_PPT.pptx
Python_Introduction_Good_PPT.pptx
 
C++ project
C++ projectC++ project
C++ project
 
Raspberry Pi introduction
Raspberry Pi introductionRaspberry Pi introduction
Raspberry Pi introduction
 
GDG-MLOps using Protobuf in Unity
GDG-MLOps using Protobuf in UnityGDG-MLOps using Protobuf in Unity
GDG-MLOps using Protobuf in Unity
 
Linux basic
Linux basicLinux basic
Linux basic
 
Python Course.docx
Python Course.docxPython Course.docx
Python Course.docx
 
Up your data game: How to use R to wrangle, analyze, and visualize data faste...
Up your data game: How to use R to wrangle, analyze, and visualize data faste...Up your data game: How to use R to wrangle, analyze, and visualize data faste...
Up your data game: How to use R to wrangle, analyze, and visualize data faste...
 
Game Studio
Game StudioGame Studio
Game Studio
 
Ravi kumar
Ravi kumarRavi kumar
Ravi kumar
 
python workshop(one of the 15 chapters)
python workshop(one of the 15 chapters)python workshop(one of the 15 chapters)
python workshop(one of the 15 chapters)
 
Rrw02 Week 1 Assignment
Rrw02 Week 1 AssignmentRrw02 Week 1 Assignment
Rrw02 Week 1 Assignment
 
មេរៀនៈ Data Structure and Algorithm in C/C++
មេរៀនៈ Data Structure and Algorithm in C/C++មេរៀនៈ Data Structure and Algorithm in C/C++
មេរៀនៈ Data Structure and Algorithm in C/C++
 
Chapter 2(answer)2
Chapter 2(answer)2Chapter 2(answer)2
Chapter 2(answer)2
 
the productive programer: mechanics
the productive programer: mechanicsthe productive programer: mechanics
the productive programer: mechanics
 
C++ advanced PPT.pdf
C++ advanced PPT.pdfC++ advanced PPT.pdf
C++ advanced PPT.pdf
 
Getting Started with Python
Getting Started with PythonGetting Started with Python
Getting Started with Python
 
carrow - Go bindings to Apache Arrow via C++-API
carrow - Go bindings to Apache Arrow via C++-APIcarrow - Go bindings to Apache Arrow via C++-API
carrow - Go bindings to Apache Arrow via C++-API
 
fileop report
fileop reportfileop report
fileop report
 
MODULE 1.pptx
MODULE 1.pptxMODULE 1.pptx
MODULE 1.pptx
 
Introduction to Machine Learning by MARK
Introduction to Machine Learning by MARKIntroduction to Machine Learning by MARK
Introduction to Machine Learning by MARK
 

More from meenaloshiniG

CONFERENCE POSTER PHARMACOGNOSY.pdf
CONFERENCE POSTER PHARMACOGNOSY.pdfCONFERENCE POSTER PHARMACOGNOSY.pdf
CONFERENCE POSTER PHARMACOGNOSY.pdf
meenaloshiniG
 
HAP-CONNECTIVE TISSUE-MEENALOSHINI.pptx
HAP-CONNECTIVE TISSUE-MEENALOSHINI.pptxHAP-CONNECTIVE TISSUE-MEENALOSHINI.pptx
HAP-CONNECTIVE TISSUE-MEENALOSHINI.pptx
meenaloshiniG
 
peripheral nervous system.pptx
peripheral nervous system.pptxperipheral nervous system.pptx
peripheral nervous system.pptx
meenaloshiniG
 
SUSPENSION PHARMACEUTICS-1 BPHARM 1ST YEAR.pdf
SUSPENSION PHARMACEUTICS-1 BPHARM 1ST YEAR.pdfSUSPENSION PHARMACEUTICS-1 BPHARM 1ST YEAR.pdf
SUSPENSION PHARMACEUTICS-1 BPHARM 1ST YEAR.pdf
meenaloshiniG
 
PHYSICS INVESTIGATORY PROJECT ON THEORY OF RELATIVITY HYPOTHESIS AND CONCLUSI...
PHYSICS INVESTIGATORY PROJECT ON THEORY OF RELATIVITY HYPOTHESIS AND CONCLUSI...PHYSICS INVESTIGATORY PROJECT ON THEORY OF RELATIVITY HYPOTHESIS AND CONCLUSI...
PHYSICS INVESTIGATORY PROJECT ON THEORY OF RELATIVITY HYPOTHESIS AND CONCLUSI...
meenaloshiniG
 
cbse Biology investigatory project class 12 on neuro-biological and systemic...
 cbse Biology investigatory project class 12 on neuro-biological and systemic... cbse Biology investigatory project class 12 on neuro-biological and systemic...
cbse Biology investigatory project class 12 on neuro-biological and systemic...
meenaloshiniG
 
Solar desalination chemistry investigatory project class 12 cbse
Solar desalination chemistry investigatory project class 12 cbse Solar desalination chemistry investigatory project class 12 cbse
Solar desalination chemistry investigatory project class 12 cbse
meenaloshiniG
 
Computer investigatroy project c++ class 12
Computer investigatroy project c++ class 12Computer investigatroy project c++ class 12
Computer investigatroy project c++ class 12
meenaloshiniG
 

More from meenaloshiniG (8)

CONFERENCE POSTER PHARMACOGNOSY.pdf
CONFERENCE POSTER PHARMACOGNOSY.pdfCONFERENCE POSTER PHARMACOGNOSY.pdf
CONFERENCE POSTER PHARMACOGNOSY.pdf
 
HAP-CONNECTIVE TISSUE-MEENALOSHINI.pptx
HAP-CONNECTIVE TISSUE-MEENALOSHINI.pptxHAP-CONNECTIVE TISSUE-MEENALOSHINI.pptx
HAP-CONNECTIVE TISSUE-MEENALOSHINI.pptx
 
peripheral nervous system.pptx
peripheral nervous system.pptxperipheral nervous system.pptx
peripheral nervous system.pptx
 
SUSPENSION PHARMACEUTICS-1 BPHARM 1ST YEAR.pdf
SUSPENSION PHARMACEUTICS-1 BPHARM 1ST YEAR.pdfSUSPENSION PHARMACEUTICS-1 BPHARM 1ST YEAR.pdf
SUSPENSION PHARMACEUTICS-1 BPHARM 1ST YEAR.pdf
 
PHYSICS INVESTIGATORY PROJECT ON THEORY OF RELATIVITY HYPOTHESIS AND CONCLUSI...
PHYSICS INVESTIGATORY PROJECT ON THEORY OF RELATIVITY HYPOTHESIS AND CONCLUSI...PHYSICS INVESTIGATORY PROJECT ON THEORY OF RELATIVITY HYPOTHESIS AND CONCLUSI...
PHYSICS INVESTIGATORY PROJECT ON THEORY OF RELATIVITY HYPOTHESIS AND CONCLUSI...
 
cbse Biology investigatory project class 12 on neuro-biological and systemic...
 cbse Biology investigatory project class 12 on neuro-biological and systemic... cbse Biology investigatory project class 12 on neuro-biological and systemic...
cbse Biology investigatory project class 12 on neuro-biological and systemic...
 
Solar desalination chemistry investigatory project class 12 cbse
Solar desalination chemistry investigatory project class 12 cbse Solar desalination chemistry investigatory project class 12 cbse
Solar desalination chemistry investigatory project class 12 cbse
 
Computer investigatroy project c++ class 12
Computer investigatroy project c++ class 12Computer investigatroy project c++ class 12
Computer investigatroy project c++ class 12
 

Recently uploaded

Unit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdfUnit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Thiyagu K
 
The geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideasThe geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideas
GeoBlogs
 
The approach at University of Liverpool.pptx
The approach at University of Liverpool.pptxThe approach at University of Liverpool.pptx
The approach at University of Liverpool.pptx
Jisc
 
Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.
Ashokrao Mane college of Pharmacy Peth-Vadgaon
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
Balvir Singh
 
Digital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and ResearchDigital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and Research
Vikramjit Singh
 
Home assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdfHome assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdf
Tamralipta Mahavidyalaya
 
Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
Pavel ( NSTU)
 
Unit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdfUnit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdf
Thiyagu K
 
Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345
beazzy04
 
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
EugeneSaldivar
 
Supporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptxSupporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptx
Jisc
 
Acetabularia Information For Class 9 .docx
Acetabularia Information For Class 9  .docxAcetabularia Information For Class 9  .docx
Acetabularia Information For Class 9 .docx
vaibhavrinwa19
 
The basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptxThe basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptx
heathfieldcps1
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
DeeptiGupta154
 
1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx
JosvitaDsouza2
 
Lapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdfLapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdf
Jean Carlos Nunes Paixão
 
Polish students' mobility in the Czech Republic
Polish students' mobility in the Czech RepublicPolish students' mobility in the Czech Republic
Polish students' mobility in the Czech Republic
Anna Sz.
 
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
Nguyen Thanh Tu Collection
 
Model Attribute Check Company Auto Property
Model Attribute  Check Company Auto PropertyModel Attribute  Check Company Auto Property
Model Attribute Check Company Auto Property
Celine George
 

Recently uploaded (20)

Unit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdfUnit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdf
 
The geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideasThe geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideas
 
The approach at University of Liverpool.pptx
The approach at University of Liverpool.pptxThe approach at University of Liverpool.pptx
The approach at University of Liverpool.pptx
 
Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
 
Digital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and ResearchDigital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and Research
 
Home assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdfHome assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdf
 
Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
 
Unit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdfUnit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdf
 
Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345
 
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
 
Supporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptxSupporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptx
 
Acetabularia Information For Class 9 .docx
Acetabularia Information For Class 9  .docxAcetabularia Information For Class 9  .docx
Acetabularia Information For Class 9 .docx
 
The basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptxThe basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptx
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
 
1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx
 
Lapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdfLapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdf
 
Polish students' mobility in the Czech Republic
Polish students' mobility in the Czech RepublicPolish students' mobility in the Czech Republic
Polish students' mobility in the Czech Republic
 
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
 
Model Attribute Check Company Auto Property
Model Attribute  Check Company Auto PropertyModel Attribute  Check Company Auto Property
Model Attribute Check Company Auto Property
 

Pacman game computer investigatory project

  • 1. Page1 TABLE OF CONTENTS S.NO TOPICS PAGE.NO 1. INTRODUCTION 2 2. SYSTEM OBJECTIVES & AIM OF THE PROJECT 3 3. HARDWARE & SOFTWARE REQUIREMENTS 4 4. THEORY 5-7 5. HEADER FILES INCLUDED 8 6. SOURCE CODE 9-23 7. OUTPUT SCREENS 24-26 8. BIBLIOGRAPHY 27
  • 2. Page2 INTRODUCTION Pac-Man[a] is a maze arcade game developed and released by Namco in 1980.[7] Outside Japan, the game was published by Midway Games as part of its licensing agreement with Namco America. The player controls Pac- Man, who must eat all the dots inside an enclosed maze while avoiding four colored ghosts. Eating large flashing dots called power pellets causes the ghosts to turn blue, allowing Pac-Man to eat them for bonus points. It is the first game to run on the Namco Pac-Man arcade board. GAME PLAY: The player navigates Pac-Man through a maze with no dead ends. The maze is filled with Pac-Dots, and includes four roving multi-colored ghosts: Blinky, Pinky, Inky, and Clyde. There is a passageway from the left side of the screen to the right side, one energizer in each of the four quadrants, and bonus fruits that appear in each level. What this game does include: - Proper display of score and lives - When the player gets a game over, the hi score is kept so that the player may try to beat it - The player gains an extra life for every 10000 points earned - All four ghosts; Blinky, Pinky, Inky, and Clyde - Proper timing for the ghosts to first exit the ghost house - The player and the ghosts may travel through the tunnel - Pellets are worth 10 points while Super Pellets are worth 50 points - Super Pellets and Super Pacman mode - The ghosts intelligently chase/run from the player - The ghosts move just slightly slower than Pacman when they are chasing - The ghosts move almost half as fast as Pacman when they are blue and running away - After a ghost is eaten, it turns white and zips back to the ghost house and then re-exits - When the player is Super Pacman, the ghosts flash before returning to normal - Proper animations upon completing a level, dying, or getting a game over
  • 3. Page3 SYSTEM OBJECTIVES & AIM OF THE PROJECT AIM : The aim of pacman is to eat all of dots. It may seems easy, but it is not as simple as it seems – the task is made difficult because of four ghosts – (pink one – Pinky, blue – Inky, red – Blinky and orange – Clyde). They are trying to catch Pacman, and when one of them touches Pac-Man, a life is lost.
  • 4. Page4 HARDWARE REQUIREMENT COMPONENTS REQUIREMENTS Processor Intel(R) Pentium(R) CPU N3520 @ 2.16GHz Ram 2 GB Hard disk drive 465 GB Graphics memory 775 MB SOFTWARE ENVIRONMENT COMPONENTS REQUIREMENTS Os 64-bit operating system(WINDOWS 7) Graphics Intel(R) HD Graphics Programming Language TURBO C7 (C++) FILES GENERATED Text file: thepacman.txt Programme file: thepacman.cpp Object file: thepacman.obj Execution file: thepacman.exe
  • 5. Page5 C++ OVERVIEW C++ is a multi-paradigm programming language that supports object-oriented programming (OOP), created by Bjarne Stroustrup in 1983 at Bell Labs, C++ is an extension(superset) of C programming and the programs are written in C language can run in C++ compilers. C++ is used by programmers to create computer software. It is used to create general systems software, drivers for various computer devices, software for servers and software for specific applications and also widely used in the creation of video games. USES: C++ is used by many programmers of different types and coming from different fields. C++ is mostly used to write device driver programs, system software, and applications that depend on direct hardware manipulation under real-time constraints. It is also used to teach the basics of object-oriented features because it is simple and is also used in the fields of research. Also, many primary user interfaces and system files of Windows and Macintosh are written using C++. So, C++ is a popular, strong and frequently used programming language of this modern programming era. FEATURES: The main focus remains on data rather than procedures. Object-oriented programs are segmented into parts called objects. Data structures are designed to categorize the objects. Data member and functions are tied together as a data structure. Data can be hidden and cannot be accessed by external functions using access specifier. Objects can communicate among themselves using functions. New data and functions can be easily added anywhere within a program whenever required.
  • 6. Page6 Object Oriented Programming in C++ Object Oriented programming is a programming style that is associated with the concept of Class, Objects and various other concepts revolving around these two, like Inheritance, Polymorphism, Abstraction, Encapsulation etc. Encapsulation Encapsulation is a process of combining data and function into a single unit like capsule. This is to avoid the access of private data members from outside the class. To achieve encapsulation, we make all data members of class private and create public functions, using them we can get the values from these data members or set the value to these data members. Abstraction: Abstraction is a process of hiding irrelevant details from user. Inheritance Inheritance is a feature using which an object of child class acquires the properties of parent class.
  • 7. Page7 Polymorphism Function overloading and Operator overloading are examples of polymorphism. Polymorphism is a feature using which an object behaves differently in different situation. Modularity: the written program can be splitted up in to modules by using classes and each class can be considered as a module. File Handling using File Streams in C++ File represents storage medium for storing data or information. Streams refer to sequence of bytes. In Files we store data i.e. text or binary data permanently and use these data to read or write in the form of input output operations by transferring bytes of data. So we use the term File Streams/File handling. We use the header file <fstream>  ofstream: It represents output Stream and this is used for writing in files.  ifstream: It represents input Stream and this is used for reading from files.  fstream: It represents both output Stream and input Stream. So it can read from files and write to files. Operations in File Handling:  Creating a file: open()  Reading data: read()  Writing new data: write()  Closing a file: close() SPECIAL OPERATIONS IN A FILE There are few important functions to be used with file streams like:
  • 8. Page8  tellp() - It tells the current position of the put pointer. Syntax: filepointer.tellp()  tellg() - It tells the current position of the get pointer. Syntax: filepointer.tellg()  seekp() - It moves the put pointer to mentioned location. Syntax: filepointer.seekp(no of bytes,reference mode)  seekg() - It moves get pointer(input) to a specified location. Syntax: filepointer.seekg((no of bytes,reference point)  put() - It writes a single character to file.  get() - It reads a single character from file. Header files included #include<graphics.h> C graphics using graphics.h functions can be used to draw different shapes, display text in different fonts, change colors and many more. #include<stdlib.h> Perform standard utility functions like dynamic memory allocation. #include<ctype.h> header file of the C Standard Library declares several functions that are useful for testing and mapping characters. #include<dos.h> header file of C language contains functions for handling interrupts, producing sound, date and time functions etc. #include<time.h> The time.h header defines
  • 9. Page9 four variable types, two macro and various functions for manipulating date and time. #include<stdio.h> the header file for standard input and output. #include<conio.h> Perform console input and console output operations like clrscr() to clear the screen and getch() to get the character from the keyboard. #include<iostream.h> Used as a stream of Input and Output. #include<fstream.h> Contains function prototypes for functions that perform input from files on disk and output to files on disk. SOURCE CODE #include<graphics.h> #include<stdlib.h> #include<ctype.h> #include<dos.h> #include<time.h> #include<stdio.h> #include<conio.h> #include<iostream.h> #include<fstream.h> #define RIGHT0 #define LEFT1 #define UP2 #define DOWN 3 char name[30]; voidinitialise(void); char endscreen(void); voidstartscreen(void); voidmusic(int);
  • 10. Page10 voidvline(unsignedchar,int,int,int,int); voidhline(unsignedchar,int,int,int,int); voiddrawbox (int,int,int,int,char); voidgamescreen(void); voidsize (int,int); voidwritechar(char,int,int,int); voidmonitor(void); voidgetkeyhit(void); inttestkeys(void); voidreadchar(int,int,unsignedchar*); voidbug(int*,int*,int*,unsignedchar*); voidmovebugright(int*,int*,unsignedchar*); voidmovebugleft(int*,int*,unsignedchar*); voidmovebugup(int*,int*,unsignedchar*); voidmovebugdown(int*,int*,unsignedchar*); voidkilleater(void); intmaze[25][80],score,row,col,ascii,scan,liveslost,delayfactor; intgd=DETECT,gm,midx,midy,maxx,maxy; intbugnumber, r[5],c[5],dir[5]; unsigned charcharbelow[5]; char far *vid_mem=(char far *) 0xB8000000L ; voidmain(void) { char ans ; clrscr(); cout<<"entername:"; cin>>name; fstreamfile; file.open("thepacman.txt",ios::app); file<<name; file.close(); /* intialize randonmnumbergeneratorwiharandomvalue */ randomize (); startscreen(); while (1) { /* Initializevariablesatthee4startof eachgame*/ /*create openingscreen*/ initialise(); /* Draw ther screenforthe game*/ gamescreen(); /* monitorthe movementof the bugsandthe eater*/ monitor(); /*create endingscreen*/ ans=endscreen();
  • 11. Page11 /*check whetherthe userwishestocontinue playing*/ if(ans=='N') break; } } voidstartscreen(void) { char ch; inti; /* Intialize the graphicessystem*/ initgraph(&gd,&gm,"C:tcbgi"); /* get maximumx andy screencoordinates*/ maxx = getmaxx(); maxy=getmaxy(); /* calculate the centerof the screen*/ midx=maxx/2; midy=maxy/2; /* draw a double-linedbox*/ setcolor(GREEN); rectangle (0,0,maxx,midy); setcolor(BLUE); rectangle (2,2,maxx-2,maxy-2); setcolor(YELLOW); /* Draw two vertical lines*/ line (55,1,55,maxy-2); line (maxx-55,1,maxx-55,maxy-2); /*displaythe string "EATER" ,horizontally*/ setcolor(6); settextjustify(CENTER_TEXT,CENTER_TEXT); settextstyle (4,HORIZ_DIR,8); outtextxy(midx,midy,"The PACMAN"); /* Place the eatercharacter at randomon the start screen*/ intloop; randomize(); for(loop=0;loop<40;loop++) { gotoxy(rand() %80,rand()%25); music(1); printf("%c",2); delay(100); } nosound(); /*playthe startingmusic*/
  • 12. Page12 /* Clearthe area enclosedbythe double-linedboundry*/ setviewport(0,0,maxx,maxy,1); clearviewport(); /* Draw the screenfordisplayinstructions*/ setcolor(BLUE); rectangle(30,0,maxx-33,maxy); setcolor(YELLOW); for (i=15;i<=maxy-15;i+=15) { ellipse(15,i,0,360,6,3); ellipse(maxx-15,i,0,360,6,3); } setcolor(5); settextjustify(CENTER_TEXT,TOP_TEXT); settextstyle(4,HORIZ_DIR,5); outtextxy(midx,60,"INSTRUCTION"); /*displayinstruction*/ settextstyle(2,HORIZ_DIR,5); outtextxy(midx,110,"Yougoal:- Toeatupall the CRUNCHY MUNCHY "); outtextxy(midx,130,"UNDAYscatteredthroughtoutthe BHOOLBHULLYIAN"); outtextxy(midx,170,"Yourtaskisnot a HALWA! There are 5 Rascalschasingyou "); outtextxy(midx,210,"The Eater.Youhave towatchout for the bugs"); outtextxy(midx,250,"THISGAME IS CREATED BY HINIA MIRZHA OF CLASSXII"); outtextxy(midx,290,"COMPUTERINVESTIGATORYPROJECT"); outtextxy(midx,330,"If youare readyto start,pressany key"); setcolor(GREEN); settextstyle (DEFAULT_FONT,HORIZ_DIR,3); outtextxy(midx,400,"We wishyouBestof luck"); /*Wait forkeypress*/ while(!kbhit()); /*Flushthe keyboardbuffer*/ if (getch()==0) getch(); /*Draaw the screenfor askinguser level*/ setviewport(0,0,maxx,maxy,1); clearviewport(); rectangle(midx-200,midy-60,midx+200,midy+60); settextstyle (DEFAULT_FONT,HORIZ_DIR,2); outtextxy(midx,60,"SelectSpeed");
  • 13. Page13 settextstyle (DEFAULT_FONT,HORIZ_DIR,1); outtextxy(midx,90,"Slow(S)"); outtextxy(midx,105,"Medium(M)"); outtextxy(midx,120,"Fast(F)"); /*Get userlevel*/ /*flushthe keyboardbuffer*/ if ((ch=getch())==0) getch(); /*Setthe value of variable delayfactoraccordingtolevel selected*/ switch(toupper(ch)) { case'S': delayfactor=100; break; case'M': delayfactor=50; break; case'F': delayfactor=20; break; default: delayfactor=100; } if(delayfactor==100) outtextxy(midx,midy,"Slow(S)"); if(delayfactor==50) outtextxy(midx,midy,"Medium(M)"); if(delayfactor==20) outtextxy(midx,midy,"Fast(F)"); /*Change overto textmode*/ while(!kbhit()); closegraph(); restorecrtmode(); } voidmusic(inttype) { floatoctave[7]={130.81,146.83,164.81,174.61,196,220,246.94}; intn,i; switch(type) { case 1: n=random(6); sound(octave[n]*4);
  • 14. Page14 delay(50); break; case 2: for(i=6;i>=0;i--){ sound(octave[i]); delay(54);} nosound(); break; case 3: sound(octave[6]*2); delay(50); nosound(); }} char endscreen() { char ans; initgraph(&gd,&gm,"C:TCbgi"); rectangle(0,0,maxx,maxy); rectangle(2,2,maxx-2,maxy-2); settextjustify(CENTER_TEXT,CENTER_TEXT); settextstyle(TRIPLEX_FONT,HORIZ_DIR,3); if(liveslost==3) { outtextxy(midx,midy-30,"BadLuck!!"); outtextxy(midx,midy,"TryAgain");} else { outtextxy(midx,midy/2,"Youreallyare a"); settextstyle(DEFAULT_FONT,HORIZ_DIR,6); outtextxy(midx,midy,"GENIUS!!"); } settextstyle(TRIPLEX_FONT,HORIZ_DIR,3); outtextxy(midx,midy+midy/2,"Anothergame(Y?N)..."); while(!(ans=='Y'||ans=='N')) { fflush(stdin); ans=getch(); ans=toupper(ans); } closegraph(); restorecrtmode(); return(ans); } voidinitialise(void) { intj; /*initialise rowandcolumnof EATere*/ row=12; col=40;
  • 15. Page15 r[0]=3;c[0]=76; r[1]=3;c[1]=12; r[2]=12;c[2]=4; r[3]=14;c[3]=62; score=0; liveslost=0; bugnumber=0; for(j=0;j<4;j++) { dir[j]=0; charbelow[j]=250; } } voidgamescreen(void) { inti ; size(32,0);/*hide cursor*/ /*Fill the screenwiththe specifiedcolor*/ drawbox (0,0,16,79,12); //drawthe horizontal linesof the maze /*Draw the titbits*/ hline(205,1,0,0,79); hline(205,1,2,2,20); hline(205,1,2,22,38); hline(205,1,2,42,61); hline(205,1,2,63,77); hline(205,1,4,2,20); hline(205,1,4,22,61); hline(205,1,4,63,77); hline(205,1,17,0,79); hline(205,1,15,2,38); hline(205,1,15,42,77); hline(205,1,13,0,12); hline(205,1,13,65,78); hline(205,1,13,16,61); hline(205,1,11,2,14); hline(205,1,11,62,77); hline(205,1,8,16,61); hline(205,1,6,2,38); hline(205,1,6,42,77); hline(205,1,7,63,77); hline(205,1,9,63,78); hline(205,1,7,2,14); hline(205,1,9,1,14); /*Draw the columnsof the titbits*/ vline(186,1,0,0,16); vline(186,1,79,0,16); vline(186,1,40,0,2);
  • 16. Page16 vline(186,1,40,4,6); vline(186,1,14,12,14); vline(186,1,40,13,15); vline(186,1,63,12,14); vline(186,1,40,9,11); vline(202,1,14,15,15); vline(202,1,63,15,15); vline(203,1,40,0,0); vline(203,1,40,4,4); vline(203,1,40,8,8); vline(203,1,40,13,13); vline(187,1,79,0,0); vline(201,1,0,0,0); vline(188,1,79,17,17); vline(200,1,0,17,17); vline(204,1,0,9,9); vline(204,1,0,13,13); vline(185,1,79,9,9); vline(185,1,79,13,13); for(intvlin=16;vlin<=60;vlin+=2) vline(186,1,vlin,10,11); gotoxy(51,24); printf("PressEscto stopthe game"); gotoxy(2,24); printf("Point:%3d",score); /*Place the five bugsat strategicPositions*/ writechar(2,3,76,15); writechar(2,3,12,15); writechar(2,12,4,15); writechar(2,14,62,15); /*PlayMusic*/ music(2); } /*Draw a box fillingthe requiredarea*/ voiddrawbox (intsr,intsc,inter,intec,charattr) { intr,c; char far *v; for(r=sr;r<=er;r++) {for(c=sc;c<=ec;c++){ v=vid_mem+(r*160)+(c*2); *v=250 ; v++; *v=attr;}}} /* Write character and itsattributesintomemeory*/
  • 17. Page17 voidwritechar(charch,intr,intc,intattr) { char far *v ; /*calculate address*/ v=vid_mem+(r*160)+c*2; *v=ch;/*store ascii code*/ v++; *v=attr;/*store attribute */ } /*drawshorizantal line*/ voidhline(unsignedcharch,intattr,intr,intc1,intc2) { intc; for(c=c1;c<=c2;c++) { writechar(ch,r,c,attr); /*if tibitplacedat rowr andcolumnc, set correspondingelementof array maez[][]to1*/ maze[r][c]=1; } } /*draws vertical line */ voidvline(unsignedcharch,intattr,intc,intr1,intr2) { intr; for(r=r1;r<=r2;r++) { writechar(ch,r,c,attr); /*if tibitplacedat rowr andcolumnc, set correspondingelementof array maez[][]to1*/ maze[r][c]=1; } } voidsize(intssl,intesl) { unionREGS i,o; i.h.ah=1; i.h.ch=ssl; i.h.cl=esl; i.h.bh=0; int86(16,&i,&o); } voidmonitor(void) { intkey; unsignedcharch; while(1) { /*place eaterat specifiedrowandcolumn*/ writechar(1,row,col,14); /*move bugsarounduntil a key ishit */ getkeyhit();
  • 18. Page18 /*if all 3 livesof the eaterare lost*/ if(liveslost==3) break; /*place a space inthe positioncurrentlyoccupedbythe eater*/ writechar('',row,col,1); /*update the positionof the eater*/ key=testkeys(); /*if invalidkeypressed*/ if(key==0) { /*write backeaterinitsorignal position*/ writechar(1,row,col,14); } else { /*readcharacter at the positionwhixhthe eateristooccupy */ readchar(row,col,&ch); /*if character read istibit,incrementscore andsoundmusic*/ if(ch==250) { score++; music(3); } if(ch==2) killeater(); /*if character read isbug , kill the eater*/ if(liveslost==3) break; /*printthe latestscore*/ gotoxy(2,24); printf("points:%3d",score); /*if all the tibitsare eatenup*/ if(score>=692) { /*erase the lasttibit*/ writechar('',row,col,1); break; } } } } /*movesthe bugsaroubnduntil a keyishit*/ voidgetkeyhit() { unionREGS i,o; intcount; /*unti a playerhitsa key,move eachbug inturn*/ while(!kbhit()) { /*introduce delay*/ delay(delayfactor); bug(&r[bugnumber],&c[bugnumber],&dir[bugnumber],&charbelow[bugnumber]);
  • 19. Page19 /*if all 3 livesof the eater are lost*/ if (liveslost==3) return; /*goto nextbug*/ bugnumber++; /*start withthe firstbug if allfive bugs have beenmoved*/ if(bugnumber==4) bugnumber=0; } /*issue interrupttoreadthe ascii code and scan code od the kay pressed*/ i.h.ah=0;/*store service no*/ int86(22,&i,&o);/*issueinterrupt*/ ascii=o.h.al; scan=o.h.ah; } /*reportswhichkeyhasbenhit*/ inttestkeys(void) { switch(scan) { case 72:/*up arrow*/ /*if path is notpresentinthe specifieddirection*/ if(maze[row-1][col]==1) return(0); /*update rowof eater*/ row--; break; case 80:/*downarrow*/ if(maze[row+1][col]==1) return(0); row++; break; case 77:/*right arrow*/ if(maze[row][col+1]==1) return(0); col++; break; case 75:/*leftarrow*/ if(maze[row][col-1]==1) return(0); col--; break; case 1:/*esckey*/ exit(0);/*terminatethe programm*/ default: return(0); }
  • 20. Page20 } /*readsthe character presenntatthe rowr and volumncintoch*/ voidreadchar(intr,intc,unsignedchar*ch) { char far *v; /*calculate addresss*/ v=vid_mem+(r*160) +c*2; *ch=*v; } /*movesthe specefybuginthe appropriate direction*/ voidbug(int*r,int*c,int*dir,unsignedchar*ch) { inttrials=1,flag=0; char temp; /*selectavaliddirectionwhichtakesthe bugclosertoeater in eachif statementthe 1st conditioncheckswhetherthe movementin that directionwouldmove the bugclosertothe eater, whereasthe 2nd conditionchecksif the maze permitsamovementinthatdirection*/ if(abs(*r-1-row)<abs(*r-row)&&maze[*r-1][*c]!=1) *dir=UP; else if(abs(*r+1-row)<abs(*r-row)&&maze[*r+1][*c]!=1) *dir=DOWN; else if(abs(*c+1-col)<abs(*c-col)&&maze[*r][*c+1]!=1) *dir=RIGHT; else if(abs(*c-1-col)<abs(*c-col)&&maze[*r][*c-1]!=1) *dir=LEFT; /*checkwhetherthe directionchosencontainsanotherbug,if so find an alternate direction*/ while(1) { switch(*dir) { case RIGHT: /*if there isa pathto right of bug*/ if(maze[*r][*c+1]!=1) { /* readthe character to the right of the bug*/ readchar(*r,*c+1,&temp); if(temp==2) { /*if the character is againa bug findalternate direction*/ if(maze[*r][*c-1]!=1) *dir=LEFT; else { /*if patch existstothe top of the bug*/ if (maze[*r-1][*c]!=1) *dir=UP;
  • 21. Page21 else { /*if path existbelow the bug*/ if(maze[*r+1][*c]!=1) *dir=DOWN; } } } else { /*if there isno bugto the right of the bugbeing considered,move the bugright*/ movebugright(r,c,ch); flag=1; } } else { /*since there isnopat in the RIGHT directio, try anotherpath*/ *dir=random(4); } break; case LEFT: /*if there isa pathto the LEFT of the bug*/ if(maze[*r][*c-1]!=1) { /*readthe character to the ;eftof the bug*/ readchar(*r,*c-1,&temp); if(temp==2) { if(maze[*r][*c+1]!=1) *dir=RIGHT; else { if(maze[*r-1][*c]!=1) *dir=UP; else { if(maze[*r+1][*c]!=1) *dir=DOWN; } } } else { movebugleft(r,c,ch); flag=1; }
  • 23. Page23 flag=1; } } else *dir=random(4); break; } if(flag==1) break; trials++; if(trials>15) break; } if(*r==row&&*c==col) killeater(); } voidmovebugleft(int*row,int*colm,unsignedchar *ch) { if( *ch==0) *ch=0; writechar(*ch,*row,*colm,12); *colm=*colm-1; readchar(*row,*colm,ch); if(*ch==1) *ch=' '; writechar(2,*row,*colm,15); } voidmovebugright(int*row,int*colm,unsigned char*ch) { if( *ch==0) *ch=0; writechar(*ch,*row,*colm,12); *colm=*colm+1; readchar(*row,*colm,ch); if(*ch==1) *ch=' '; writechar(2,*row,*colm,15); } voidmovebugup(int *row,int*col,unsignedchar*ch) { if( *ch==0) *ch=0; writechar(*ch,*row,*col,12); *row=*row-1; readchar(*row,*col,ch); if(*ch==1) *ch=' '; writechar(2,*row,*col,15); } voidmovebugdown(int*row,int*col,unsignedchar*ch) {
  • 28. Page28 BIBLIOGRAPHY http://www.sourcecodesworld.com/source/show.asp?ScriptID=1035 (source code) https://www.w3schools.com/cpp/cpp_getstarted.asp (c++ introduction) https://www.tutorialspoint.com/cplusplus/cpp_polymorphism.html (polymorphism) https://www.geeksforgeeks.org/inheritance-in-c/ (inheritance) https://beginnersbook.com/2017/09/cpp-encapsulation/ (encapsulation) https://www.studytonight.com/cpp/file-streams-in-cpp.php (file streams) https://www.quora.com/How-is-modularity-introduced-in-c++ (modularity) https://www.w3schools.in/cplusplus-tutorial/data-abstraction/ (abstraction) https://en.wikipedia.org/wiki/Pac-Man (pac-man game)