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.
fc001/五子棋课程设计最终版.cpp

383 lines
7.3 KiB

6 years ago
#include <stdlib.h>
#include <stdio.h>
#include <conio.h>
#include <string.h>
#define SIZE 19
int jushu=0;
int q1=0,q2=0;
int k[SIZE][SIZE];
int WANJIA;
int count;
int X,Y;
char* Text;
int welcome(void)
{
printf("\n\n\n\n\n\n");
printf("\t\t\t~*************<2A><>ӭ<EFBFBD><D3AD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϸ*************~\n");
printf("\n\n\n");
printf("\t\t\t~*************<2A><><EFBFBD><EFBFBD><EFBFBD>ߣ<EFBFBD><DFA3><EFBFBD><EFBFBD><EFBFBD>*************~\n");
printf("\n\n\n");
printf("\t\t\t~*************<2A><><EFBFBD>س<EFBFBD><D8B3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>*************~");
while(getchar() == 0);
system("CLS");
return 0;
}
int help(void)
{
printf("\n\n\n\n\n\n");
printf("\t\t\t~************************<2A><><EFBFBD><EFBFBD>**************************~\n");
printf("\n");
printf("\t\t\t~*************p1<70><31><EFBFBD><EFBFBD>wasd<73><64><EFBFBD>ƹ<EFBFBD><C6B9>꣬Tab<61><62><EFBFBD><EFBFBD><EFBFBD><EFBFBD>************~\n");
printf("\n\n\n");
printf("\t\t\t~************p2<70><32><EFBFBD>ҷ<EFBFBD><D2B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ƹ<EFBFBD><C6B9><EFBFBD>ո<EFBFBD><D5B8><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>**********~\n");
printf("\n\n\n");
printf("\t\t\t~********************<2A><><EFBFBD>س<EFBFBD><D8B3><EFBFBD><EFBFBD><EFBFBD>ʼ<EFBFBD><CABC>Ϸ******************~");
while(getchar() == 0);
system("CLS");
return 0;
}
int blackwin(void)
{
printf("\n\n\n\n\n\n");
printf("\t\t\t~*************<2A><>ϲ<EFBFBD>ڷ<EFBFBD>ʤ<EFBFBD><CAA4>************~\n");
printf("\n\n\n");
printf("\t\t\t~************<2A><>ǰ<EFBFBD>ܾ<EFBFBD><DCBE><EFBFBD><EFBFBD><EFBFBD>%d*************~\n",jushu);
printf("\n\n\n");
printf("\t\t\t~******<2A>ڷ<EFBFBD>ʤ<EFBFBD><CAA4><EFBFBD><EFBFBD>%d<>֣<EFBFBD><D6A3>׷<EFBFBD>ʤ<EFBFBD><CAA4><EFBFBD><EFBFBD>%d<><64>******~",q1,q2);
printf("\n\n\n");
printf("\t\t\t~**********<2A><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><D2BB>***********~\n");
}
int whitewin(void)
{
printf("\n\n\n\n\n\n");
printf("\t\t\t~*************<2A><>ϲ<EFBFBD>׷<EFBFBD>ʤ<EFBFBD><CAA4>************~\n");
printf("\n\n\n");
printf("\t\t\t~************<2A><>ǰ<EFBFBD>ܾ<EFBFBD><DCBE><EFBFBD><EFBFBD><EFBFBD>%d*************~\n",jushu);
printf("\n\n\n");
printf("\t\t\t~******<2A>ڷ<EFBFBD>ʤ<EFBFBD><CAA4><EFBFBD><EFBFBD>%d<>֣<EFBFBD><D6A3>׷<EFBFBD>ʤ<EFBFBD><CAA4><EFBFBD><EFBFBD>%d<><64>******~",q1,q2);
printf("\n\n\n");
printf("\t\t\t~**********<2A><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><D2BB>***********~\n");
}
int pingju(void)
{
printf("\n\n\n\n\n\n");
printf("\t\t\t~***************<2A><>ϲƽ<CFB2><C6BD>************~\n");
printf("\n\n\n");
printf("\t\t\t~************<2A><>ǰ<EFBFBD>ܾ<EFBFBD><DCBE><EFBFBD><EFBFBD><EFBFBD>%d*************~\n",jushu);
printf("\n\n\n");
printf("\t\t\t~******<2A>ڷ<EFBFBD>ʤ<EFBFBD><CAA4><EFBFBD><EFBFBD>%d<>֣<EFBFBD><D6A3>׷<EFBFBD>ʤ<EFBFBD><CAA4><EFBFBD><EFBFBD>%d<><64>******~",q1,q2);
printf("\n\n\n");
printf("\t\t\t~**********<2A><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><D2BB>***********~\n");
}
void Chushihua()//<2F><><EFBFBD>̳<EFBFBD>ʼ<EFBFBD><CABC>
{
int i,j;
X=Y=SIZE/2;
Text="";
count=0;
WANJIA=1;
for(i=0;i<SIZE;i++)
{
for(j=0;j<SIZE;j++)
{
k[i][j]=0;
}
}
}
char* getqipan(int i,int j)//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ָ<EFBFBD><D6B8><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EABDBB>λ<EFBFBD>õ<EFBFBD><C3B5>ַ<EFBFBD><D6B7><EFBFBD>ͨ<EFBFBD><CDA8><EFBFBD>Ʊ<EFBFBD><C6B1><EFBFBD>ƴ<EFBFBD><C6B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
{
if(k[i][j]==1)//1Ϊ<31><CEAA><EFBFBD><EFBFBD>
printf ("<EFBFBD><EFBFBD>") ;
else if(k[i][j]==2)//2Ϊ<32><CEAA><EFBFBD><EFBFBD>
printf ("<EFBFBD><EFBFBD>");
else if(i==0&&j==0)//<2F><><EFBFBD><EFBFBD>Ϊ<EFBFBD><CEAA>Ե<EFBFBD><D4B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʽ
printf ("<EFBFBD><EFBFBD>");
else if(i==SIZE-1&&j==0)
printf ("<EFBFBD><EFBFBD>");
else if(i==SIZE-1&&j==SIZE-1)
printf ("<EFBFBD><EFBFBD>");
else if(i==0&&j==SIZE-1)
printf ("<EFBFBD><EFBFBD>");
else if(i==0)
printf ("<EFBFBD><EFBFBD>");
else if(i==SIZE-1)
printf ("<EFBFBD><EFBFBD>");
else if(j==0)
printf ("<EFBFBD><EFBFBD>");
else if(j==SIZE-1)
printf ("<EFBFBD><EFBFBD>");
else
printf ("<EFBFBD><EFBFBD>");//<2F>м<EFBFBD><D0BC>Ŀ<EFBFBD>λ
}
char* getguangbiao(int i,int j){//<2F><><EFBFBD><EFBFBD>ָ<EFBFBD><D6B8><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EABDBB>λ<EFBFBD><CEBB><EFBFBD><EFBFBD><EFBFBD>ϸ<EFBFBD><CFB8><EFBFBD><EFBFBD><EFBFBD>ʽ<EFBFBD><CABD>ͨ<EFBFBD><CDA8><EFBFBD>Ʊ<EFBFBD><C6B1><EFBFBD><EFBFBD><EFBFBD>ģ<EFBFBD><C4A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʾ
if(i==X){
if(j==Y)
printf("<EFBFBD><EFBFBD>");
else if (j==Y+1)
printf ("<EFBFBD><EFBFBD>");
}
else if(i==X+1)
{
if(j==Y)
printf ("<EFBFBD><EFBFBD>");
else if (j==Y+1)
printf ("<EFBFBD><EFBFBD>");
}
else;
printf ("<EFBFBD><EFBFBD>");//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڹ<EFBFBD><DAB9><EFBFBD><EAB8BD><EFBFBD><EFBFBD>Ϊ<EFBFBD><CEAA>
}
void printqipan()//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
{
int i,j;
for(j=0;j<=SIZE;j++)
{
for(i=0;i<=SIZE;i++)
{
getguangbiao(i,j);//д<><D0B4><EFBFBD><EFBFBD><EFBFBD>Ͻ<EFBFBD><CFBD>ַ<EFBFBD>
if(j==0||j==SIZE)//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>̱<EFBFBD>Ե<EFBFBD><D4B5><EFBFBD>ÿո<C3BF><D5B8><EFBFBD><EFBFBD><EFBFBD>λ<EFBFBD><CEBB>
{
if(i!=SIZE)
printf("<EFBFBD><EFBFBD>");
}
else//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>м<EFBFBD><D0BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>߳н<DFB3><D0BD><EFBFBD><EFBFBD><EFBFBD>
{
if(i==0||i==SIZE-1)//<2F><><EFBFBD>ұ<EFBFBD>Ե<EFBFBD><D4B5><EFBFBD><EFBFBD><EFBFBD>߸<EFBFBD><DFB8><EFBFBD>
printf("<EFBFBD><EFBFBD>");
else if(i!=SIZE)//<2F>м<EFBFBD><D0BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
printf("<EFBFBD><EFBFBD>");
}
}
if(j==SIZE)//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><D2BB>ѭ<EFBFBD><D1AD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֻ<EFBFBD><D6BB>Ҫ<EFBFBD><D2AA><EFBFBD><EFBFBD><EFBFBD>߲<EFBFBD><DFB2>ַ<EFBFBD><D6B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҫ<EFBFBD><D2AA>һ<EFBFBD><D2BB>
{
break;
}
printf("\n");
printf("<EFBFBD><EFBFBD>");
for(i=0;i<SIZE;i++)
{
getqipan(i,j);//д<><EFBFBD><EBBDBB><EFBFBD>ַ<EFBFBD>
if(i!=SIZE-1)//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҳ<EFBFBD><D2B2>򲹳<EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD>߳н<DFB3><D0BD><EFBFBD><EFBFBD><EFBFBD>
{
if(j==0||j==SIZE-1)
{
printf("<EFBFBD><EFBFBD>");//<2F><><EFBFBD>±<EFBFBD>Ե<EFBFBD>ĺ<EFBFBD><C4BA>߸<EFBFBD><DFB8><EFBFBD>
}
else
{
printf("<EFBFBD><EFBFBD>");//<2F>м<EFBFBD><D0BC>ĺ<EFBFBD><C4BA><EFBFBD>
}
}
}
printf("\n");
}
}
int Put(){//<2F>ڵ<EFBFBD>ǰ<EFBFBD><C7B0><EFBFBD><EFBFBD>λ<EFBFBD><CEBB><EFBFBD><EFBFBD><EFBFBD>ӣ<EFBFBD><D3A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ǿգ<C7BF><D5A3>򷵻<EFBFBD>0<EFBFBD><30>ʾʧ<CABE><CAA7>
if(k[X][Y]==0)
{
k[X][Y]=WANJIA;//<2F>ı<EFBFBD><C4B1><EFBFBD>λ<EFBFBD><CEBB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
return 1;//<2F><><EFBFBD><EFBFBD>1<EFBFBD><31>ʾ<EFBFBD>ɹ<EFBFBD>
}
else
{
return 0;
}
}
int Check()//ʤ<><CAA4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><E9A3AC><EFBFBD>жϵ<D0B6>ǰ<EFBFBD><C7B0><EFBFBD><EFBFBD>λ<EFBFBD><CEBB><EFBFBD><EFBFBD>û<EFBFBD><C3BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
{
int w=1,x=1,y=1,z=1,i;
for(i=1;i<5;i++)if(Y+i<SIZE&&k[X][Y+i]==WANJIA)w++;else break;//<2F><><EFBFBD>¼<EFBFBD><C2BC><EFBFBD>
for(i=1;i<5;i++)if(Y-i>0&&k[X][Y-i]==WANJIA)w++;else break;//<2F><><EFBFBD>ϼ<EFBFBD><CFBC><EFBFBD>
for(i=1;i<5;i++)if(X+i<SIZE&&k[X+i][Y]==WANJIA)x++;else break;//<2F><><EFBFBD>Ҽ<EFBFBD><D2BC><EFBFBD>
for(i=1;i<5;i++)if(X-i>0&&k[X-i][Y]==WANJIA)x++;else break;//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
for(i=1;i<5;i++)if(X+i<SIZE&&Y+i<SIZE&&k[X+i][Y+i]==WANJIA)y++;else break;//<2F><><EFBFBD><EFBFBD><EFBFBD>¼<EFBFBD><C2BC><EFBFBD>
for(i=1;i<5;i++)if(X-i>0&&Y-i>0&&k[X-i][Y-i]==WANJIA)y++;else break;//<2F><><EFBFBD><EFBFBD><EFBFBD>ϼ<EFBFBD><CFBC><EFBFBD>
for(i=1;i<5;i++)if(X+i<SIZE&&Y-i>0&&k[X+i][Y-i]==WANJIA)z++;else break;//<2F><><EFBFBD><EFBFBD><EFBFBD>ϼ<EFBFBD><CFBC><EFBFBD>
for(i=1;i<5;i++)if(X-i>0&&Y+i<SIZE&&k[X-i][Y+i]==WANJIA)z++;else break;//<2F><><EFBFBD><EFBFBD><EFBFBD>¼<EFBFBD><C2BC><EFBFBD>
if(z>=5)
{return WANJIA;}
else if(w>=5)
{return WANJIA;}
if(x>=5)
{return WANJIA;}
else if(y>=5)
{return WANJIA;}
else
return 0;
}
int run()//<2F><><EFBFBD><EFBFBD>Ϸ
{
jushu+=1;
int input;
int whichwin;
Chushihua();
while(1)
{
printqipan();
input=getch();
if(input==27)
{
exit(0);
}
else if(input==32 ||input==0x0009)
{
if(Put())
{
whichwin=Check();
count++;
WANJIA=3-WANJIA;
if(whichwin==1)
{
q1+=1;
system("cls");
blackwin();
if (getch()==0xE0)
{
getch();
}
return WANJIA;
}
else if(whichwin==2)
{
q2+=1;
system("cls");
whitewin();
if (getch()==0xE0)
{
getch();
}
return WANJIA;
}
else if (count==SIZE*SIZE)
{
system("cls");
pingju();
if (getch()==0xE0)
{
getch();
}
return 0;
}
}
}
else if(input==0xE0)
{
input=getch();
switch(input)
{
case 0x4B:
X--;
break;
case 0x48:
Y--;
break;
case 0x4D:
X++;
break;
case 0x50:
Y++;
break;
}
if(X<0)X=SIZE-1;//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>λ<EFBFBD><CEBB>Խ<EFBFBD><D4BD><EFBFBD><EFBFBD><EFBFBD>ƶ<EFBFBD><C6B6><EFBFBD><EFBFBD>Բ<EFBFBD>
if(Y<0)Y=SIZE-1;
if(X>SIZE-1)X=0;
if(Y>SIZE-1)Y=0;
}
else if(input=='a')
{
X--;
if(X<0)X=SIZE-1;//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>λ<EFBFBD><CEBB>Խ<EFBFBD><D4BD><EFBFBD><EFBFBD><EFBFBD>ƶ<EFBFBD><C6B6><EFBFBD><EFBFBD>Բ<EFBFBD>
if(Y<0)Y=SIZE-1;
if(X>SIZE-1)X=0;
if(Y>SIZE-1)Y=0;
}
else if(input=='d')
{
X++;
if(X<0)X=SIZE-1;//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>λ<EFBFBD><CEBB>Խ<EFBFBD><D4BD><EFBFBD><EFBFBD><EFBFBD>ƶ<EFBFBD><C6B6><EFBFBD><EFBFBD>Բ<EFBFBD>
if(Y<0)Y=SIZE-1;
if(X>SIZE-1)X=0;
if(Y>SIZE-1)Y=0;
}
else if(input=='s')
{
Y++;
if(X<0)X=SIZE-1;//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>λ<EFBFBD><CEBB>Խ<EFBFBD><D4BD><EFBFBD><EFBFBD><EFBFBD>ƶ<EFBFBD><C6B6><EFBFBD><EFBFBD>Բ<EFBFBD>
if(Y<0)Y=SIZE-1;
if(X>SIZE-1)X=0;
if(Y>SIZE-1)Y=0;
}
else if(input=='w')
{
Y--;
if(X<0)X=SIZE-1;//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>λ<EFBFBD><CEBB>Խ<EFBFBD><D4BD><EFBFBD><EFBFBD><EFBFBD>ƶ<EFBFBD><C6B6><EFBFBD><EFBFBD>Բ<EFBFBD>
if(Y<0)Y=SIZE-1;
if(X>SIZE-1)X=0;
if(Y>SIZE-1)Y=0;
}
}
}
int main()//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
{
system("title <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>γ<EFBFBD><CEB3><EFBFBD><EFBFBD><EFBFBD>-<2D><><EFBFBD><EFBFBD>");//<2F><><EFBFBD>ñ<EFBFBD><C3B1><EFBFBD>
system("mode con cols=100 lines=64");//<2F><><EFBFBD>ô<EFBFBD><C3B4>ڴ<EFBFBD>С
system("color E5");//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɫ
welcome();
help();
while(1){//ѭ<><D1AD>ִ<EFBFBD><D6B4><EFBFBD><EFBFBD>Ϸ
run();
}
}