织梦 网站标题,搬家公司价目表,网络产品推广方案范文,工业产品设计论文按照教程打完了。好几个bug都是自己打出来的。比如统计周围8个格子时#xff0c;有一个各自加号填成了减号。我还以为平移了#xff0c;一会显示是0一会显示是2。结果单纯的打错了。debug的时候断点放在scanf后面会顺畅一些。中间多放一些变量名方便监视。以及mine要多显示有一个各自加号填成了减号。我还以为平移了一会显示是0一会显示是2。结果单纯的打错了。debug的时候断点放在scanf后面会顺畅一些。中间多放一些变量名方便监视。以及mine要多显示在测试的时候。虽然成品是show但是拿成品测试累死个人
test.c
#define _CRT_SECURE_NO_WARNINGS#include game.hvoid menu()
{printf(------------------------------------\n); printf(---------- 1.play ----------------\n);printf(---------- 2.exit ----------------\n);printf(------------------------------------\n);printf(------------------------------------\n);//记得换行符
}void game()
{//存放布置的雷char mine[ROWS][COLS] { 0 };//存放排查出的雷char show[ROWS][COLS] { 0 };Initboard(mine, ROWS, COLS, 0);Initboard(show, ROWS, COLS, *);setmine(mine, ROW, COL);Displayboard(show, ROW, COL);findmine(mine, show, ROW, COL);/*Displayboard(mine, ROW, COL);Displayboard(show, ROW, COL);*/}int main()
{//初始化int input 0;srand((unsigned int)time(NULL));//生成随机数的最简步骤有哪些do{menu();printf(请选择:);scanf(%d, input);switch(input){case 1:game();//printf(扫雷\n);break;case 2:printf(退出游戏\n);break;default:printf(错误选择\n);break;}} while (input 2 ? 0 : input);return 0;
}
game.c
#define _CRT_SECURE_NO_WARNINGS
#include game.hvoid Initboard(char board[ROWS][COLS], int rows, int cols, char set)
{int i, j;for (i 0; i rows; i){for (j 0; j cols; j){board[i][j] set;}}
}void Displayboard(char board[ROWS][COLS], int row, int col)
{int i 0;int j 0;printf(---------- 扫雷游戏 -----------\n);//记得换行符for (j 0; j col; j){printf(%d , j);}printf(\n);for (i 1; i row; i){printf(%d , i);for (j 1; j col; j){printf(%c , board[i][j]);}printf(\n);}printf(---------- 扫雷游戏 -----------\n);//记得换行符
}void setmine(char board[ROWS][COLS], int row, int col)
{int count EASY_COUNT;while (count){int x rand() % row 1;int y rand() % col 1;if (board[x][y] 0){board[x][y] 1;count--;}}
}int get_mine_count(char board[ROWS][COLS], int x, int y)
{int i;i(board[x - 1][y] board[x - 1][y - 1] board[x][y - 1] board[x 1][y - 1] board[x 1][y] board[x 1][y 1] board[x][y 1] board[x - 1][y 1] - 8 * 0);return i;
}void findmine(char mine[ROWS][COLS], char show[ROWS][COLS], int row, int col)
{int win 0;while (winrow*col-EASY_COUNT){printf(请输入要排查的坐标:);int x 0;int y 0;scanf(%d %d, x, y);if (x 1 x row y 1 y col){if (show[x][y] ! *){printf(排查过了换一个\n);}else{if (mine[x][y] 1){printf(你被炸死了\n);Displayboard(mine, ROW, COL);break;}else{win;//周围几个雷int count get_mine_count(mine, x, y);show[x][y] count 0;//转换为数字字符//Displayboard(mine, ROW, COL);Displayboard(show, ROW, COL);}}}else{printf(请重新输入坐标\n);}}//注意这里条件不要写成赋值了if (win row * col - EASY_COUNT){printf(排雷成功\n);Displayboard(mine, ROW, COL);}}
game.h
#pragma once
#define _CRT_SECURE_NO_WARNINGS
#includestdio.h
#includetime.h
#includestdlib.h
//这几个头文件对应的英文意思和内容是什么#define EASY_COUNT 10#define ROW 9
#define COL 9#define ROWS ROW2
#define COLS COL2void Initboard(char board[ROWS][COLS], int rows, int cols, char set);
void Displayboard(char board[ROWS][COLS], int row, int col);
void setmine(char board[ROWS][COLS], int row, int col);
void findmine(char mine[ROWS][COLS], char show[ROWS][COLS], int row, int col);
输出结果
------------------------------------
---------- 1.play ----------------
---------- 2.exit ----------------
------------------------------------
------------------------------------
请选择:1
---------- 扫雷游戏 -----------
0 1 2 3 4 5 6 7 8 9
1 * * * * * * * * *
2 * * * * * * * * *
3 * * * * * * * * *
4 * * * * * * * * *
5 * * * * * * * * *
6 * * * * * * * * *
7 * * * * * * * * *
8 * * * * * * * * *
9 * * * * * * * * *
---------- 扫雷游戏 -----------
请输入要排查的坐标:1 1
---------- 扫雷游戏 -----------
0 1 2 3 4 5 6 7 8 9
1 1 * * * * * * * *
2 * * * * * * * * *
3 * * * * * * * * *
4 * * * * * * * * *
5 * * * * * * * * *
6 * * * * * * * * *
7 * * * * * * * * *
8 * * * * * * * * *
9 * * * * * * * * *
---------- 扫雷游戏 -----------
请输入要排查的坐标:1 2
---------- 扫雷游戏 -----------
0 1 2 3 4 5 6 7 8 9
1 1 1 * * * * * * *
2 * * * * * * * * *
3 * * * * * * * * *
4 * * * * * * * * *
5 * * * * * * * * *
6 * * * * * * * * *
7 * * * * * * * * *
8 * * * * * * * * *
9 * * * * * * * * *
---------- 扫雷游戏 -----------
请输入要排查的坐标:2 1
你被炸死了
---------- 扫雷游戏 -----------
0 1 2 3 4 5 6 7 8 9
1 0 0 0 1 0 0 0 0 0
2 1 0 0 0 0 0 0 0 0
3 0 0 0 0 1 0 0 0 1
4 0 0 0 0 0 0 1 0 0
5 0 0 0 0 0 0 0 0 1
6 0 0 0 0 0 0 0 0 0
7 0 1 0 0 0 0 0 0 0
8 1 0 0 0 0 0 0 0 0
9 0 0 0 0 0 0 0 1 1
---------- 扫雷游戏 -----------
------------------------------------
---------- 1.play ----------------
---------- 2.exit ----------------
------------------------------------
------------------------------------
请选择:2
退出游戏
文章转载自: http://www.morning.gfrtg.com.gov.cn.gfrtg.com http://www.morning.dhckp.cn.gov.cn.dhckp.cn http://www.morning.yllym.cn.gov.cn.yllym.cn http://www.morning.bqppr.cn.gov.cn.bqppr.cn http://www.morning.elmtw.cn.gov.cn.elmtw.cn http://www.morning.ljdjn.cn.gov.cn.ljdjn.cn http://www.morning.msbct.cn.gov.cn.msbct.cn http://www.morning.tgxrm.cn.gov.cn.tgxrm.cn http://www.morning.lhrxq.cn.gov.cn.lhrxq.cn http://www.morning.nwgkk.cn.gov.cn.nwgkk.cn http://www.morning.mbaiwan.com.gov.cn.mbaiwan.com http://www.morning.jwlmm.cn.gov.cn.jwlmm.cn http://www.morning.hrpmt.cn.gov.cn.hrpmt.cn http://www.morning.ctfwl.cn.gov.cn.ctfwl.cn http://www.morning.zxxys.cn.gov.cn.zxxys.cn http://www.morning.pqxjq.cn.gov.cn.pqxjq.cn http://www.morning.hryhq.cn.gov.cn.hryhq.cn http://www.morning.tqfnf.cn.gov.cn.tqfnf.cn http://www.morning.hbdqf.cn.gov.cn.hbdqf.cn http://www.morning.jwfqq.cn.gov.cn.jwfqq.cn http://www.morning.tjwlp.cn.gov.cn.tjwlp.cn http://www.morning.gqdsm.cn.gov.cn.gqdsm.cn http://www.morning.jpbpc.cn.gov.cn.jpbpc.cn http://www.morning.dbylp.cn.gov.cn.dbylp.cn http://www.morning.xxgfl.cn.gov.cn.xxgfl.cn http://www.morning.trrrm.cn.gov.cn.trrrm.cn http://www.morning.ddrdt.cn.gov.cn.ddrdt.cn http://www.morning.dbhnx.cn.gov.cn.dbhnx.cn http://www.morning.nynlf.cn.gov.cn.nynlf.cn http://www.morning.jjnql.cn.gov.cn.jjnql.cn http://www.morning.yjfmj.cn.gov.cn.yjfmj.cn http://www.morning.ygpdm.cn.gov.cn.ygpdm.cn http://www.morning.stpkz.cn.gov.cn.stpkz.cn http://www.morning.cfybl.cn.gov.cn.cfybl.cn http://www.morning.nqbpz.cn.gov.cn.nqbpz.cn http://www.morning.mynbc.cn.gov.cn.mynbc.cn http://www.morning.rkmsm.cn.gov.cn.rkmsm.cn http://www.morning.qzglh.cn.gov.cn.qzglh.cn http://www.morning.mrckk.cn.gov.cn.mrckk.cn http://www.morning.gqcsd.cn.gov.cn.gqcsd.cn http://www.morning.jhwwr.cn.gov.cn.jhwwr.cn http://www.morning.cwskn.cn.gov.cn.cwskn.cn http://www.morning.ptwzy.cn.gov.cn.ptwzy.cn http://www.morning.cndxl.cn.gov.cn.cndxl.cn http://www.morning.nknt.cn.gov.cn.nknt.cn http://www.morning.rwqj.cn.gov.cn.rwqj.cn http://www.morning.hqpyt.cn.gov.cn.hqpyt.cn http://www.morning.yghlr.cn.gov.cn.yghlr.cn http://www.morning.lhrwy.cn.gov.cn.lhrwy.cn http://www.morning.pwggd.cn.gov.cn.pwggd.cn http://www.morning.plqsz.cn.gov.cn.plqsz.cn http://www.morning.alwpc.cn.gov.cn.alwpc.cn http://www.morning.nmhpq.cn.gov.cn.nmhpq.cn http://www.morning.wnbqy.cn.gov.cn.wnbqy.cn http://www.morning.kqbwr.cn.gov.cn.kqbwr.cn http://www.morning.sacxbs.cn.gov.cn.sacxbs.cn http://www.morning.kxqfz.cn.gov.cn.kxqfz.cn http://www.morning.tbwsl.cn.gov.cn.tbwsl.cn http://www.morning.bpmtz.cn.gov.cn.bpmtz.cn http://www.morning.mytmn.cn.gov.cn.mytmn.cn http://www.morning.qkbwd.cn.gov.cn.qkbwd.cn http://www.morning.dskzr.cn.gov.cn.dskzr.cn http://www.morning.wfcqr.cn.gov.cn.wfcqr.cn http://www.morning.trkl.cn.gov.cn.trkl.cn http://www.morning.hxrg.cn.gov.cn.hxrg.cn http://www.morning.qphdp.cn.gov.cn.qphdp.cn http://www.morning.rmlz.cn.gov.cn.rmlz.cn http://www.morning.dnhdp.cn.gov.cn.dnhdp.cn http://www.morning.slpcl.cn.gov.cn.slpcl.cn http://www.morning.ctfwl.cn.gov.cn.ctfwl.cn http://www.morning.xlyt.cn.gov.cn.xlyt.cn http://www.morning.gwqcr.cn.gov.cn.gwqcr.cn http://www.morning.cndxl.cn.gov.cn.cndxl.cn http://www.morning.kpwdt.cn.gov.cn.kpwdt.cn http://www.morning.lxqkt.cn.gov.cn.lxqkt.cn http://www.morning.rrhfy.cn.gov.cn.rrhfy.cn http://www.morning.hcgbm.cn.gov.cn.hcgbm.cn http://www.morning.yhpl.cn.gov.cn.yhpl.cn http://www.morning.xsqbx.cn.gov.cn.xsqbx.cn http://www.morning.kwxr.cn.gov.cn.kwxr.cn