Coding of Pacman in CG
#include<dos.h>
#include<iostream.h>
#include<graphics.h>
#include<conio.h>
void limit();
char arok();
void sond();
void warn();
void page();
void play();
void page1();
void advanc();
/************************************************************************/
/********MAIN*********/
//Alireza,www.source69.blogfa.com//
void main()
{
textbackground(YELLOW);
page();
page1();
limit();//Alireza,www.source69.blogfa.com//
play();
clrscr();
}
/***********END MAIN*******/
/**************************************************************************/
static p,l;
/********************************PLAY**************************************/
void play()//Alireza,www.source69.blogfa.com//
{
warn();
int i=5,j=18,ch=77,k,h,w=400,s=21,g=20;
int bl[14][40];
for(int u=0;u<14;u++)
for(int t=0;t<40;t++)
bl[u][t]=1;
while(ch!=27){
ch=arok();//Alireza,www.source69.blogfa.com//
while(ch==77 ){
delay(w);
gotoxy(j,i);
sond();
textcolor(YELLOW);
if((3<i && i<22) && ( 17<j && j<61)){
bl[i-6][j-20]=0;
cprintf(" ");
j++;
if((6<=i && i<20)&&(20<=j && j<60) &&(i%2!=0 || j%3!=0)&&bl[i-6][j-20]==1 )
advanc();
if((5<i && i<20) &&(i%2==0 && j%3==0) && (19<j) && (j<59)){
warn();
ch=12;
h=10;
}
}
else
j=61;
k=kbhit();
if(k!=0)
ch=12;//Alireza,www.source69.blogfa.com//
}
while(ch==80 ){
bl[i-6][j-20]=0;
i++;
delay(w);
sond();
textcolor(YELLOW);
gotoxy(j,i-1);
if((3<i && i<22) && ( 17<j && j<62)){
cprintf(" ");
gotoxy(j,i);
cprintf(" ");
if((6<=i && i<20)&&(20<=j && j<60)&&(i%2!=0 || j%3!=0)&&bl[i-6][j-20]==1)
advanc();
if((5<i && i<19) && (i%2==0 && j%3==0) && ( 19<j && j<59)){
warn();
ch=12;
h=10;
}//Alireza,www.source69.blogfa.com//
}
else
i=21;
k=kbhit();
if(k!=0)
ch=12;
}
while(ch==75){
bl[i-6][j-20]=0;
delay(w);
j--;
gotoxy(j,i);
sond();
textcolor(YELLOW);
if((3<i && i<22) && ( 17<j && j<62)){
cprintf(" ");
if((6<=i && i<20)&&(20<=j && j<60)&&(i%2!=0 || j%3!=0)&&bl[i-6][j-20]==1)
advanc();
if((5<i && i<19) && (i%2==0 && j%3==0) && ( 19<j && j<59)){
warn();
ch=12;
h=10;
}//Alireza,www.source69.blogfa.com//
}
else
j=18;//Alireza,www.source69.blogfa.com//
k=kbhit();
if(k!=0)
ch=12;
}
while(ch==72){
bl[i-6][j-20]=0;
delay(w);
i--;
sond();
textcolor(YELLOW);
if((3<i && i<22) && ( 17<j && j<62)){
gotoxy(j,i+1);
cprintf(" ");
gotoxy(j,i);
cprintf(" ");
if((6<=i && i<20)&&(20<=j && j<60)&&(i%2!=0 || j%3!=0)&&bl[i-6][j-20]==1)
advanc();
if((5<i && i<19) && (i%2==0 && j%3==0) && ( 19<j && j<59)){
warn();
ch=12;
h=10;
}
}
else
i=4;
k=kbhit();
if(k!=0)
ch=12;
}
//////////////////////////////
while(ch==43 && s>3){
gotoxy(5,s);
sound(w*5);
cprintf("ÛÛ %03d",g);
delay(50);
nosound();//Alireza,www.source69.blogfa.com//
w-=20;
ch=12;
s--;
if(s<=8)
textcolor(RED);
else if(s>=8 && s<=15)//Alireza,www.source69.blogfa.com//
textcolor(YELLOW);
else
textcolor(LIGHTGREEN);
if(s==3){
gotoxy(2,s+1);
cprintf("Max");
}
g+=20;
}
while(ch==45 && s<=19){
g-=20;
gotoxy(5,s+1);
sound(w*5);//Alireza,www.source69.blogfa.com//
cprintf(" ");
delay(50);
nosound();
if(s<=8)
textcolor(RED);
else if(s>=8 && s<=15)
textcolor(YELLOW);//Alireza,www.source69.blogfa.com//
else
textcolor(LIGHTGREEN);
w+=20;
ch=12;
s++;
if(s==19){//Alireza,www.source69.blogfa.com//
textcolor(YELLOW);
gotoxy(2,21);
cprintf("Min");
}
}
///////////////////////////////////////
if(h==10){
textcolor(RED);
gotoxy(j,i);
cprintf("@");
j=18;
i=5;
h=1;
g=20;
for(int f=21;f>=s+1;f--) {
if(f<=8)
textcolor(RED);//Alireza,www.source69.blogfa.com//
else if(f>=8 && f<=15)
textcolor(YELLOW);//Alireza,www.source69.blogfa.com//
else//Alireza,www.source69.blogfa.com//
textcolor(LIGHTGREEN);
gotoxy(5,f);//Alireza,www.source69.blogfa.com//
cprintf("ÛÛ %03d",g);
g+=20;//Alireza,www.source69.blogfa.com//
}
gotoxy(j,i);//Alireza,www.source69.blogfa.com//
}
if(ch=='r'){
for(int u=0;u<14;u++)
for(int t=0;t<40;t++)
bl[u][t]=1;//Alireza,www.source69.blogfa.com//
page();
page1();
limit();
l=0;
p=0;
warn();
j=18;
i=5;
h=1;
g=20;
for(int f=21;f>=s+1;f--) {//Alireza,www.source69.blogfa.com//
if(f<=8)
textcolor(RED);
else if(f>=8 && f<=15)
textcolor(YELLOW);
else
textcolor(LIGHTGREEN);
gotoxy(5,f);
cprintf("ÛÛ %03d",g);
g+=20;
}
gotoxy(j,i);
}
}
}
/************Alireza,www.source69.blogfa.com//***********************PAGE************Alireza,www.source69.blogfa.com//*********************/
void page()
{//Alireza,www.source69.blogfa.com//
clrscr();
textbackground(YELLOW);
register int i,j;
for(i=6;i<20;i++)
for(j=20;j<60;j++){
gotoxy(j,i);//Alireza,www.source69.blogfa.com//
if(i%2==0 && j%3==0){
textcolor(RED);
cprintf("@");
}
else{
textcolor(GREEN);
cprintf("ß");
}
}
textcolor(WHITE);
}
/********************************ADVANCE**********************************/
void advanc()
{
l++;
gotoxy(74,10);//Alireza,www.source69.blogfa.com//
textcolor(GREEN);
cprintf("<%d>",l);
}
/*******************///Alireza,www.source69.blogfa.com//**************WARN*****************//Alireza,www.source69.blogfa.com//******************/
void warn()//Alireza,www.source69.blogfa.com//
{
sound(100);
delay(450);
sound(300);
gotoxy(65,6);
textcolor(RED);
cprintf(" You" );
gotoxy(65,8);
textcolor(RED);
cprintf(" Eat");
gotoxy(65,10);
textcolor(RED);
cprintf(" <%d>",p);
gotoxy(73,10);
textcolor(GREEN);
cprintf(" <%d>",l);
gotoxy(65,12);
textcolor(RED);
cprintf(" Wrong ");
gotoxy(70,6);
textcolor(GREEN);
cprintf(" You");
gotoxy(70,8);
textcolor(GREEN);
cprintf(" Eat");
gotoxy(72,12);
textcolor(GREEN);
cprintf(" Right");//Alireza,www.source69.blogfa.com//
gotoxy(65,14);
textcolor(YELLOW);
cprintf(" ____________");
gotoxy(66,16);
textcolor(GREEN);
cprintf(" Advanc=%d",(l*3)-p);
delay(350);
sound(100);
delay(200);
nosound();//Alireza,www.source69.blogfa.com//
p++;
}
/********************************SOUND************************************/
//Alireza,www.source69.blogfa.com//
void sond()
{
sound(5000);//Alireza,www.source69.blogfa.com//
delay(5);
nosound();//Alireza,www.source69.blogfa.com//
}
/********************************AROK**************************************/
char arok()
{
int g,h;//Alireza,www.source69.blogfa.com//
g=getch();
if(g==0){
h=getch();//Alireza,www.source69.blogfa.com//
return h;
}
else//Alireza,www.source69.blogfa.com//
return g;
}
/**************************************limit*****************************/
void limit()//Alireza,www.source69.blogfa.com//
{
int i;
textcolor(0);
gotoxy(1,3);
cprintf("Ã");//Alireza,www.source69.blogfa.com//
for(i=0;i<78;i++)
cprintf("Ä");
cprintf("´");
gotoxy(16,3);
cprintf("Â");
gotoxy(63,3);//Alireza,www.source69.blogfa.com//
cprintf("Â");
for(i=4;i<22;i++){
gotoxy(16,i);
cprintf("³");
gotoxy(63,i);//Alireza,www.source69.blogfa.com//
cprintf("³");
}
gotoxy(1,23);
cprintf("³< For Exit Press Esc > < For Stop Press Any key > < For Move Use Arrok >");//Alireza,www.source69.blogfa.com//
gotoxy(1,2);//Alireza,www.source69.blogfa.com//
cprintf("³< For Speed Press + > < For Resatart Press R > < For Lower Press - >");//Alireza,www.source69.blogfa.com//
textcolor(0);
gotoxy(18,5);
}
/**********************///Alireza,www.source69.blogfa.com//**************PAGE1*****************///Alireza,www.source69.blogfa.com//****************/
void page1()
{
textcolor(0);
gotoxy(1,1);
cprintf("Ú");
for(int i=0;i<78;i++)
cprintf("Ä");
cprintf("¿");
for(i=2;i<24;i++){
gotoxy(1,i);
cprintf("³");//Alireza,www.source69.blogfa.com//
gotoxy(80,i);
cprintf("³");
}
cprintf("À");
for(i=1;i<79;i++)
cprintf("Ä");
cprintf("Ù");
gotoxy(1,22);
cprintf("Ã");
for(i=0;i<78;i++)
cprintf("Ä");
cprintf("´");
gotoxy(16,22);
cprintf("Á");
gotoxy(63,22);
cprintf("Á");
gotoxy(4,22);
cprintf("Á");//Alireza,www.source69.blogfa.com//
gotoxy(7,22);
cprintf("Á");
gotoxy(18,5);
textcolor(0);
}
#include<iostream.h>
#include<graphics.h>
#include<conio.h>
void limit();
char arok();
void sond();
void warn();
void page();
void play();
void page1();
void advanc();
/************************************************************************/
/********MAIN*********/
//Alireza,www.source69.blogfa.com//
void main()
{
textbackground(YELLOW);
page();
page1();
limit();//Alireza,www.source69.blogfa.com//
play();
clrscr();
}
/***********END MAIN*******/
/**************************************************************************/
static p,l;
/********************************PLAY**************************************/
void play()//Alireza,www.source69.blogfa.com//
{
warn();
int i=5,j=18,ch=77,k,h,w=400,s=21,g=20;
int bl[14][40];
for(int u=0;u<14;u++)
for(int t=0;t<40;t++)
bl[u][t]=1;
while(ch!=27){
ch=arok();//Alireza,www.source69.blogfa.com//
while(ch==77 ){
delay(w);
gotoxy(j,i);
sond();
textcolor(YELLOW);
if((3<i && i<22) && ( 17<j && j<61)){
bl[i-6][j-20]=0;
cprintf(" ");
j++;
if((6<=i && i<20)&&(20<=j && j<60) &&(i%2!=0 || j%3!=0)&&bl[i-6][j-20]==1 )
advanc();
if((5<i && i<20) &&(i%2==0 && j%3==0) && (19<j) && (j<59)){
warn();
ch=12;
h=10;
}
}
else
j=61;
k=kbhit();
if(k!=0)
ch=12;//Alireza,www.source69.blogfa.com//
}
while(ch==80 ){
bl[i-6][j-20]=0;
i++;
delay(w);
sond();
textcolor(YELLOW);
gotoxy(j,i-1);
if((3<i && i<22) && ( 17<j && j<62)){
cprintf(" ");
gotoxy(j,i);
cprintf(" ");
if((6<=i && i<20)&&(20<=j && j<60)&&(i%2!=0 || j%3!=0)&&bl[i-6][j-20]==1)
advanc();
if((5<i && i<19) && (i%2==0 && j%3==0) && ( 19<j && j<59)){
warn();
ch=12;
h=10;
}//Alireza,www.source69.blogfa.com//
}
else
i=21;
k=kbhit();
if(k!=0)
ch=12;
}
while(ch==75){
bl[i-6][j-20]=0;
delay(w);
j--;
gotoxy(j,i);
sond();
textcolor(YELLOW);
if((3<i && i<22) && ( 17<j && j<62)){
cprintf(" ");
if((6<=i && i<20)&&(20<=j && j<60)&&(i%2!=0 || j%3!=0)&&bl[i-6][j-20]==1)
advanc();
if((5<i && i<19) && (i%2==0 && j%3==0) && ( 19<j && j<59)){
warn();
ch=12;
h=10;
}//Alireza,www.source69.blogfa.com//
}
else
j=18;//Alireza,www.source69.blogfa.com//
k=kbhit();
if(k!=0)
ch=12;
}
while(ch==72){
bl[i-6][j-20]=0;
delay(w);
i--;
sond();
textcolor(YELLOW);
if((3<i && i<22) && ( 17<j && j<62)){
gotoxy(j,i+1);
cprintf(" ");
gotoxy(j,i);
cprintf(" ");
if((6<=i && i<20)&&(20<=j && j<60)&&(i%2!=0 || j%3!=0)&&bl[i-6][j-20]==1)
advanc();
if((5<i && i<19) && (i%2==0 && j%3==0) && ( 19<j && j<59)){
warn();
ch=12;
h=10;
}
}
else
i=4;
k=kbhit();
if(k!=0)
ch=12;
}
//////////////////////////////
while(ch==43 && s>3){
gotoxy(5,s);
sound(w*5);
cprintf("ÛÛ %03d",g);
delay(50);
nosound();//Alireza,www.source69.blogfa.com//
w-=20;
ch=12;
s--;
if(s<=8)
textcolor(RED);
else if(s>=8 && s<=15)//Alireza,www.source69.blogfa.com//
textcolor(YELLOW);
else
textcolor(LIGHTGREEN);
if(s==3){
gotoxy(2,s+1);
cprintf("Max");
}
g+=20;
}
while(ch==45 && s<=19){
g-=20;
gotoxy(5,s+1);
sound(w*5);//Alireza,www.source69.blogfa.com//
cprintf(" ");
delay(50);
nosound();
if(s<=8)
textcolor(RED);
else if(s>=8 && s<=15)
textcolor(YELLOW);//Alireza,www.source69.blogfa.com//
else
textcolor(LIGHTGREEN);
w+=20;
ch=12;
s++;
if(s==19){//Alireza,www.source69.blogfa.com//
textcolor(YELLOW);
gotoxy(2,21);
cprintf("Min");
}
}
///////////////////////////////////////
if(h==10){
textcolor(RED);
gotoxy(j,i);
cprintf("@");
j=18;
i=5;
h=1;
g=20;
for(int f=21;f>=s+1;f--) {
if(f<=8)
textcolor(RED);//Alireza,www.source69.blogfa.com//
else if(f>=8 && f<=15)
textcolor(YELLOW);//Alireza,www.source69.blogfa.com//
else//Alireza,www.source69.blogfa.com//
textcolor(LIGHTGREEN);
gotoxy(5,f);//Alireza,www.source69.blogfa.com//
cprintf("ÛÛ %03d",g);
g+=20;//Alireza,www.source69.blogfa.com//
}
gotoxy(j,i);//Alireza,www.source69.blogfa.com//
}
if(ch=='r'){
for(int u=0;u<14;u++)
for(int t=0;t<40;t++)
bl[u][t]=1;//Alireza,www.source69.blogfa.com//
page();
page1();
limit();
l=0;
p=0;
warn();
j=18;
i=5;
h=1;
g=20;
for(int f=21;f>=s+1;f--) {//Alireza,www.source69.blogfa.com//
if(f<=8)
textcolor(RED);
else if(f>=8 && f<=15)
textcolor(YELLOW);
else
textcolor(LIGHTGREEN);
gotoxy(5,f);
cprintf("ÛÛ %03d",g);
g+=20;
}
gotoxy(j,i);
}
}
}
/************Alireza,www.source69.blogfa.com//***********************PAGE************Alireza,www.source69.blogfa.com//*********************/
void page()
{//Alireza,www.source69.blogfa.com//
clrscr();
textbackground(YELLOW);
register int i,j;
for(i=6;i<20;i++)
for(j=20;j<60;j++){
gotoxy(j,i);//Alireza,www.source69.blogfa.com//
if(i%2==0 && j%3==0){
textcolor(RED);
cprintf("@");
}
else{
textcolor(GREEN);
cprintf("ß");
}
}
textcolor(WHITE);
}
/********************************ADVANCE**********************************/
void advanc()
{
l++;
gotoxy(74,10);//Alireza,www.source69.blogfa.com//
textcolor(GREEN);
cprintf("<%d>",l);
}
/*******************///Alireza,www.source69.blogfa.com//**************WARN*****************//Alireza,www.source69.blogfa.com//******************/
void warn()//Alireza,www.source69.blogfa.com//
{
sound(100);
delay(450);
sound(300);
gotoxy(65,6);
textcolor(RED);
cprintf(" You" );
gotoxy(65,8);
textcolor(RED);
cprintf(" Eat");
gotoxy(65,10);
textcolor(RED);
cprintf(" <%d>",p);
gotoxy(73,10);
textcolor(GREEN);
cprintf(" <%d>",l);
gotoxy(65,12);
textcolor(RED);
cprintf(" Wrong ");
gotoxy(70,6);
textcolor(GREEN);
cprintf(" You");
gotoxy(70,8);
textcolor(GREEN);
cprintf(" Eat");
gotoxy(72,12);
textcolor(GREEN);
cprintf(" Right");//Alireza,www.source69.blogfa.com//
gotoxy(65,14);
textcolor(YELLOW);
cprintf(" ____________");
gotoxy(66,16);
textcolor(GREEN);
cprintf(" Advanc=%d",(l*3)-p);
delay(350);
sound(100);
delay(200);
nosound();//Alireza,www.source69.blogfa.com//
p++;
}
/********************************SOUND************************************/
//Alireza,www.source69.blogfa.com//
void sond()
{
sound(5000);//Alireza,www.source69.blogfa.com//
delay(5);
nosound();//Alireza,www.source69.blogfa.com//
}
/********************************AROK**************************************/
char arok()
{
int g,h;//Alireza,www.source69.blogfa.com//
g=getch();
if(g==0){
h=getch();//Alireza,www.source69.blogfa.com//
return h;
}
else//Alireza,www.source69.blogfa.com//
return g;
}
/**************************************limit*****************************/
void limit()//Alireza,www.source69.blogfa.com//
{
int i;
textcolor(0);
gotoxy(1,3);
cprintf("Ã");//Alireza,www.source69.blogfa.com//
for(i=0;i<78;i++)
cprintf("Ä");
cprintf("´");
gotoxy(16,3);
cprintf("Â");
gotoxy(63,3);//Alireza,www.source69.blogfa.com//
cprintf("Â");
for(i=4;i<22;i++){
gotoxy(16,i);
cprintf("³");
gotoxy(63,i);//Alireza,www.source69.blogfa.com//
cprintf("³");
}
gotoxy(1,23);
cprintf("³< For Exit Press Esc > < For Stop Press Any key > < For Move Use Arrok >");//Alireza,www.source69.blogfa.com//
gotoxy(1,2);//Alireza,www.source69.blogfa.com//
cprintf("³< For Speed Press + > < For Resatart Press R > < For Lower Press - >");//Alireza,www.source69.blogfa.com//
textcolor(0);
gotoxy(18,5);
}
/**********************///Alireza,www.source69.blogfa.com//**************PAGE1*****************///Alireza,www.source69.blogfa.com//****************/
void page1()
{
textcolor(0);
gotoxy(1,1);
cprintf("Ú");
for(int i=0;i<78;i++)
cprintf("Ä");
cprintf("¿");
for(i=2;i<24;i++){
gotoxy(1,i);
cprintf("³");//Alireza,www.source69.blogfa.com//
gotoxy(80,i);
cprintf("³");
}
cprintf("À");
for(i=1;i<79;i++)
cprintf("Ä");
cprintf("Ù");
gotoxy(1,22);
cprintf("Ã");
for(i=0;i<78;i++)
cprintf("Ä");
cprintf("´");
gotoxy(16,22);
cprintf("Á");
gotoxy(63,22);
cprintf("Á");
gotoxy(4,22);
cprintf("Á");//Alireza,www.source69.blogfa.com//
gotoxy(7,22);
cprintf("Á");
gotoxy(18,5);
textcolor(0);
}
Comments
Post a Comment