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

#include<iostream.

h>
#include<graphics.h>
#include<conio.h>
#include<dos.h>
#include<stdlib.h>
#include<process.h>
#include<time.h>
#define UPARR 72
#define LEFTARR 75
#define RIGHTARR 77
#define DOWNARR 80
int food(int&,int&,int&);
int lifebar(int&); //lifebar shows the bar
int movebonus(int&,int&);
int movebonus1(int&,int&);
int movebonus2(int&,int&);
int movebonus3(int&,int&);
int level(int);
void play();

int main1();
void game();
void main()
{cout<<"DOS/4GW Professional Protected Mode Run-time Version 1.0\nCopyright (c)
Linkstatic Systems, Inc. 2009-2011";
delay(2000);
clrscr();
int DIR=DETECT,MOD;
clrscr();
initgraph(&DIR,&MOD,"d:\\tc3.0\\bgi");

int w;
while(1)
{
w=main1();
switch(w)
{
case 1: game();
break;
case 2: play();
break;
case 4: exit(0);
}
}
}
void game()
{
cleardevice();
char d=72;
int rr,b=1,ee=400,ww=0, g=0,bg=0,sc=9,check1,dd, fx,fy,bx=0,by=0,bx2=0,by2=0,bx3
=0,by3=0,count=1,x=240,y=240,num=1,check=0;
setbkcolor(bg);
setcolor(RED);
rectangle(1,1,638,478);
rectangle(2,2,637,477);
rectangle(3,3,636,476);
rectangle(4,4,635,475);
setcolor(19);
settextstyle(14,0,2);
outtextxy(14,468,"SCORE:");
setcolor(RED);
setfillstyle(1,RED);
bar3d(201,450,400,470,5,1);
circle(x,y,6);
char f;
int bx1=0,by1=0,num1=1,check1a,check1b,check1c,num2=1,num3=1;
while(d!='n')
{ ww++;
dd=level(g);
if(g==200)
{ cleardevice();
setcolor(WHITE);
settextstyle(0,0,4);
outtextxy(200,200,"LEVEL 3");
sleep(2);
setcolor(BLACK);
settextstyle(0,0,4);
outtextxy(200,200,"LEVEL 3");
setcolor(RED);
rectangle(1,1,638,478);
rectangle(2,2,637,477);
rectangle(3,3,636,476);
rectangle(4,4,635,475);
setcolor(19);
settextstyle(14,0,2);
outtextxy(14,468,"SCORE:");
setcolor(RED);
setfillstyle(1,RED);
bar3d(201,450,400,470,5,1);
circle(x,y,6);
g=g+5; bar3d(ee,450,400,470,5,0); }
if(g==100)
{ cleardevice();
setcolor(WHITE);
settextstyle(0,0,4);
outtextxy(200,200,"LEVEL 2");
sleep(2);
setcolor(BLACK);
settextstyle(0,0,4);
outtextxy(200,200,"LEVEL 2");
setcolor(RED);
rectangle(1,1,638,478);
rectangle(2,2,637,477);
rectangle(3,3,636,476);
rectangle(4,4,635,475);
setcolor(19);
settextstyle(14,0,2);
outtextxy(14,468,"SCORE:");
setcolor(RED);
setfillstyle(1,RED);
bar3d(201,450,400,470,5,1);
circle(x,y,6);
g=g+5; bar3d(ee,450,400,470,5,0);
}
if(x<=6 || y<=6 || x>=633 || y>=470|| ee<201)
{
cleardevice();
setbkcolor(BLACK);
setcolor(WHITE);
settextstyle(0,0,4);
outtextxy(200,200,"GAME OVER");
getch();
getch();
cleardevice();
break;
}
if((bx>=x-3 && bx<=x+3) && (by>=y-3 && by<=y+3)||(bx1>=x-3 && bx1<=x+3
) && (by1>=y-3 && by1<=y+3)||(bx2>=x-3 && bx2<=x+3) && (by2>=y-3 && by2<=y+3)||(
bx3>=x-3 && bx3<=x+3) && (by3>=y-3 && by3<=y+3) )
{
cleardevice();
setbkcolor(BLACK);
settextstyle(0,0,4);
outtextxy(200,200,"YOU DIED!!");
getch();
getch();
cleardevice();
break;
}
if(ww%4==0)
rr = lifebar(ee);
if(dd <=10 && ww%700==0)
{ setcolor(BLACK);
setfillstyle(1,BLACK);
circle(bx1,by1,4);
floodfill(bx1,by1,BLACK);
randomize();
bx1=200+rand()%300;
by1=70+rand()%200;
num1=movebonus1(bx1,by1);
check1a=0;
}
if(dd<=5 && ww%800==0)
{ setcolor(BLACK);
setfillstyle(1,BLACK);
circle(bx2,by2,4);
floodfill(bx2,by2,BLACK);
setcolor(BLACK);
setfillstyle(1,BLACK);
circle(bx3,by3,4);
floodfill(bx3,by3,BLACK);

bx2=400+rand()%200;
by2=200+rand()%100;
num2=movebonus2(bx2,by2);
bx3=100+rand()%200;
by3=70%rand()%75;
num3=movebonus3(bx3,by3);
check1b=0;
check1c=0;
}
if(ww%600==0)
{ setcolor(BLACK);
setfillstyle(1,BLACK);
circle(bx,by,4);
floodfill(bx,by,BLACK);

randomize();
bx=100+rand()%500;
by=50+rand()%300;

num=movebonus(bx,by);
check1=0;

}
if(kbhit())
d=getch();
if(check==0)
check=food(fx,fy,g);
setcolor(WHITE);
setfillstyle(1,WHITE);
circle(fx,fy,2);
floodfill(fx,fy,WHITE);
if( d==75||d=='a')
{
setcolor(bg);
setfillstyle(1,bg);
circle(x,y,6);
floodfill(x,y,bg);
setcolor(sc);
setfillstyle(1,sc);
circle(x-1,y,6);
floodfill(x-1,y,sc);
x=x-1;
if(num==0&&check1==0)
num= movebonus(bx,by);
if(num1==0 && check1a==0 )
num1=movebonus1(bx1,by1);
if(num2==0 && check1b==0)
num2=movebonus2(bx2,by2);
if(num3==0 && check1c==0)
num3=movebonus3(bx3,by3);
delay(dd);
}
if( d==80||d=='s')
{
setcolor(bg);
setfillstyle(1,bg);
circle(x,y,6);
floodfill(x,y,bg);
setcolor(sc);
setfillstyle(1,sc);
circle(x,y+1,6);
floodfill(x,y+1,sc);
y=y+1;
if(num==0 && check1==0)
num= movebonus1(bx,by);
if(num1==0 && check1a==0)
num1=movebonus1(bx1,by1);
if(num2==0 && check1b==0)
num2=movebonus2(bx2,by2);
if(num3==0 && check1c==0)
num3=movebonus3(bx3,by3);
delay(dd);
}
if( d==77||d=='d')
{
setcolor(bg);
setfillstyle(1,bg);
circle(x,y,6);
floodfill(x,y,bg);
setcolor(sc);
setfillstyle(1,sc);
circle(x+1,y,6);
floodfill(x+1,y,sc);
x=x+1;
if(num==0 && check1==0)
num=movebonus1(bx,by);
if(num1==0 && check1a==0)
num1=movebonus1(bx1,by1);
if(num2==0 && check1b==0)
num2=movebonus2(bx2,by2);
if(num3==0 && check1c==0)
num3=movebonus3(bx3,by3);
delay(dd);
}
if( d==72||d=='w')
{
setcolor(bg);
setfillstyle(1,bg);
circle(x,y,6);
floodfill(x,y,bg);
setcolor(sc);
setfillstyle(1,sc);
circle(x,y-1,6);
floodfill(x,y-1,sc);
y=y-1;
if(num==0 && check1==0)
num=movebonus(bx,by);
if(num1==0 && check1a==0)
num1=movebonus1(bx1,by1);
if(num2==0 && check1b==0)
num2=movebonus2(bx2,by2);
if(num3==0 && check1c==0)
num3=movebonus3(bx3,by3); delay(dd);
}
if(num==1)
{
setcolor(BLACK);
setfillstyle(1,BLACK);
circle(bx,by,4);
floodfill(bx,by,BLACK);
check1=1;
}
if(num1==1)
{
setcolor(BLACK);
setfillstyle(1,BLACK);
circle(bx1,by1,4);
floodfill(bx1,by1,BLACK);
check1a=1;
}
if(num2==1)
{
setcolor(BLACK);
setfillstyle(1,BLACK);
circle(bx2,by2,4);
floodfill(bx2,by2,BLACK);
check1b=1;
}
if(num3==1)
{
setcolor(BLACK);
setfillstyle(1,BLACK);
circle(bx3,by3,4);
floodfill(bx3,by3,BLACK);
check1c=1;
}

if(( x>=fx-3 && x<=fx+3) &&( y>=fy-3 && y<=fy+3))


{
check=0;
setcolor(0);
circle(fx,fy,2);
setcolor(RED);
setfillstyle(1,RED);
bar3d(201,450,400,470,5,1);
ee=400;
}

}
int food(int& a,int& b,int& g)
{
randomize();
a=10+rand()%600;
b=10+rand()%195;
gotoxy(8,30);
cout<<g;
g=g+10;
return 1;
}
int lifebar(int& a)
{
setfillstyle(1,BLACK);
for(int i=400;i>=a;i=i-5)
{setcolor(RED);
bar3d(i,450,400,470,5,0);
}
a=a-1;
}

int movebonus(int& x,int& y)


{
int axis;
int gg;

axis= rand()%2;
if( x<=10 || y<=10 || x>=631 || y>=450 )
return 1;

switch(axis)
{
case 0:
gg=rand()%2;
switch(gg)
{
case 0: setcolor(BLACK);
setfillstyle(1,BLACK);
circle(x,y,4);
floodfill(x,y,BLACK);
setcolor(BLUE);
setfillstyle(1,BLUE);
circle(x+1,y,4);
floodfill(x+1,y,BLUE);
x=x+1;
break;
case 1: setcolor(BLACK);
setfillstyle(1,BLACK);
circle(x,y,4);
floodfill(x,y,BLACK);
setcolor(BLUE);
setfillstyle(1,BLUE);
circle(x-1,y,4);
floodfill(x-1,y,BLUE);
x=x-1;
break;
}
break;
case 1: gg=rand()%2;
switch(gg)
{ case 0: setcolor(BLACK);
setfillstyle(1,BLACK);
circle(x,y,4);
floodfill(x,y,BLACK);
setcolor(BLUE);
setfillstyle(1,BLUE);
circle(x,y+1,4);
floodfill(x,y+1,BLUE);

y=y+1;
break;
case 1: setcolor(BLACK);
setfillstyle(1,BLACK);
circle(x,y,4);
floodfill(x,y,BLACK);
setcolor(BLUE);
setfillstyle(1,BLUE);
circle(x,y-1,4);
floodfill(x,y-1,BLUE);

y=y-1;
break;
}

}
return 0;
}
int movebonus1(int& x,int& y)
{
int axis;
int gg;
randomize();

axis= rand()%2;
if( x<=10 || y<=10 || x>=631 || y>=450 )
return 1;
switch(axis)
{
case 0:
gg=rand()%2;
switch(gg)
{
case 0: setcolor(BLACK);
setfillstyle(1,BLACK);
circle(x,y,4);
floodfill(x,y,BLACK);
setcolor(BLUE);
setfillstyle(1,BLUE);
circle(x+1,y,4);
floodfill(x+1,y,BLUE);
x=x+1;
break;
case 1: setcolor(BLACK);
setfillstyle(1,BLACK);
circle(x,y,4);
floodfill(x,y,BLACK);
setcolor(BLUE);
setfillstyle(1,BLUE);
circle(x-1,y,4);
floodfill(x-1,y,BLUE);
x=x-1;
break;
}
break;
case 1: gg=rand()%2;
switch(gg)
{ case 0: setcolor(BLACK);
setfillstyle(1,BLACK);
circle(x,y,4);
floodfill(x,y,BLACK);
setcolor(BLUE);
setfillstyle(1,BLUE);
circle(x,y+1,4);
floodfill(x,y+1,BLUE);

y=y+1;
break;
case 1: setcolor(BLACK);
setfillstyle(1,BLACK);
circle(x,y,4);
floodfill(x,y,BLACK);
setcolor(BLUE);
setfillstyle(1,BLUE);
circle(x,y-1,4);
floodfill(x,y-1,BLUE);

y=y-1;
break;
}

}
return 0;
}

int level(int a)
{
if(a>200)
return 5;
else
if(a>100)
return 10;
else
if(a>600)
return 3;
else
return 20;
}

int main1()
{
char d;
int tx=270,ty=190;
setcolor(WHITE);
settextstyle(6,0,5); //6,9,10
outtextxy(230,100,"THE DOT");
settextstyle(6,0,1);
outtextxy(380,140,"v1.0");
settextstyle(6,0,1);
setcolor(BLUE);
outtextxy(270,190,"New Game");
setcolor(WHITE);
outtextxy(270,220,"How to play");
outtextxy(270,250,"High Score");
outtextxy(270,280,"Quit Game");
settextstyle(14,0,1);
outtextxy(10,450,"By linkstatic");
settextstyle(6,0,1);
setcolor(BLUE);
setfillstyle(1,BLUE);
circle(255,205,6);
floodfill(255,205,BLUE);
int x=255,y=205;
while(d!=13)
{ d=getch();
if(d==80)
{
setcolor(WHITE);
if(ty==190)
{
outtextxy(tx,ty,"New Game");
setcolor(BLUE);
outtextxy(tx,ty+30,"How to play");
}
if(ty==220)
{
outtextxy(tx,ty,"How to play");
setcolor(BLUE);
outtextxy(tx,ty+30,"High Score");
}
if(ty==250)
{
outtextxy(tx,ty,"High Score");
setcolor(BLUE);
outtextxy(tx,ty+30,"Quit Game");
}
if(ty==280)
{
outtextxy(tx,ty,"Quit Game");
setcolor(BLUE);
outtextxy(tx,ty-90,"New Game");
ty=ty-120;
}
if(y==295)
{
setcolor(BLACK);
setfillstyle(1,BLACK);
circle(x,295,6);
floodfill(x,295,BLACK);
y=175;
}
setcolor(BLACK);
setfillstyle(1,BLACK);
circle(x,y,6);
floodfill(x,y,BLACK);
setcolor(BLUE);
setfillstyle(1,BLUE);
circle(x,y+30,6);
floodfill(x,y+30,BLUE);
y=y+30; //235,265,295
ty=ty+30;
}

if(d==72)
{ if(ty==190)
{
setcolor(WHITE);
outtextxy(tx,ty,"New Game");
setfillstyle(1,BLACK);circle(x,y,6);floodfill(x,y,BLACK);
setcolor(BLUE);
outtextxy(tx,ty+90,"Quit Game");
y=325;ty=310;
}
if(y==235)
{
setcolor(WHITE);
outtextxy(tx,ty,"How to play");
setcolor(BLUE);
outtextxy(tx,ty-30,"New Game");
}
if(y==265)
{
setcolor(WHITE);
outtextxy(tx,ty,"High Score");
setcolor(BLUE);
outtextxy(tx,ty-30,"How to play");
}
if(y==295)
{
setcolor(WHITE);
outtextxy(tx,ty,"Quit Game");
setcolor(BLUE);
outtextxy(tx,ty-30,"High Score");
}
setcolor(BLACK);
setfillstyle(1,BLACK);
circle(x,y,6);
floodfill(x,y,BLACK);
setcolor(BLUE);
setfillstyle(1,BLUE);
circle(x,y-30,6);
floodfill(x,y-30,BLUE);
y=y-30;
ty=ty-30;
}

}
if(ty==190)
return 1;
if(ty==220)
return 2;
if(ty==250)
return 3;
if(ty==280)
return 4;

}
int movebonus2(int& x,int& y)
{
int axis;
int gg;

axis= rand()%2;
if( x<=10 || y<=10 || x>=631 || y>=450 )
return 1;

switch(axis)
{
case 0:
gg=rand()%2;
switch(gg)
{
case 0: setcolor(BLACK);
setfillstyle(1,BLACK);
circle(x,y,4);
floodfill(x,y,BLACK);
setcolor(BLUE);
setfillstyle(1,BLUE);
circle(x+1,y,4);
floodfill(x+1,y,BLUE);
x=x+1;
break;
case 1: setcolor(BLACK);
setfillstyle(1,BLACK);
circle(x,y,4);
floodfill(x,y,BLACK);
setcolor(BLUE);
setfillstyle(1,BLUE);
circle(x-1,y,4);
floodfill(x-1,y,BLUE);
x=x-1;
break;
}
break;
case 1: gg=rand()%2;
switch(gg)
{ case 0: setcolor(BLACK);
setfillstyle(1,BLACK);
circle(x,y,4);
floodfill(x,y,BLACK);
setcolor(BLUE);
setfillstyle(1,BLUE);
circle(x,y+1,4);
floodfill(x,y+1,BLUE);

y=y+1;
break;
case 1: setcolor(BLACK);
setfillstyle(1,BLACK);
circle(x,y,4);
floodfill(x,y,BLACK);
setcolor(BLUE);
setfillstyle(1,BLUE);
circle(x,y-1,4);
floodfill(x,y-1,BLUE);

y=y-1;
break;
}

}
return 0;
}

int movebonus3(int& x,int& y)


{
int axis;
int gg;
randomize();

axis= rand()%2;
if( x<=10 || y<=10 || x>=631 || y>=450 )
return 1;

switch(axis)
{
case 0:
gg=rand()%2;
switch(gg)
{
case 0: setcolor(BLACK);
setfillstyle(1,BLACK);
circle(x,y,4);
floodfill(x,y,BLACK);
setcolor(BLUE);
setfillstyle(1,BLUE);
circle(x+1,y,4);
floodfill(x+1,y,BLUE);
x=x+1;
break;
case 1: setcolor(BLACK);
setfillstyle(1,BLACK);
circle(x,y,4);
floodfill(x,y,BLACK);
setcolor(BLUE);
setfillstyle(1,BLUE);
circle(x-1,y,4);
floodfill(x-1,y,BLUE);
x=x-1;
break;
}
break;
case 1: gg=rand()%2;
switch(gg)
{ case 0: setcolor(BLACK);
setfillstyle(1,BLACK);
circle(x,y,4);
floodfill(x,y,BLACK);
setcolor(BLUE);
setfillstyle(1,BLUE);
circle(x,y+1,4);
floodfill(x,y+1,BLUE);

y=y+1;
break;
case 1: setcolor(BLACK);
setfillstyle(1,BLACK);
circle(x,y,4);
floodfill(x,y,BLACK);
setcolor(BLUE);
setfillstyle(1,BLUE);
circle(x,y-1,4);
floodfill(x,y-1,BLUE);

y=y-1;
break;
}

}
return 0;
}
void play()
{
cleardevice();
setcolor(3);
settextstyle(6,0,2);
outtextxy(250,50,"HOW TO PLAY");
bar(250,80,370,85);
setcolor(9);
setfillstyle(1,9);
circle(150,150,6);
floodfill(150,150,9);
setcolor(RED);
settextstyle(6,0,1);
outtextxy(170,135,"= Your Dot");
setcolor(WHITE);
setfillstyle(1,WHITE);
circle(380,150,2);
floodfill(380,150,WHITE);
setcolor(RED);
outtextxy(400,135,"= Food!!");
setcolor(BLUE);
setfillstyle(1,BLUE);
circle(150,200,4);
floodfill(150,200,BLUE);
setcolor(RED);outtextxy(170,185,"= Enemy");
outtextxy(150,235,"Use the arrow keys to move and eat food for points");
outtextxy(150,255,"Dont touch the Enemies or the boundaries or you lose.");

getch();
cleardevice();
}

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