当前位置: 首页 > news >正文

黑白风格网站二级网站怎么做

黑白风格网站,二级网站怎么做,网站首页制作代码,h5开发工程师是做什么的目录 C语言编程实现五子棋&#xff1a;&#xff1a; game.h game.c 1.打印菜单 2.打印棋盘 3.玩家下棋 4.判断五子连珠 5.判断输赢 6.游戏运行 game.c完整源代码展示 test.c C语言编程实现五子棋&#xff1a;&#xff1a; game.h #pragma once #include<stdio.h> …

目录

C语言编程实现五子棋::

game.h

game.c

                        1.打印菜单

                        2.打印棋盘

                        3.玩家下棋

                        4.判断五子连珠

                        5.判断输赢

                        6.游戏运行

game.c完整源代码展示

test.c


C语言编程实现五子棋::

game.h

#pragma once
#include<stdio.h>
#include<stdlib.h>
#define ROW 20
#define COL 20
#define PLAYER1 1
#define PLAYER2 2
#define NEXT 0
#define PLAYER1_WIN 1
#define PLAYER2_WIN 2
#define DRAW 3 
enum Dir
{LEFT,RIGHT,UP,DOWN,LEFT_UP,LEFT_DOWN,RIGHT_UP,RIGHT_DOWN
};
void Menu();
void Game();

game.c

1.打印菜单

void Menu()
{printf("#############################\n");printf("#######   五子棋游戏   ######\n");printf("#######1.Play    0.Exit######\n");printf("#############################\n");printf("#############################\n");printf("Please Select:");
}

2.打印棋盘

void ShowBoard(int board[ROW][COL], int row, int col)
{//清屏system("cls");printf("  ");int i = 1;for (i = 1;i <= col;i++){printf("%3d", i);}printf("\n");for (i = 0;i < row;i++){int j = 0;printf("%2d ", i + 1);for (j = 0;j < col;j++){if (board[i][j] == 0){printf(" . ");}else if (board[i][j] == PLAYER1){printf(" # ");}else{printf(" o ");}}printf("\n");}
}

3.玩家下棋

void PlayerMove(int board[ROW][COL], int row, int col, int who)
{while (1){printf("Player[%d] Please Enter your Pos:", who);scanf("%d %d", &x, &y);if (x < 1 || x > row || y < 1 || y > col){printf("输入坐标不合法!\n");continue;}else if (board[x - 1][y - 1] != 0){printf("Pos Is Occupied!\n");continue;}else{board[x - 1][y - 1] = who;break;}}
}

4.判断五子连珠

