You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

344 lines
7.0 KiB

6 years ago
void Record() //<2F><>¼<EFBFBD><C2BC><EFBFBD>ӵ<EFBFBD><D3B5><EFBFBD><EFBFBD><EFBFBD>
{
p->coord.x=point.x;
p->coord.y=point.y;
ptr=p;
p=(struct Piece *)malloc(sizeof(struct Piece));
p->fore=ptr;
ShowWho();
Q[point.x][point.y]=player+1;
if(player)
{
player=0;
return;
}
player=1;
goto_xy(point.x,point.y);
}
void PutDown() //<2F><>ʾ<EFBFBD><CABE><EFBFBD>Ӻ<EFBFBD><D3BA><EFBFBD>
{
if(Q[point.x][point.y]==0) //<2F><><EFBFBD>жϸ<D0B6>λ<EFBFBD><CEBB><EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
{
if(player)
{
printf("<EFBFBD><EFBFBD>");
printf("\a"); //'\a'<27><>ʾ<EFBFBD><CABE><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
Record();
}
else
{
printf("<EFBFBD><EFBFBD>");
printf("\a");
Record();
}
goto_xy(point.x,point.y);
}
}
void Play(char ch) //<2F><><EFBFBD>̵IJ<CCB5><C4B2><EFBFBD> <20>ƶ<EFBFBD><C6B6><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>ͻ<EFBFBD><CDBB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
{
if(player==1) //<2F>׷<EFBFBD>
{
if(ch== 'W' || ch=='w') //W <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
{
if(point.y<=3)
point.y=22;
else
point.y--;
goto_xy(point.x,point.y);
}
if(ch=='A' || ch=='a') //A <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
{
if(point.x<=10)
point.x=20;
else
point.x--;
goto_xy(point.x,point.y);
}
if(ch=='D' || ch=='d') //D <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
{
if(point.x>=20)
point.x=10;
else
point.x++;
goto_xy(point.x,point.y);
}
if(ch=='S' || ch=='s') //S <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
{
if(point.y>=22)
point.y=3;
else
point.y++;
goto_xy(point.x,point.y);
}
if(ch==32) //<2F>ո<EFBFBD><D5B8><EFBFBD><EFBFBD><EFBFBD>ASCLL<4C><4C> <09><><EFBFBD><EFBFBD>
{
PutDown();
}
}
else
{
if(ch==72) //<2F><><EFBFBD><EFBFBD>ASCLL<4C><4C> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
{
if(point.y<=3)
point.y=22;
else
point.y--;
goto_xy(point.x,point.y);
}
if(ch==75) //<2F><><EFBFBD><EFBFBD>ASCLL<4C><4C> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
{
if(point.x<=10)
point.x=20;
else
point.x--;
goto_xy(point.x,point.y);
}
if(ch==77) //<2F><><EFBFBD><EFBFBD>ASCLL<4C><4C> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
{
if(point.x>=20)
point.x=10;
else
point.x++;
goto_xy(point.x,point.y);
}
if(ch==80) //<2F><><EFBFBD><EFBFBD>ASCLL<4C><4C> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
{
if(point.y>=22)
point.y=3;
else
point.y++;
goto_xy(point.x,point.y);
}
if(ch==13) //<2F>س<EFBFBD><D8B3><EFBFBD><EFBFBD><EFBFBD>ASCLL<4C><4C> <09><><EFBFBD><EFBFBD>
{
PutDown();
}
}
if(button=='b'||button=='B') //<2F><><EFBFBD><EFBFBD><EFBFBD>IJ<EFBFBD><C4B2><EFBFBD>
{
ptr1=p;
if(p!=head)
{
p=p->fore;
free(ptr1);
point.x=p->coord.x;
point.y=p->coord.y;
go_back(point.x,point.y);
}
}
}
int Judge()
{
int count=0;
int pp=player==0?2:1; //<2F><>Ŀ<EFBFBD><C4BF><EFBFBD><EFBFBD>
for(int c=0; c<200; c++)
{
for(int r=0; r<200; r++)
{
if(Q[r][c]!=pp)
continue;
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
int rr=r;
int cc=c;
while(--cc>=3 &&Q[rr][cc]==pp)
count++;
cc=c;
while(++cc<23 &&Q[rr][cc]==pp)
count++;
cc=c;
if(count>=4)
return pp;
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
count=0;
while(--rr>=10 &&Q[rr][cc]==pp)
count++;
rr=r;
while(++rr<30 &&Q[rr][cc]==pp)
count++;
rr=r;
if(count>=4)
return pp;
//<2F><><EFBFBD>б<E9B7B4><D0B1>
count=0;
cc--;
rr--;
while((cc>=3||rr>=10) &&Q[rr][cc]==pp)
{
count++;
cc--;
rr--;
}
rr=r;
cc=c;
cc++;
rr++;
while((cc<23||rr<30) &&Q[rr][cc]==pp)
{
count++;
cc++;
rr++;
}
rr=r;
cc=c;
if(count+1>=5)
return pp;
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>б<EFBFBD><D0B1>
count=0;
cc++;
rr--;
while((cc<23||rr>=10) &&Q[rr][cc]==pp)
{
count++;
cc++;
rr--;
}
rr=r;
cc=c;
cc--;
rr++;
while((cc>=3||rr<30) &&Q[rr][cc]==pp)
{
count++;
cc--;
rr++;
}
rr=r;
cc=c;
if(count+1>=5)
return pp;
count=0;
}
}
return 0;
}
int main(void)
{
int j=0,k=0;
system("color 4E"); //#include<windows.h> 4 <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɫ E <20><><EFBFBD><EFBFBD><E5B5AD>ɫ
printf("\n <20><>ӭplay<61><79><EFBFBD><EFBFBD><EFBFBD>");
goto_xy(15,3);
printf("<EFBFBD><EFBFBD><EFBFBD>ߣ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>");
goto_xy(17,5);
printf(" <20><><EFBFBD><EFBFBD>");
Sleep(3000);
system("cls");
while(1)
{
Init(); //<2F><>ʼ<EFBFBD><CABC>
int winner=0;
Welcome(); //<2F><>ӭ<EFBFBD><D3AD><EFBFBD><EFBFBD>
while(1) //<2F><>ȡ<EFBFBD>˵<EFBFBD>ѡ<EFBFBD><D1A1>
{
char choice=getch();
menu_choose(choice);
if(startchoice!=0)
break;
}
if(startchoice==1) //ѡ<><D1A1><EFBFBD><EFBFBD><EFBFBD>˶<EFBFBD>ս
{
Draw();
goto_xy(17,24);
printf("<EFBFBD>ֵ<EFBFBD><EFBFBD>׷<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>");
goto_xy(point.x,point.y);
while(1)
{
button=getch();
Play(button); //<2F><>ȡ<EFBFBD><C8A1><EFBFBD>̵IJ<CCB5><C4B2><EFBFBD> <20>ƶ<EFBFBD><C6B6><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>ͻ<EFBFBD><CDBB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
if(button==27) //ESC<53><43>ASCLL<4C><4C>
{
if(MessageBox(NULL,TEXT("ȷ<EFBFBD><EFBFBD><EFBFBD>˳<EFBFBD><EFBFBD><EFBFBD>"),TEXT(""),MB_ICONQUESTION|MB_OKCANCEL)==IDOK)
{
system("cls");
printf("\n ллʹ<D0BB>ã<EFBFBD>\n");
return 0;
}
}
if(button==13 || button==32) //<2F>س<EFBFBD><D8B3><EFBFBD><EFBFBD><EFBFBD><EFBFBD>߿ո<DFBF><D5B8><EFBFBD>ASCLL<4C><4C> <09><><EFBFBD>º<EFBFBD><C2BA><EFBFBD>ʼ<EFBFBD>ж<EFBFBD><D0B6><EFBFBD>Ӯ
winner=Judge();
if(winner!=0)
{
goto_xy(15,26);
if(winner==2)
{
printf("<EFBFBD><EFBFBD>ϲ<EFBFBD><EFBFBD><EFBFBD>׷<EFBFBD>Ӯ<EFBFBD><EFBFBD>\n");
j=j+1;
}
if(winner==1)
{
printf("<EFBFBD><EFBFBD>ϲ<EFBFBD><EFBFBD><EFBFBD>ҷ<EFBFBD>Ӯ<EFBFBD><EFBFBD>\n");
k=k+1;
}
goto_xy(29,24);
printf("<EFBFBD><EFBFBD> %d : %d <20><>",j,k);
}
if(winner!=1&&winner!=2)
{
continue;
}
goto_xy(13,24);
printf(" <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϸ?(Y/N): ");
while(1)
{
button=getch();
if(button=='n'||button=='N'||button=='y'||button=='Y')
break;
}
if(button=='n'||button=='N')
{
if(MessageBox(NULL,TEXT(" ȷ<><C8B7><EFBFBD>˳<EFBFBD><CBB3><EFBFBD>"),TEXT(""),MB_ICONQUESTION|MB_OKCANCEL)==IDOK)
{
system("cls");
printf("\n ллʹ<D0BB>ã<EFBFBD>\n");
return 0;
}
}
if(button=='y'||button=='Y')
{
winner=0;
system("cls");
break;
}
}
}
if(startchoice==2)
{
if(MessageBox(NULL,TEXT(" ȷ<><C8B7><EFBFBD>˳<EFBFBD><CBB3><EFBFBD>"),TEXT(""),MB_ICONQUESTION|MB_OKCANCEL)==IDOK)
{
printf("\n\n ллʹ<D0BB>ã<EFBFBD>\n");
return 0;
}
}
}
return 0;
}