2 player game
Program
#include
#include
#include
#include
#include
static float a,b,h1,h2,x1=20,x2=25,y1=250,y2=200,x3=20,x4=25,y3=190,y4=140;
static int ch=3,ch1=3,q=1,t,s=1,s1,s2,c=0,c1=0,i=0,k=1,t1,t2,p1=0,p2=0;
gameover()
{
int j=0;
while(j<100) p="="1)" t="getpixel(x1+2,479-(y1+y2)/2);" t1="getpixel(a-6,479-b);">(479-(y1+y2)/2)&&(t1==2))
c=1; //down
else if((479-b)<(479-(y1+y2)/2)&&(t1==2)) c=2; //up return c; } else if(p==2) { t=getpixel(639-(x3+2),479-(y3+y4)/2); t2=getpixel(a+6,479-b); if((479-b)>(479-(y3+y4)/2)&&(t2==2))
{c1=1; //down
//printf("%2.f %2.f",479-(y3+y4)/2,479-b);
//printf("yes ");
}
else if((479-b)<(479-(y3+y4)/2)&&(t2==2)) { //printf("%2.f %2.f",479-(y3+y4)/2,479-b); c1=2; //up //printf("no "); } return c1; } return 0; } ball() { ch1=getch(); while(ch1!=13) { move(); ch1=getch(); if(ch1==27) break; } //ch1=getch(); if(ch1==13) { q=2; sound(1100); delay(50); nosound(); while(ch1!=27) { setfillstyle(1,5); setcolor(5); circle(a,479-b,5); floodfill(a,479-b,5); c=check(s1); c1=check(s2); delay(5); setfillstyle(1,0); setcolor(0); circle(a,479-b,5); floodfill(a,479-b,0); if(kbhit()) move(); if(k==1) { t=getpixel(639-(x3+2),479-(y3+y4)/2); t2=getpixel(a+7,479-b); if(t==t2) { sound(1100); delay(50); nosound(); h2=a; c=0;c1=0;//printf("h2=%2.f,yes",h2); k=2; } a++; } else if(k==2) { t=getpixel(x1,479-(y1+y2)/2); t1=getpixel(a-7,479-(b)); if(t==t1) { sound(1100); delay(50); nosound(); h1=a; c=0;c1=0; //printf("yes %2.f =h1",h1); k=1; } a--; } if((479-b)==(479-50)) { //printf("s=%d",s); if(c==1) c=2; else if(c1==1) c1=2; } if(a==639||(a+25)==639) { ch1=3; p1++; printf("%d %d",p1,p2); s=1; q=1; c=0; c1=0; start(1,5); } if(a==0||(a-25)==0) { p2++; s=2; c=0;c1=0; q=1; ch1=3; printf("%d %d",p1,p2); start(2,5); } if((479-b)==(479-429)) { //printf("s=%d",s); if(c1==2) c1=1; else if(c==2) c=1; } if(c==1) //down frm 1st { a++; b--; } else if(c==2) //up frm 1st { a++; b++; } else if(c1==1) { a--; b--; } else if(c1==2) { a--; b++; } if(p1==5||p2==5) gameover(); }//end while } //end ch if return; } move() { fflush(stdin); ch1=getch(); if(ch1==119||ch1==115) move1(); else move2(); return; } move1() { //ch1=getch(); switch(ch1) { case 119://up if(y1<=420) { if(q==1&&s==1) { star(1,0); //delay(1); } setfillstyle(1,2); bar(x1,479-(y1+10),x2,479-(y2+10)); //delay(1); setfillstyle(1,1); bar(x1,479-(y2),x2,479-(y2+10)); y1=y1+10; y2=y2+10; setfillstyle(1,2); if(q==1&&s==1) star(1,5); } break; case 115://down if(y2>=50)
{
if(q==1&&s==1)
{
star(1,0);
//delay(1);
}
setfillstyle(1,2);
bar(x1,479-(y1-10),x2,479-(y2-10));
//delay(1);
setfillstyle(1,1);
bar(x1,479-(y1),x2,479-(y1-10));
y1=y1-10;
y2=y2-10;
setfillstyle(1,2);
if(q==1&&s==1)
star(1,5);
}
break;
}
return;
}
move2()
{
switch(ch1)
{
case 112://up
if(y3<=420) { if(q==1&&s==2) star(2,0); setfillstyle(1,2); bar(639-x3,479-(y3+10),639-x4,479-(y4+10)); setfillstyle(1,1); bar(639-x3,479-(y4),639-x4,479-(y4+10)); y3=y3+10; y4=y4+10; setfillstyle(1,2); if(q==1&&s==2) star(2,5); } break; case 108://down if(y4>=(50))
{
if(q==1&&s==2)
star(2,0);
setfillstyle(1,2);
bar(639-x3,479-(y3-10),639-x4,479-(y4-10));
setfillstyle(1,1);
bar(639-x3,479-(y3),639-x4,479-(y3-10));
y3=y3-10;
y4=y4-10;
setfillstyle(1,2);
if(q==1&&s==2)
star(2,5);
}
break;
}
return;
}
star(int o,int c)
{
s=o;
if(s==1)
{
a=x2+7;
b=(y2+y1)/2;
i=608;
k=1;
s1=1;
s2=2;
setfillstyle(1,c);
setcolor(c);
circle(a,479-b,5);
floodfill(a,479-b,c);
}
if(s==2)
{
a=620-(x3-7);
b=(y3+y4)/2;
i=608;
k=2;
s1=1;
s2=2;
setfillstyle(1,c);
setcolor(c);
circle(a,479-b,5);
floodfill(a,479-b,c);
}
return;
}
start(int o,int c)
{
s=o;
if(s==1)
{
a=x2+7;
b=(y2+y1)/2;
i=608;
k=1;
s1=1;
s2=2;
setfillstyle(1,c);
setcolor(c);
circle(a,479-b,5);
floodfill(a,479-b,c);
}
if(s==2)
{
a=620-(x3-7);
b=(y3+y4)/2;
i=608;
k=2;
s1=1;
s2=2;
setfillstyle(1,c);
setcolor(c);
circle(a,479-b,5);
floodfill(a,479-b,c);
}
ball();
return;
}
play()
{
setfillstyle(1,2); //solid color
bar(x1,479-y1,x2,479-y2);
bar(639-x3,479-y3,639-x4,479-y4);
line(0,479-435,639,479-435);
line(0,440,639,440);
start(s,5);
return;
}
main()
{
int k,a=DETECT,b,ch;
initgraph(&a,&b,"D:\\TC\\BGI");
play();
getch();
return 0;
}
Program
#include
#include
#include
#include
#include
static float a,b,h1,h2,x1=20,x2=25,y1=250,y2=200,x3=20,x4=25,y3=190,y4=140;
static int ch=3,ch1=3,q=1,t,s=1,s1,s2,c=0,c1=0,i=0,k=1,t1,t2,p1=0,p2=0;
gameover()
{
int j=0;
while(j<100) p="="1)" t="getpixel(x1+2,479-(y1+y2)/2);" t1="getpixel(a-6,479-b);">(479-(y1+y2)/2)&&(t1==2))
c=1; //down
else if((479-b)<(479-(y1+y2)/2)&&(t1==2)) c=2; //up return c; } else if(p==2) { t=getpixel(639-(x3+2),479-(y3+y4)/2); t2=getpixel(a+6,479-b); if((479-b)>(479-(y3+y4)/2)&&(t2==2))
{c1=1; //down
//printf("%2.f %2.f",479-(y3+y4)/2,479-b);
//printf("yes ");
}
else if((479-b)<(479-(y3+y4)/2)&&(t2==2)) { //printf("%2.f %2.f",479-(y3+y4)/2,479-b); c1=2; //up //printf("no "); } return c1; } return 0; } ball() { ch1=getch(); while(ch1!=13) { move(); ch1=getch(); if(ch1==27) break; } //ch1=getch(); if(ch1==13) { q=2; sound(1100); delay(50); nosound(); while(ch1!=27) { setfillstyle(1,5); setcolor(5); circle(a,479-b,5); floodfill(a,479-b,5); c=check(s1); c1=check(s2); delay(5); setfillstyle(1,0); setcolor(0); circle(a,479-b,5); floodfill(a,479-b,0); if(kbhit()) move(); if(k==1) { t=getpixel(639-(x3+2),479-(y3+y4)/2); t2=getpixel(a+7,479-b); if(t==t2) { sound(1100); delay(50); nosound(); h2=a; c=0;c1=0;//printf("h2=%2.f,yes",h2); k=2; } a++; } else if(k==2) { t=getpixel(x1,479-(y1+y2)/2); t1=getpixel(a-7,479-(b)); if(t==t1) { sound(1100); delay(50); nosound(); h1=a; c=0;c1=0; //printf("yes %2.f =h1",h1); k=1; } a--; } if((479-b)==(479-50)) { //printf("s=%d",s); if(c==1) c=2; else if(c1==1) c1=2; } if(a==639||(a+25)==639) { ch1=3; p1++; printf("%d %d",p1,p2); s=1; q=1; c=0; c1=0; start(1,5); } if(a==0||(a-25)==0) { p2++; s=2; c=0;c1=0; q=1; ch1=3; printf("%d %d",p1,p2); start(2,5); } if((479-b)==(479-429)) { //printf("s=%d",s); if(c1==2) c1=1; else if(c==2) c=1; } if(c==1) //down frm 1st { a++; b--; } else if(c==2) //up frm 1st { a++; b++; } else if(c1==1) { a--; b--; } else if(c1==2) { a--; b++; } if(p1==5||p2==5) gameover(); }//end while } //end ch if return; } move() { fflush(stdin); ch1=getch(); if(ch1==119||ch1==115) move1(); else move2(); return; } move1() { //ch1=getch(); switch(ch1) { case 119://up if(y1<=420) { if(q==1&&s==1) { star(1,0); //delay(1); } setfillstyle(1,2); bar(x1,479-(y1+10),x2,479-(y2+10)); //delay(1); setfillstyle(1,1); bar(x1,479-(y2),x2,479-(y2+10)); y1=y1+10; y2=y2+10; setfillstyle(1,2); if(q==1&&s==1) star(1,5); } break; case 115://down if(y2>=50)
{
if(q==1&&s==1)
{
star(1,0);
//delay(1);
}
setfillstyle(1,2);
bar(x1,479-(y1-10),x2,479-(y2-10));
//delay(1);
setfillstyle(1,1);
bar(x1,479-(y1),x2,479-(y1-10));
y1=y1-10;
y2=y2-10;
setfillstyle(1,2);
if(q==1&&s==1)
star(1,5);
}
break;
}
return;
}
move2()
{
switch(ch1)
{
case 112://up
if(y3<=420) { if(q==1&&s==2) star(2,0); setfillstyle(1,2); bar(639-x3,479-(y3+10),639-x4,479-(y4+10)); setfillstyle(1,1); bar(639-x3,479-(y4),639-x4,479-(y4+10)); y3=y3+10; y4=y4+10; setfillstyle(1,2); if(q==1&&s==2) star(2,5); } break; case 108://down if(y4>=(50))
{
if(q==1&&s==2)
star(2,0);
setfillstyle(1,2);
bar(639-x3,479-(y3-10),639-x4,479-(y4-10));
setfillstyle(1,1);
bar(639-x3,479-(y3),639-x4,479-(y3-10));
y3=y3-10;
y4=y4-10;
setfillstyle(1,2);
if(q==1&&s==2)
star(2,5);
}
break;
}
return;
}
star(int o,int c)
{
s=o;
if(s==1)
{
a=x2+7;
b=(y2+y1)/2;
i=608;
k=1;
s1=1;
s2=2;
setfillstyle(1,c);
setcolor(c);
circle(a,479-b,5);
floodfill(a,479-b,c);
}
if(s==2)
{
a=620-(x3-7);
b=(y3+y4)/2;
i=608;
k=2;
s1=1;
s2=2;
setfillstyle(1,c);
setcolor(c);
circle(a,479-b,5);
floodfill(a,479-b,c);
}
return;
}
start(int o,int c)
{
s=o;
if(s==1)
{
a=x2+7;
b=(y2+y1)/2;
i=608;
k=1;
s1=1;
s2=2;
setfillstyle(1,c);
setcolor(c);
circle(a,479-b,5);
floodfill(a,479-b,c);
}
if(s==2)
{
a=620-(x3-7);
b=(y3+y4)/2;
i=608;
k=2;
s1=1;
s2=2;
setfillstyle(1,c);
setcolor(c);
circle(a,479-b,5);
floodfill(a,479-b,c);
}
ball();
return;
}
play()
{
setfillstyle(1,2); //solid color
bar(x1,479-y1,x2,479-y2);
bar(639-x3,479-y3,639-x4,479-y4);
line(0,479-435,639,479-435);
line(0,440,639,440);
start(s,5);
return;
}
main()
{
int k,a=DETECT,b,ch;
initgraph(&a,&b,"D:\\TC\\BGI");
play();
getch();
return 0;
}
No comments:
Post a Comment
Thanks to given comments.......