From 92b1c1761d6da7b9c534bdb56179ea05a310b75f Mon Sep 17 00:00:00 2001 From: "18408000302@stu.hut.edu.cn" <18408000302@stu.hut.edu.cn> Date: Fri, 11 Jan 2019 14:29:16 +0800 Subject: [PATCH] first commit --- 文件(1).c | 462 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 计分板.c | 35 ++++ 2 files changed, 497 insertions(+) create mode 100644 文件(1).c create mode 100644 计分板.c diff --git a/文件(1).c b/文件(1).c new file mode 100644 index 0000000..f46969a --- /dev/null +++ b/文件(1).c @@ -0,0 +1,462 @@ +#include +#include +#include +#include"Ʒְ.c" +extern void jifenban();//һļļƷְ庯 +void huanying();//ӭ +void printqipan();//ӡ +void initqipan();//ʼ +void white();//׷ +void black();//ڷ +void startgame();//Ϸʼ +int panduan(int,int);//жӮ +int win(); //ʾ˭Ӯ +char p[19][19][4];// +int a,b,c,d,x,y,w,z,B,H;//BH¼׺ֵӮּƷ +char ch; +int whowin; +int last;//ʣλ + + +int main(){ + huanying(); + return 0; +} + +void startgame() //Ϸ庯 +{ + initqipan(); /*̳ʼ*/ + while(1) + { + black();//ڷ庯 + last--;//ʣλ + if(win()==1)//жǷһӮ + break; + system("cls");//Ļ + // + white();//׷庯 + last--;//ʣλ + if(win()==1)//жǷһӮ + break; + system("cls");//Ļ + if(last==0) + win();//ƽֽʤʾ˭Ӯ + } + printf(" Ƿ¿ʼϷ룺Y or N ");//ѯûǷһ + scanf("%s",&ch); + if(ch=='Y')//һ + { + system("cls"); + startgame();//ٴνϷʼϷ + } + if(ch=='N')//˳Ϸ + { + system("cls"); + printf(" ~Ϸ~");//Ϸ + jifenban();////////һļļƷְ庯///////// + return; + + } +} + + + void black() // +{ + printqipan(); + printf("\n ڷ \n");//ڷ + printf(" ʾΪ ո ꡱ2 3ʾΪ2Ϊ3 \n");//ʾûʽ + printf(" "); + scanf("%d%d",&x,&y); + while(1) + { + if(strcmp(p[x][y]," ")==0)//жλǷ + { + strcpy(p[x][y],"");//ûº + break; + } + else + printf(" ڴλӣ꣺");//ʾû + scanf("%d%d",&x,&y); + } + system("cls"); + printqipan(); + printf(" Ҫ룺Y N ");//ѯûǷҪ + scanf("%s",&ch); + if(ch=='Y') + { + system("cls"); + strcpy(p[x][y]," ");//ԭһ + black();//庯 + } + if(ch=='N') + return;//˳ + } + +void white() // +{ + printqipan();//ӡ̺ + printf("\n ׷ \n");//׷ + printf(" ʾΪ ո ꡱ2 3ʾΪ2Ϊ3 \n");//ʾʽ + printf(" "); + scanf("%d%d",&x,&y); + while(1) + { + if(strcmp(p[x][y]," ")==0)//жϴλǷ + { + strcpy(p[x][y],"");//û° + break; + } + else + printf(" ڴλӣ꣺");//ʾ + scanf("%d%d",&x,&y); + } + system("cls"); + printqipan(); + printf(" Ҫ룺Y N ");//ѯǷ + scanf("%s",&ch); + if(ch=='Y') + { + strcpy(p[x][y]," ");//ԭ + system("cls"); + white();// + } + if(ch=='N')//˳ + return; + } + + + int win() ///////ʾһӮ +{ + int havewinner=0; + int whowin; + whowin=panduan(x,y); //////ʾ˭Ӯ ׷ 1 ڷ 2 + if(whowin==1) + { + havewinner=1; + + printf(" \n ׷ʤ\n"); + B++;//ƷӮһ + + } + if(whowin==2) + { + havewinner=1; + + printf(" \n ڷʤ\n"); + H++;//ƷӮһ + + } + if(last==0&&havewinner==0) + printf("~ƽ~");//ƽʾ + return havewinner; +} + + + int panduan(int x,int y)/////////////жϺ +{ + char color[4];//巽ɫ + int count=1;//ͳƸ,Եͬһ + int i=1;//ˮƽֱ + int j=1;//iͬʱб + int winner=0;//1׷2ڷ + strcpy(color,p[x][y]); + //ˮƽ + while(strcmp(color,p[x][y-i])==0&&x>=0&&x<19&&y>=0&&y<19&&count<5) + { + i++; + count++; + if(count==5)//count5ж˭ӮˣȻʸû + { + if(strcmp(color,"")==0) + winner=1; + else + winner=2; + strcpy(p[x][y],"Ӯ"); + i=1;count=1; + while(strcmp(color,p[x][y-i])==0&&x>=0&&x<19&&y>=0&&y<19&&count<5) + { + strcpy(p[x][y-i],"Ӯ"); + i++;count++; + } + i=1; + while(strcmp(color,p[x][y+i])==0&&x>=0&&x<19&&y>=0&&y<19&&count<5) + { + strcpy(p[x][y+i],"Ӯ"); + i++;count++; + } + } + } + //ˮƽұ + i=1; + while(strcmp(color,p[x][y+i])==0&&x>=0&&x<19&&y>=0&&y<19&&count<5) + { + i++; + count++; + if(count==5)//count5ж˭ӮˣȻʸû + { + if(strcmp(color,"")==0) + winner=1; + else + winner=2; + strcpy(p[x][y],"Ӯ"); + i=1;count=1; + while(strcmp(color,p[x][y+i])==0&&x>=0&&x<19&&y>=0&&y<19&&count<5) + { + strcpy(p[x][y+i],"Ӯ"); + i++;count++; + } + i=1; + while(strcmp(color,p[x][y-i])==0&&x>=0&&x<19&&y>=0&&y<19&&count<5) + { + strcpy(p[x][y-i],"Ӯ"); + i++;count++; + } + } + } + + //ֱķ + //ֱϷ + i=1; + count=1;//֮ǰ + while(strcmp(color,p[x-i][y])==0&&x>=0&&x<19&&y>=0&&y<19&&count<5) + { + i++; + count++; + if(count==5)//count5ж˭ӮˣȻʸû + { + if(strcmp(color,"")==0) + winner=1; + else + winner=2; + strcpy(p[x][y],"Ӯ"); + i=1;count=1; + while(strcmp(color,p[x-i][y])==0&&x>=0&&x<19&&y>=0&&y<19&&count<=5) + { + strcpy(p[x-i][y],"Ӯ"); + i++;count++; + } + i=1; + while(strcmp(color,p[x+i][y])==0&&x>=0&&x<19&&y>=0&&y<19&&count<=5) + { + strcpy(p[x+i][y],"Ӯ"); + i++;count++; + } + } + } + //ֱ· + i=1; + while(strcmp(color,p[x+i][y])==0&&x>=0&&x<19&&y>=0&&y<19&&count<5) + { + i++; + count++; + if(count==5)//count5ж˭ӮˣȻʸû + { + if(strcmp(color,"")==0) + winner=1; + else + winner=2; + strcpy(p[x][y],"Ӯ"); + i=1;count=1; + while(strcmp(color,p[x+i][y])==0&&x>=0&&x<19&&y>=0&&y<19&&count<=5) + { + strcpy(p[x+i][y],"Ӯ"); + i++;count++; + } + i=1; + while(strcmp(color,p[x-i][y])==0&&x>=0&&x<19&&y>=0&&y<19&&count<=5) + { + strcpy(p[x-i][y],"Ӯ"); + i++;count++; + } + } + } + //ϵб Ϸ + i=1; + j=1; + count=1; + while(strcmp(color,p[x-i][y-j])==0&&x>=0&&x<19&&y>=0&&y<19&&count<5) + { + i++; + j++; + count++; + if(count==5)//count5ж˭ӮˣȻʸû + { + if(strcmp(color,"")==0) + winner=1; + else + winner=2; + strcpy(p[x][y],"Ӯ"); + i=1;j=1;count=1; + while(strcmp(color,p[x-i][y-j])==0&&x>=0&&x<19&&y>=0&&y<19&&count<5) + { + strcpy(p[x-i][y-j],"Ӯ"); + i++;j++;count++; + } + i=1;j=1; + while(strcmp(color,p[x+i][y+j])==0&&x>=0&&x<19&&y>=0&&y<19&&count<5) + { + strcpy(p[x+i][y+j],"Ӯ"); + i++;j++;count++; + } + } + } + //ϵб · + i=1; + j=1; + while(strcmp(color,p[x+i][y+j])==0&&x>=0&&x<19&&y>=0&&y<19&&count<5) + { + i++; + j++; + count++; + if(count==5)//count5ж˭ӮˣȻʸû + { + if(strcmp(color,"")==0) + winner=1; + else + winner=2; + strcpy(p[x][y],"Ӯ"); + i=1;j=1;count=1; + while(strcmp(color,p[x+i][y+j])==0&&x>=0&&x<19&&y>=0&&y<19&&count<5) + { + strcpy(p[x+i][y+j],"Ӯ"); + i++;j++;count++; + } + i=1;j=1; + while(strcmp(color,p[x-i][y-j])==0&&x>=0&&x<19&&y>=0&&y<19&&count<5) + { + strcpy(p[x-i][y-j],"Ӯ"); + i++;j++;count++; + } + } + } + //ϵб Ϸ + i=1; + j=1; + count=1; + while(strcmp(color,p[x-i][y+j])==0&&x>=0&&x<19&&y>=0&&y<19&&count<5) + { + i++; + j++; + count++; + if(count==5)//count5ж˭ӮˣȻʸû + { + if(strcmp(color,"")==0) + winner=1; + else + winner=2; + strcpy(p[x][y],"Ӯ"); + i=1;j=1;count=1; + while(strcmp(color,p[x-i][y+j])==0&&x>=0&&x<19&&y>=0&&y<19&&count<5) + { + strcpy(p[x-i][y+j],"Ӯ"); + i++;j++;count++; + } + i=1;j=1; + while(strcmp(color,p[x+i][y-j])==0&&x>=0&&x<19&&y>=0&&y<19&&count<5) + { + strcpy(p[x+i][y-j],"Ӯ"); + i++;j++;count++; + } + } + } + //ϵб · + i=1; + j=1; + while(strcmp(color,p[x+i][y-j])==0&&x>=0&&x<19&&y>=0&&y<19&&count<5) + { + i++; + j++; + count++; + if(count==5)//count5ж˭ӮˣȻʸû + { + if(strcmp(color,"")==0) + winner=1; + + else + winner=2; + strcpy(p[x][y],"Ӯ"); + i=1;j=1;count=1; + while(strcmp(color,p[x+i][y-j])==0&&x>=0&&x<19&&y>=0&&y<19&&count<5) + { + strcpy(p[x+i][y-j],"Ӯ"); + i++;j++;count++; + } + i=1;j=1; + while(strcmp(color,p[x-i][y+j])==0&&x>=0&&x<19&&y>=0&&y<19&&count<5) + { + strcpy(p[x-i][y+j],"Ӯ"); + i++;j++;count++; + } + } + } + return winner; +} + + + void initqipan() /////////ʼ +{ + int i,j; + for(i=0;i<19;i++) + for(j=0;j<19;j++) + strcpy(p[i][j]," "); +} + void printqipan() /*ӡ*/ +{ + int i,j; + system("color e2");//ĻΪɫΪɫ + printf(" ӭ\n"); + printf(" 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 \n"); + printf(" \n"); + for(i=0,j=0;i<18;i++,j++){ + printf(" %2d %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s%2d\n",j,p[i][0],p[i][1],p[i][2],p[i][3],p[i][4],p[i][5],p[i][6],p[i][7],p[i][8],p[i][9],p[i][10],p[i][11],p[i][12],p[i][13],p[i][14],p[i][15],p[i][16],p[i][17],p[i][18],j); + printf(" \n"); + } + printf(" 18 %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s18\n",p[18][0],p[18][1],p[18][2],p[18][3],p[18][4],p[18][5],p[18][6],p[18][7],p[18][8],p[18][9],p[18][10],p[18][11],p[18][12],p[18][13],p[18][14],p[18][15],p[18][16],p[18][17],p[18][18]); + printf(" \n"); + printf(" 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 \n"); +} + + void huanying() //ӭ +{ + char choice; + int i,j; + system("color e2"); //ĻΪdzɫΪɫ + printf("\n\n\n\n\n\n\n\n\n\n\n"); + printf(" \n");/*ӭ*/ + for(i=0;i<5;i++) + printf(" \n"); + printf(" \n"); + for(i=0;i<3;i++) + printf(" \n"); + printf(" \n"); + printf(" \n\n"); + printf(" ӭϹҵѧϷ\n\n"); + printf(" ļ飺һϷ˭\n");/*Ϸ*/ + printf(" ͬɫӣ˭ӮñͰֱͺб45͡\n\n"); + printf(" *******************************СաСϳƷ***********************************\n"); + printf(" Ϫ ף \n"); + printf(" ׷ ɽ ȡ\n"); + printf(" Ͽ ˮ ᰡ\n"); + printf(" ǣб 󡣡\n"); + printf(" ʮ ֱ ָ б ǡ\n\n"); + printf(" ---ʫ͸\n\n");/*һ׹ʫ͸Ϸߡ*/ + printf(" һְɡ\n\n"); + printf(" ˶ս\n\n"); + printf(" 뿪ʼϷ1.ʼϷ 2.˳Ϸ\n\n ѡǣ");/*ûѡϷĿʼ˳Ϸ*/ + scanf("%s",&choice); + while(1){ + if(choice=='1'||choice=='2') + { + if(choice=='1') + { + system("cls"); + startgame(); ////////ʼϷ + } + if(choice=='2') + return ; + } + else + printf(" Ŷ");/*û淶ʾҪû*/ + scanf("%s",&choice); + } +} diff --git a/计分板.c b/计分板.c new file mode 100644 index 0000000..476f51d --- /dev/null +++ b/计分板.c @@ -0,0 +1,35 @@ +#include +#include +extern void printqipan(); +void jifenban(){//Ƿְ + extern int B; + extern int H; + system("color e2"); + printf("\n\n"); + printqipan(); + printf("\n\n"); + printf(" _____________\n"); + printf(" +++++ \n"); + printf(" +++++ \n"); + printf(" _____________________ __________________________________\n"); + printf(" ( ) \n"); + printf(" / \\ ׷ѡֻʤ%2d \n",B); + printf(" / || || \\ _______________________________\n"); + printf(" { } \n"); + printf(" < {ѡ} > ڷѡֻʤ%2d \n",H); + printf(" \\ ___С___ / _______________________________\n"); + printf(" \\ !|||||! / Ƿְ \n"); + printf(" --------------------------- _______________________________\n"); + printf(" |||||||||||||||||||||||||| \n"); + printf(" |||||||||||||||||||||||||| \n"); + printf(" \n"); + printf(" ____________________________________ \n"); + printf(" / \n"); + printf(" _______________________________________\n"); + printf(" \n"); + printf(" \\ \n"); + printf(" \n"); + printf(" _____________ \n"); + printf(" !YOU LOVE LOVE YOU!"); + return; +}