#include<stdio.h>
#include<graphics.h>
#include<conio.h>
#include<dos.h>
#include<bios.h>
#define left 0x4b00
#define right 0x4d00
#define up 0x4800
#define down 0x5000
#define esp 0x011b
#define pup 0x1c0d/*因为不知道enter的键值,用pagedown键代替*/
int ma[10][10];
int tag;
yanchi(int t1,int h)/*延迟一段时间*/
{struct time st;
int s,t;
clrscr();
gettime(&st);
s=st.ti_sec;
t=0;
if(h==0)printf("the YELLOW win!!!\n");
else printf("the RED win!!!\n");
printf("please wait %d s\n",t1);
while(t<=t1)
{ while(s==st.ti_sec)
{gettime(&st);
}
t++;
s=st.ti_sec;
printf("%d s\n ", t);
}
}
void xishitime()/*显示时间*/
{
struct time st;
gettime(&st);
gotoxy(40,130);
printf("the current time is \n");
printf("%d: %d: %d ",st.ti_hour,st.ti_min,st.ti_sec);
}
int check(int x,int y,int tag)/*检验是否构成屋子*/
{ int i,j;
int c1,c2;
int k,h;
j=(x-70)/40;
i=(y-50)/40;
c1=0;
for(k=i;k>=0;k--)
if(ma[k][j]==tag+1)
c1++;
else break;
c2=0;
for(k=i;k<10;k++)
if(ma[k][j]==tag+1)
c2++;
else break;
if(c1+c2>=7)
return 1;
for(k=j;k>=0;k--)
if(ma[i][k]==tag+1)
c1++;
else break;
c2=0;
for(k=j;k<10;k++)
if(ma[i][k]==tag+1)
c2++;
else break;
if(c1+c2>=7)return 1;
c1=0;
for(k=i,h=j;k<10&&h>=0;k++,h--)
if(ma[k][h]==tag+1)
c1++;
else break;
c2=0;
for(k=i,h=j;k>=0&&h<10;k--,h++)
if(ma[k][h]==tag+1)
c2++;
else break;
if(c1+c2>=6)
return 1;
c1=0;
for(k=i,h=j;k>=0&&h>=0;k--,h--)
if(ma[k][h]==tag+1)
c1++;
else break;
c2=0;
for(k=i,h=j;k<10&&h<10;k++,h++)
if(ma[k][h]==tag+1)
c2++;
else break;
if(c1+c2>=6)
return 1;
return 0;
}
void drawqp()/*画棋盘*/
{
int i;
setbkcolor(BLUE);
for(i=0;i<440;i+=40)
{
line(60,40+i,460,40+i);
line(60+i,40,60+i,440);
}
}
void drawtg(int x,int y,int tag)/*根据走棋人画棋子*/
{ switch(tag)
{case 0:setfillstyle(SOLID_FILL,YELLOW);break;
case 1:setfillstyle(SOLID_FILL,RED);break;
}
bar(x,y,x+20,y+20);
}
void quyuan(int x,int y)/*去掉原来位置的棋子*/
{setfillstyle(SOLID_FILL,BLUE);
bar(x,y,x+20,y+20);
}
void drawhf(int x,int y)/*走过后恢复棋子*/
{int i,j;
j=(x-70)/40;
i=(y-50)/40;
switch(ma[i][j])
{case 0:setfillstyle(SOLID_FILL,BLUE);break;
case 1:setfillstyle(SOLID_FILL,YELLOW);break;
case 2:setfillstyle(SOLID_FILL,RED);break;
}
bar(x,y,x+20,y+20);
}
void zouqi()/*走棋*/
{ int kg;
int k; int shi;
int x,y;
int i,j;
tag=0;
printf("$long live the heavenson of tang!!!$");
for(i=0;i<10;i++)
for(j=0;j<10;j++)
ma[i][j]=0;
while(1)
{x=30;
y=50;
kg=0;
drawtg(x,y,tag);
while(!kg)
{k=bioskey(0);
j=(x-70)/40;
i=(y-50)/40;
switch(k)
{case right:if(x<500)
{x+=40;
drawtg(x,y,tag);
if(x-40==30)
quyuan(x-40,y);
else
drawhf(x-40,y);
} break;
case left:if(x>30)
{x-=40;
drawtg(x,y,tag);
drawhf(x+40,y);
} break;
case up:if(y>=50)
{y-=40;
drawtg(x,y,tag);
drawhf(x,y+40);
} break;
case down:if(y<=440&&x>30)
{ y+=40;
drawtg(x,y,tag);
drawhf(x,y-40);
} break;
case esp:exit(0);break;
case pup:if(ma[i][j]==0)
{ if(tag==0)
ma[i][j]=1;
else ma[i][j]=2;
drawtg(x,y,tag);
if(check(x,y,tag)==1)
{cleardevice();
yanchi(6,tag);
exit(0);
}
kg=1;
} break;
}
}
tag=(tag+1)%2;
}
}
main()
{ int gd,gm;
detectgraph(&gd,&gm);
initgraph(gd,gm,"E:\\turbo c\\tc201e\\bgi");
drawqp();
xishitime();
zouqi();
xishitime();
closegraph();
}