该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
map[i][j]=0;
cleardevice();
setbkcolor(13);
setcolor(1);
setfillstyle(1,2);
settextstyle(0,0,2);
outtextxy(10,440,"X:");
outtextxy(10,460,"Y:");
bar(BASEX,BASEY,BASEX+MX*BOXL,BASEY+MY*BOXL);
setlinestyle(0,0,3);
rectangle(BASEX,BASEY,BASEX+MX*BOXL,BASEY+MY*BOXL);
setlinestyle(0,0,1);
for(i=BASEX;i<=BASEX+MX*BOXL;i+=BOXL)
line(i,BASEY,i,BASEY+MY*BOXL);
for(i=BASEY;i<=BASEY+MY*BOXL;i+=BOXL)
line(BASEX,i,BASEX+MX*BOXL,i);
putimage(BASEX+x*BOXL-BOXL/2,BASEY+y*BOXL-BOXL/2,Sign,1);
}
void ShowScore()
{char s[20];
setcolor(3);
settextstyle(0,0,2);
outtextxy(512,13,"WHITE");
itoa(WhiteScore,s,10);
outtextxy(512,33,s);
setcolor(4);
settextstyle(0,0,2);
outtextxy(512,73,"RED");
itoa(RedScore,s,10);
outtextxy(512,93,s);
}
int Down()
{ static int px=0,py=0;
long key=0;
switch(who)
{case 0:
do{
while(bioskey(1)==0)
{
if(CheckMouse()==1) return 0;
}
px=x;
py=y;
key=bioskey(0);
switch(key)
{ case KEY_W :case KEY_w : if(y-1>0) y--;break;
case KEY_S :case KEY_s : if(y+1
case KEY_A :case KEY_a : if(x-1>0) x--;break;
case KEY_D :case KEY_d :if(x+1
case ESC : return 3;
case SPACE :
if(map[x][y]==0)
{ map[x][y]=1;
putimage(BASEX+x*BOXL-BOXL/2,BASEY+y*BOXL-BOXL/2,Red,1);
return 0;
}
}
Showxy(x,y);
if( x==px && y==py) continue;
putimage(BASEX+px*BOXL-BOXL/2,BASEY+py*BOXL-BOXL/2,Sign,1);
putimage(BASEX+x*BOXL-BOXL/2,BASEY+y*BOXL-BOXL/2,Sign,1);
}while(1);
case 1:
do
{
while(bioskey(1)==0)
{
if(CheckMouse()==1) return 0;
}
px=x;
py=y;
key=bioskey(0);
switch(key)
{ case UP: if(y-1>0) y--;break;
case DOWN: if(y+1
case LEFT: if(x-1>0) x--;break;
case RIGHT:if(x+1
case ESC :return 3;
case ENTER:
if(map[x][y]==0)
{ map[x][y]=2;
putimage(BASEX+x*BOXL-BOXL/2,BASEY+y*BOXL-BOXL/2,White,1);
return 0;
}
}
if( x==px && y==py) continue;
Showxy(x,y);
putimage(BASEX+px*BOXL-BOXL/2,BASEY+py*BOXL-BOXL/2,Sign,1);
putimage(BASEX+x*BOXL-BOXL/2,BASEY+y*BOXL-BOXL/2,Sign,1);
}while(1);
}
}
int ChaiJue()
{
int i,j,n=0,p;
i=x;
j=y;
while(i!=0 && j!=0)
{ i--;
j--;
};
p=1;
n=0;
while(i!=MX-1 &&j!=MY-1)
{ if(map[i][j]!=0)
{
if(map[i][j]==p)
{ n++;
if(n==5) return p;
}
else
{
p=map[i][j];
n=1;
}
}
else
n=0;
i++;
j++;
}
i=x;
j=y;
while(i!=0 && j!=MY-1)
{ i--;
j++;
};
p=1;
n=0;
while(i!=MX-1 &&j!=0)
{ if(map[i][j]!=0)
{
if(map[i][j]==p)
{ n++;
if(n==5) return p;
}
else
{
p=map[i][j];
n=1;
}
}else
n=0 ;
i++;
j--;
}
p=1;
n=0;
for(i=0;i
{ if(map[i][y]==0)
{n=0;continue;}
if(map[i][y]==p)
{ n++;
if(n==5) return p;
}
else
{
p=map[i][y];
n=1;
}
}
p=1;
n=0;
for(i=0;i
{ if(map[x][i]==0)
{n=0;continue;}
if(map[x][i]==p)
{ n++;
if(n==5) return p;
}
else
{
p=map[x][i];
n=1;
}
}
return 0;
}
int main()
{ int Over=0;
int Win=0;
InitGra();
InitGame();
while(! Over)
{
Win=0;
x=MX/2;
y=MY/2;
DrawGround();
ShowScore();
Showxy(x,y);
while(!Win)
{ message();
if( Down() ) break;
Win=ChaiJue();
who=!who;
}
setcolor(4);
settextstyle(1,0,4);
if(Win==2)
{ who=1;
WhiteScore+=100;
settextstyle(0,0,5);
outtextxy(100,230,"the White win!");
}
else if(Win==1)
{ who=0;
RedScore+=100;
settextstyle(0,0,5);
outtextxy(100,230,"the Red win!");
}else
{
Over=1;
}
if(Over!=1)
sleep(2);
}
free(White);
free(Red);
free(Sign);
closegraph();
return 0;
}