int ChessCount(int board[ROW][COL], int row, int col,enum Dir d)
{int _x = x - 1;int _y = y - 1;int count = 0;while (1){switch (d){case LEFT:_y--;break;case RIGHT:_y++;break;case UP:_x--;break;case DOWN:_x++;break;case LEFT_UP:_x--;_y--;break;case LEFT_DOWN:_x++;_y--;break;case RIGHT_UP:_x--;_y++;break;case RIGHT_DOWN:_x++;_y++;break;default://Do Nothingbreak;}//不合法if (_x < 0 || _x > row - 1 || _y < 0 || _y > col - 1){break;}//合法if (board[x - 1][y - 1] == board[_x][_y]){count++;}else{break;}}return count;
}

5.判断输赢

int IsWin(int board[ROW][COL], int row, int col)
{//在当前位置(x,y)处int count1 = ChessCount(board, row, col, LEFT) + ChessCount(board, row, col, RIGHT) + 1;int count2 = ChessCount(board, row, col, UP) + ChessCount(board, row, col, DOWN) + 1;int count3 = ChessCount(board, row, col, LEFT_UP) + ChessCount(board, row, col, RIGHT_DOWN) + 1;int count4 = ChessCount(board, row, col, LEFT_DOWN) + ChessCount(board, row, col, RIGHT_UP)+ 1;if (count1 >= 5 || count2 >= 5 || count3 >= 5 || count4 >= 5){if (board[x - 1][y - 1] == PLAYER1){return PLAYER1_WIN;}else{return PLAYER2_WIN;}}int i = 0;for (i = 0;i < row;i++){int j = 0;for (j = 0;i < col;j++){if (board[i][j] == 0){return NEXT;}}}return DRAW;
}

6.游戏运行

void Game()
{int board[ROW][COL];memset(board, 0, sizeof(board));int result = NEXT;do{ShowBoard(board, ROW, COL);PlayerMove(board, ROW, COL, PLAYER1);result = IsWin(board, ROW, COL);ShowBoard(board, ROW, COL);if (NEXT != result){break;}ShowBoard(board, ROW, COL);PlayerMove(board, ROW, COL, PLAYER2);result = IsWin(board, ROW, COL);if (NEXT != result){break;}} while (1);//用户1赢 用户2赢 平局switch (result){case PLAYER1_WIN:printf("恭喜用户1,你已经赢了!\n");break;case PLAYER2_WIN:printf("恭喜用户2,你已经赢了!\n");break;case DRAW:printf("平局,和气生财!\n");break;default:break;}system("pause");ShowBoard(board, ROW, COL);
}

game.c完整源代码展示:

#define _CRT_SECURE_NO_WARNINGS
#include"game.h"
int x = 0;
int y = 0;
void Menu()
{printf("#############################\n");printf("#######   五子棋游戏   ######\n");printf("#######1.Play    0.Exit######\n");printf("#############################\n");printf("#############################\n");printf("Please Select:");
}
//按照(x,y)作为起点,按照特定的方向,求连续相对的最大个数
int ChessCount(int board[ROW][COL], int row, int col,enum Dir d)
{int _x = x - 1;int _y = y - 1;int count = 0;while (1){switch (d){case LEFT:_y--;break;case RIGHT:_y++;break;case UP:_x--;break;case DOWN:_x++;break;case LEFT_UP:_x--;_y--;break;case LEFT_DOWN:_x++;_y--;break;case RIGHT_UP:_x--;_y++;break;case RIGHT_DOWN:_x++;_y++;break;default://Do Nothingbreak;}//不合法if (_x < 0 || _x > row - 1 || _y < 0 || _y > col - 1){break;}//合法if (board[x - 1][y - 1] == board[_x][_y]){count++;}else{break;}}return count;
}
//4种返回值 NEXT:继续 PLAYER1_WIN:用户1赢 PLAYER2_WIN:用户2赢 DRAW:平局
int IsWin(int board[ROW][COL], int row, int col)
{//在当前位置(x,y)处int count1 = ChessCount(board, row, col, LEFT) + ChessCount(board, row, col, RIGHT) + 1;int count2 = ChessCount(board, row, col, UP) + ChessCount(board, row, col, DOWN) + 1;int count3 = ChessCount(board, row, col, LEFT_UP) + ChessCount(board, row, col, RIGHT_DOWN) + 1;int count4 = ChessCount(board, row, col, LEFT_DOWN) + ChessCount(board, row, col, RIGHT_UP)+ 1;if (count1 >= 5 || count2 >= 5 || count3 >= 5 || count4 >= 5){if (board[x - 1][y - 1] == PLAYER1){return PLAYER1_WIN;}else{return PLAYER2_WIN;}}int i = 0;for (i = 0;i < row;i++){int j = 0;for (j = 0;i < col;j++){if (board[i][j] == 0){return NEXT;}}}return DRAW;
}
void ShowBoard(int board[ROW][COL], int row, int col)
{//清屏system("cls");printf("  ");int i = 1;for (i = 1;i <= col;i++){printf("%3d", i);}printf("\n");for (i = 0;i < row;i++){int j = 0;printf("%2d ", i + 1);for (j = 0;j < col;j++){if (board[i][j] == 0){printf(" . ");}else if (board[i][j] == PLAYER1){printf(" # ");}else{printf(" o ");}}printf("\n");}
}
void PlayerMove(int board[ROW][COL], int row, int col, int who)
{while (1){printf("Player[%d] Please Enter your Pos:", who);scanf("%d %d", &x, &y);if (x < 1 || x > row || y < 1 || y > col){printf("输入坐标不合法!\n");continue;}else if (board[x - 1][y - 1] != 0){printf("Pos Is Occupied!\n");continue;}else{board[x - 1][y - 1] = who;break;}}
}
void Game()
{int board[ROW][COL];memset(board, 0, sizeof(board));int result = NEXT;do{ShowBoard(board, ROW, COL);PlayerMove(board, ROW, COL, PLAYER1);result = IsWin(board, ROW, COL);ShowBoard(board, ROW, COL);if (NEXT != result){break;}ShowBoard(board, ROW, COL);PlayerMove(board, ROW, COL, PLAYER2);result = IsWin(board, ROW, COL);if (NEXT != result){break;}} while (1);//用户1赢 用户2赢 平局switch (result){case PLAYER1_WIN:printf("恭喜用户1,你已经赢了!\n");break;case PLAYER2_WIN:printf("恭喜用户2,你已经赢了!\n");break;case DRAW:printf("平局,和气生财!\n");break;default:break;}system("pause");ShowBoard(board, ROW, COL);
}

test.c

#define _CRT_SECURE_NO_WARNINGS
#include"game.h"
int main()
{int select = 0;int quit = 0;while (quit == 0){Menu();scanf("%d", &select);switch (select){case 1:Game();break;case 0:quit = 1;printf("游戏结束\n");break;default:printf("输入错误,请重新输入!\n");break;}}return 0;
}


文章转载自:
http://complaint.c7493.cn
http://omdurman.c7493.cn
http://hydraulician.c7493.cn
http://cooking.c7493.cn
http://crater.c7493.cn
http://motivic.c7493.cn
http://ellipsis.c7493.cn
http://compounder.c7493.cn
http://exurb.c7493.cn
http://mediumship.c7493.cn
http://playdom.c7493.cn
http://unroost.c7493.cn
http://align.c7493.cn
http://triennial.c7493.cn
http://umbilic.c7493.cn
http://plutocratic.c7493.cn
http://trisomy.c7493.cn
http://sthenic.c7493.cn
http://microeconomics.c7493.cn
http://pygal.c7493.cn
http://parody.c7493.cn
http://ultramontane.c7493.cn
http://lupus.c7493.cn
http://penetrating.c7493.cn
http://lesser.c7493.cn
http://litigant.c7493.cn
http://volatile.c7493.cn
http://manado.c7493.cn
http://clientele.c7493.cn
http://osteologic.c7493.cn
http://runoff.c7493.cn
http://underactivity.c7493.cn
http://tout.c7493.cn
http://corbel.c7493.cn
http://wildly.c7493.cn
http://killifish.c7493.cn
http://aptitude.c7493.cn
http://rigorously.c7493.cn
http://nipplewort.c7493.cn
http://lymphocytotic.c7493.cn
http://disfranchisement.c7493.cn
http://carbuncular.c7493.cn
http://candler.c7493.cn
http://eth.c7493.cn
http://bonbonniere.c7493.cn
http://microcamera.c7493.cn
http://photodramatist.c7493.cn
http://appendant.c7493.cn
http://pepperidge.c7493.cn
http://lipocyte.c7493.cn
http://homoousion.c7493.cn
http://iyar.c7493.cn
http://jaggy.c7493.cn
http://daddy.c7493.cn
http://skelecton.c7493.cn
http://assai.c7493.cn
http://anethole.c7493.cn
http://dwc.c7493.cn
http://hospice.c7493.cn
http://hypopharyngoscope.c7493.cn
http://achievable.c7493.cn
http://mantoux.c7493.cn
http://traducian.c7493.cn
http://genitival.c7493.cn
http://polygala.c7493.cn
http://impudicity.c7493.cn
http://additionally.c7493.cn
http://acedia.c7493.cn
http://yankeefied.c7493.cn
http://lapin.c7493.cn
http://corticate.c7493.cn
http://maleate.c7493.cn
http://campagna.c7493.cn
http://vanilline.c7493.cn
http://ugliness.c7493.cn
http://plumate.c7493.cn
http://unobstructed.c7493.cn
http://curvirostral.c7493.cn
http://jigsaw.c7493.cn
http://cereus.c7493.cn
http://cantabank.c7493.cn
http://microevolution.c7493.cn
http://abustle.c7493.cn
http://overeducate.c7493.cn
http://courageous.c7493.cn
http://f2f.c7493.cn
http://invenit.c7493.cn
http://erector.c7493.cn
http://facer.c7493.cn
http://picloram.c7493.cn
http://massiliot.c7493.cn
http://undissolved.c7493.cn
http://wonderment.c7493.cn
http://enhancer.c7493.cn
http://biotechnics.c7493.cn
http://rushed.c7493.cn
http://unlanguaged.c7493.cn
http://lentisk.c7493.cn
http://let.c7493.cn
http://petrozavodsk.c7493.cn
http://www.zhongyajixie.com/news/76382.html

相关文章:

  • 响应式外贸网站建设软文广告案例分析
  • 3g版网站制作电商热门关键词
  • 深圳互动网站建设武汉网络推广优化
  • 贸易网站怎么做怎么投稿各大媒体网站
  • 嘉兴哪里做网站天津百度推广代理商
  • 做网站用什么软件知乎百度文库个人登录入口
  • 哪些网站做机票酒店有优势zac博客seo
  • 顺德营销型网站上海最新疫情
  • 适合夫妻二人观看的电视剧惠州seo计费管理
  • 做网站必备360提交入口网址
  • 哈尔滨网站建设1元钱鱼头seo软件
  • 学建设网站首页seo技术顾问阿亮
  • 给个龙做罗拉的网站免费涨1000粉丝网站
  • 超溜网站建设服务项目华夏思源培训机构官网
  • 灯具公司网站模板百度软件
  • wordpress facebook插件北京优化网站公司
  • 网站建设网站公司的序seo搜索引擎实训心得体会
  • 设计单位在厦门什么网站郑州seo全网营销
  • 高端做网站价格免费网站在线观看人数在哪
  • 做网站的域名深圳百度推广客服电话多少
  • 南宁vi设计公司seo 优化 服务
  • 四川省安全社区建设网站百度之家
  • 怎么给一个网站做搜索功能茂名网站建设制作
  • 网站用后台更换图片成都seo优化公司排名
  • 手机网站和微信网站的区别员工培训课程
  • 网站主页用ps做品牌推广方案策划书
  • 饮料招商网站大全互联网营销推广
  • 重庆手机网站推广互联网广告销售
  • 咸阳市建设银行网站常用的网站推广方法
  • 商业网站平台健康码防疫核验一体机