国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學(xué)院 > 開發(fā)設(shè)計(jì) > 正文

五子棋

2019-11-08 02:28:20
字體:
供稿:網(wǎng)友
/*1、畫一個(gè)19*19的棋盤2、定義一個(gè)棋盤數(shù)組3、光標(biāo)移動(dòng)的函數(shù)4、落子的函數(shù)5、判定是否落子的函數(shù)6、判定輸贏的函數(shù)7、執(zhí)行函數(shù)8、重新開始函數(shù) */#include<stdio.h>#include<conio.h>#include<windows.h>#include<string.h>#include<stdlib.h>void  exe();void drawBoard();void gotoxy(int x,int y); void move();void init();  void border();void  luozi();void blance();void  record();void inittow(); void after();#define  width  19#define  height 19int k,l,m,n;int count;//棋盤 int chessboard[height][width];//設(shè)置一個(gè)flag判定是否已經(jīng)落子int flag=1;char PRess; //記錄當(dāng)前光標(biāo)位置的結(jié)構(gòu)體typedef struct position{int x;int y; }position; position chess;  //勝利之后的動(dòng)作 void after()  {  char a;  if(count==5){gotoxy(0,20);if(!flag==0)printf("玩家%d勝利/n",!flag+2);elseprintf("玩家%d勝利/n",!flag);printf("是否重新開始一局?Y/N/n");scanf("%s",&a);switch(a){case 'Y':exe();break;case 'N':exit(0);break;}} }//畫棋盤 void drawBoard(){int i,j;system("cls");for(i=0;i<height;i++){for(j=0;j<width;j++){printf("十");chessboard[i][j]=10;}printf("/n");}}// 光標(biāo)移動(dòng)的函數(shù)void gotoxy(int x,int y) {COORD c;c.X=2*x;c.Y=y;SetConsoleCursorPosition (GetStdHandle(STD_OUTPUT_HANDLE), c); //修改當(dāng)前光標(biāo)的位置}//判定是否出界void border(){if(chess.x<19&&chess.y<19&&chess.x>=0&&chess.y>=0){gotoxy(chess.x,chess.y);} } //落子的函數(shù)void  luozi(){if(flag){printf("●"); chessboard[chess.y][chess.x]=1;flag=!flag;}else{printf("○"); chessboard[chess.y][chess.x]=0;flag=!flag;} }//判定初始化void inittow(){count=0;k=chess.y;m=chess.y;l=chess.x;n=chess.x;  } //記錄 void  record(){//豎直方向inittow();while(chessboard[k][l]==(!flag)||chessboard[m][n]==(!flag)){if(chessboard[k][l]==(!flag)){k--;if(chessboard[k][l]==(!flag));count++;}if(chessboard[m][n]==(!flag)){m++;if(chessboard[m][n]==(!flag))count++; }}after(); //水平方向inittow();while(chessboard[k][l]==!flag||chessboard[m][n]==!flag){if(chessboard[k][l]==(!flag)){l--;if(chessboard[k][l]==(!flag));count++;}if(chessboard[m][n]==(!flag)){n++;if(chessboard[m][n]==(!flag))count++; }}after(); //左上到右下inittow();while(chessboard[k][l]==!flag||chessboard[m][n]==!flag){if(chessboard[k][l]==(!flag)){k--;l--;if(chessboard[k][l]==(!flag));count++;}if(chessboard[m][n]==(!flag)){m++;n++;if(chessboard[m][n]==(!flag))count++; }}after();//右上到左下 inittow();while(chessboard[k][l]==!flag||chessboard[m][n]==!flag){if(chessboard[k][l]==(!flag)){k++;l--;if(chessboard[k][l]==(!flag));count++;}if(chessboard[m][n]==(!flag)){m--;n++;if(chessboard[m][n]==(!flag))count++; }}after();}//判定輸贏的函數(shù)void blance(){record();}//控制光標(biāo)移動(dòng)以及落子的函數(shù) void move(){if(press){switch(press){case 'w':chess.y-=1;border();break;case 's':chess.y+=1;border(); break;case 'a':chess.x-=1;border(); break;case 'd':chess.x+=1;border(); break; case 'j':luozi();blance();break; }}} //初始化函數(shù)void init(){drawBoard();gotoxy(0,0);chess.x=0;chess.y=0; } //執(zhí)行函數(shù)void  exe(){init();while(1){press=getch();move();}} int main(){system("color 2d");exe();gotoxy(19,19);}
發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 新营市| 庄河市| 永宁县| SHOW| 美姑县| 长沙县| 辽宁省| 仙居县| 永平县| 谷城县| 新龙县| 沅陵县| 哈尔滨市| 连城县| 古田县| 莱州市| 鹤山市| 清水县| 托克逊县| 收藏| 北安市| 全南县| 抚松县| 新河县| 天津市| 个旧市| 友谊县| 天峻县| 安新县| 德安县| 剑川县| 潞城市| 广东省| 潞城市| 四平市| 新沂市| 集安市| 冕宁县| 逊克县| 聂荣县| 晋宁县|