diff --git a/C语言五子棋课程设计代码-黄智.c b/C语言五子棋课程设计代码-黄智.c new file mode 100644 index 0000000..a232f85 --- /dev/null +++ b/C语言五子棋课程设计代码-黄智.c @@ -0,0 +1,471 @@ +#include +#include +#include +#include +#define MAXIMUS 19 //̴С +int p[MAXIMUS][MAXIMUS];//洢ԾϢ +char buff[MAXIMUS*2+1][MAXIMUS*4+3];// +int Cx,Cy;//ǰλ +int Now;//ǰӵң1ڣ2 +int wl,wp;//ǰд뻺λ +char* showText;//ʾϢ +int count;//غ +char* Copy(char* strDest,const char* strSrc);//޸Ĺַƺĩ˵\0 +void Initialize();//ʼһԾֺ +char* getStyle(int i,int j);//ָ꽻λõַͨƱƴ +char* getCurse(int i,int j);//ָ꽻λϸʽͨƱģʾ +void write(char* c);//򻺳дַ +void ln();//дλ +void Display();//Ļ +void Print();//浽ȻDisplayʾ +int Put();//ڵǰλӣǿգ򷵻0ʾʧ +int JugeWin();//ʤ飬жϵǰλû +int RunGame(); +void welcome(); +void help(); +void bye(); +void DoWin(int v); +void huiqi(int (* p)[MAXIMUS],int num);//庯 +int s1=0,s2=0;/*ļƷֱ*/ +void p1_point();/*1pƷļȡ,1pƷļд,1pƷļ*/ +void p2_point();/*2pƷļȡ,2pƷļд,2pƷļ*/ + + + +char* Copy(char* strDest,const char* strSrc)//޸Ĺַƺĩ˵\0 +{ +char* strDestCopy = strDest; +while (*strSrc!='\0') +{ +*strDest++=*strSrc++; +} +return strDestCopy; +} +void Initialize()//ʼһԾֺ +{ +int i,j;//ѭ +showText="";//ʾϢ +count=0;//غ +for(i=0;i0&&p[Cx][Cy-i]==Now)w++;else break;//ϼ +if(w>=5)return Now;//ﵽ5жϵǰΪӮ +for(i=1;i<5;i++)if(Cx+i0&&p[Cx-i][Cy]==Now)x++;else break;// +if(x>=5)return Now;//ﵽ5жϵǰΪӮ +for(i=1;i<5;i++)if(Cx+i0&&Cy-i>0&&p[Cx-i][Cy-i]==Now)y++;else break;//ϼ +if(y>=5)return Now;//ﵽ5жϵǰΪӮ +for(i=1;i<5;i++)if(Cx+i0&&p[Cx+i][Cy-i]==Now)z++;else break;//ϼ +for(i=1;i<5;i++)if(Cx-i>0&&Cy+i=5)return Now;//ﵽ5жϵǰΪӮ +return 0;//ûм鵽飬򷵻0ʾûҴʤ +} +int RunGame()//Ծ֣ӮϢ(Ȼ) +{ +int input;// +int victor;//ӮϢ +Initialize();//ʼԾ +while(1){//ʼ޻غϵѭֱʤ +if(Now==1) +printf("ǰӷɫΪɫ"); +if(Now==2) +printf("ǰӷɫΪɫ"); +Print();//ӡ +input=getch();//ȴ̰һַ +if(input==27)//ESC˳ +{ +exit(0); +} +else if(input==8) +{ + huiqi(p,Now); + Now=3-Now; +} +else if(input==0x20&&Now==1||input==13&&Now==2)//ǿոʼ +{ +if(Put())//ӳɹжʤ +{ +victor=JugeWin(); +Now=3-Now;//ֻǰ +count++; +if(victor==1)//ڷﵽʤʾʾֲȴһΰʤϢ +{ +DoWin(victor); +if(getch()==0xE0) +{ +getch(); +} +return Now; +} +else if(victor==2)//׷ﵽʤʾʾֲȴһΰʤϢ +{ +DoWin(victor); +if(getch()==0xE0) +{ +getch(); +} +return Now; +} +else if(count==MAXIMUS*MAXIMUS)//غﵽ̳Ϊƽ +{ +showText="ƽ֣"; +Display(); +if(getch()==0xE0) +{ +getch(); +} +return 0; +} +} +} +else if(Now==2&&input==0xE0)//µǷ룬һΪ0xE0ʾµǿƼ +{ +input=getch();//õڶϢ +switch(input)//жϷƶλ +{ +case 0x4B: Cx--;break; +case 0x48: Cy--;break; +case 0x4D: Cx++;break; +case 0x50: Cy++;break; +} +} +if(Now==1) +{ +switch(input)//жw,s,a,dƶλ +{ +case 'a': Cx--;break; +case 'w': Cy--;break; +case 'd': Cx++;break; +case 's': Cy++;break; +} +} +if(Cx<0)Cx=MAXIMUS-1;//λԽƶԲ +if(Cy<0)Cy=MAXIMUS-1; +if(Cx>MAXIMUS-1)Cx=0; +if(Cy>MAXIMUS-1)Cy=0; +} +} +void welcome() /*ӭ*/ +{ +Initialize(); /*ʼ*/ +system("cls"); /**/ +system("color 2"); /*ɫ*/ +system("mode con cols=504 lines=512");/*ʽ*/ +printf("\n\n\tXTTTTTTTTTTTTTTTTTT[\n"); +printf("\tU U\n"); +printf("\tU ӭϷף죡 U\n"); +printf("\tU U\n"); +printf("\tU ._______________________. U\n"); +printf("\tU | _____________________ | U\n"); +printf("\tU | I I | U\n"); +printf("\tU | I I | U\n"); +printf("\tU | I I | U\n"); +printf("\tU | I I | U\n"); +printf("\tU | I___________________I | U\n"); +printf("\tU !_______________________! U\n"); +printf("\tU ._[__________]_. U\n"); +printf("\tU .___|_______________|___. U\n"); +printf("\tU |::: ____ | U\n"); +printf("\tU | ~~~~ [CD-ROM] | U\n"); +printf("\tU !_____________________! U\n"); +printf("\tU U\n"); +printf("\tU U\n"); +printf("\tU U\n"); +printf("\tU U\n"); +printf("\tU 밴档 U\n"); +printf("\tU || U\n"); +printf("\tU || U\n"); +printf("\tU || U\n"); +printf("\tU || U\n"); +printf("\t^TTTTTTTTTTTTTTTTTTa\n"); + getch(); +} +void help() /*,ͬwelcome();*/ +{ + Initialize(); + system("cls"); /**/ + system("color 2"); /*ɫ*/ + system("mode con cols=504 lines=512");/*ʽ*/ +printf("\n\n\tX[\n"); +printf("\tU ʾ U\n"); +printf("\tU1 U\n"); +printf("\tUƶWϣS£ U\n"); +printf("\tU A󣩣Dң U\n"); +printf("\tU壺ո U\n"); +printf("\tU2 U\n"); +printf("\tUƶҷ U\n"); +printf("\tU壺س U\n"); +printf("\tU壺Backspace U\n"); +printf("\tU U\n"); +printf("\tU U\n"); +printf("\tU U\n"); +printf("\tU U\n"); +printf("\tU U\n"); +printf("\tU U\n"); +printf("\tU ! U\n"); +printf("\tU U\n"); +printf("\tU U\n"); +printf("\t^a\n"); +getch(); +} +void DoWin(int v) +{ + int n; + Initialize(); + system("cls"); /**/ + system("color F0"); /*ɫ*/ +if(v==1) +{ +printf(" ڷʤ \n"); +p1_point(); +} +if(v==2) +{ +printf(" ׷ʤ \n"); +p2_point(); +} +printf("\n\n\n\n\tX[\n"); +printf("\tU U\n"); +printf("\tU U\n"); +printf("\tU U\n"); +printf("\tU U\n"); +printf("\tU U\n"); +printf("\tU U\n"); +printf("\tU һ U\n"); +printf("\tU U\n"); +printf("\tU U\n"); +printf("\tU U\n"); +printf("\tU 1 U\n"); +printf("\tU U\n"); +printf("\tU U\n"); +printf("\tU U\n"); +printf("\tU U\n"); +printf("\tU 2 U\n"); +printf("\tU U\n"); +printf("\tU U\n"); +printf("\t^a\n"); +scanf("%d",&n); +if(n==1) +printf("밴"); +if(n==2) +bye(); +} +void bye() /*say bye~@!,ʵֹͬ*/ +{ + Initialize(); + system("cls"); /**/ + system("color 2"); /*ɫ*/ +printf("\tX[\n"); +printf("\tU U\n"); +printf("\tU U\n"); +printf("\tU U\n"); +printf("\tU ллʹ U\n"); +printf("\tU U\n"); +printf("\tU U\n"); +printf("\tU U\n"); +printf("\tU U\n"); +printf("\tU U\n"); +printf("\tU U\n"); +printf("\tU U\n"); +printf("\tU U\n"); +printf("\tU U\n"); +printf("\tU U\n"); +printf("\tU л U\n"); +printf("\tU л U\n"); +printf("\tU ټ U\n"); +printf("\tU U\n"); +printf("\t^a\n"); + exit(0); +} +void huiqi(int (* p)[MAXIMUS],int num)//庯 +{ + int i,j; + for(i=0;i -#include -#include -#include -#define MAXIMUS 19 -#define W 0x1177 -#define S 0x1f73 -#define A 0x1e61 -#define D 0x2064 -int p[MAXIMUS][MAXIMUS]; -char buff[MAXIMUS*2+1][MAXIMUS*4+3]; -int Cx,Cy; -int Now; -int wl,wp; -char* showText; -int count; -int bye(); -int DoWin(int v); -char* Copy(char* strDest,const char* strSrc) -{ -char* strDestCopy = strDest; -while (*strSrc!='\0') -{ -*strDest++=*strSrc++; -} -return strDestCopy; -} -void Initialize() -{ -int i,j; -showText=""; -count=0; -for(i=0;i