欧美一区二区三区老妇人-欧美做爰猛烈大尺度电-99久久夜色精品国产亚洲a-亚洲福利视频一区二区

C語(yǔ)言怎么實(shí)現(xiàn)簡(jiǎn)單掃雷游戲

這篇文章主要講解了“C語(yǔ)言怎么實(shí)現(xiàn)簡(jiǎn)單掃雷游戲”,文中的講解內(nèi)容簡(jiǎn)單清晰,易于學(xué)習(xí)與理解,下面請(qǐng)大家跟著小編的思路慢慢深入,一起來(lái)研究和學(xué)習(xí)“C語(yǔ)言怎么實(shí)現(xiàn)簡(jiǎn)單掃雷游戲”吧!

10余年建站經(jīng)驗(yàn), 成都網(wǎng)站設(shè)計(jì)、網(wǎng)站制作、外貿(mào)營(yíng)銷網(wǎng)站建設(shè)客戶的見證與正確選擇。成都創(chuàng)新互聯(lián)公司提供完善的營(yíng)銷型網(wǎng)頁(yè)建站明細(xì)報(bào)價(jià)表。后期開發(fā)更加便捷高效,我們致力于追求更美、更快、更規(guī)范。

本文指的掃雷是簡(jiǎn)單模擬電腦中的掃雷游戲,但以我目前的水平,也就只能在黑框中實(shí)現(xiàn)

test.c

#include<stdio.h>#include<stdlib.h>#include<time.h>#include "game2.h"  void menu(){ printf("********* welcome ********\n"); printf("**********1.play**********\n"); printf("**********0.exit**********\n");}enum Option{ EXIT, PLAY}; void game(){ int x = 0; int y = 0; int i = 0; int win = 0; char mine[ROWS + 2][COLS + 2] = { 0 }; char show[ROWS + 2][ROWS + 2] = { 0 }; init_board(mine, ROWS + 2, COLS + 2, '0'); init_board(show, ROWS + 2, COLS + 2, '*'); //display(mine, ROWS + 2, COLS + 2);#define _CRT_SECURE_NO_WARNINGS //display(show, ROWS + 2, COLS + 2); mine_set(mine, ROWS + 2, COLS + 2); display(mine, ROWS + 2, COLS + 2); while (win<ROWS*COLS - DEFAULT_COUNT) { for (i = 0; i <= win; i++) { printf("請(qǐng)輸入坐標(biāo):>"); scanf("%d%d", &x, &y); //合法性判斷  if ((x>0) && (x <= ROWS) && (y > 0) && (y <= COLS))  {  if ((i == 0) && (mine[x][y] == '1'))  {   (mine[x][y] = '0') ;  }  if (mine[x][y] == '1')  {   printf("很遺憾,你被炸死了\n");   break;  }  else  {   int count = 0;   win++;   count = get_mine_num(mine, x, y);   show[x][y] = count + '0';   display(show, ROWS + 2, COLS + 2);  }  }  else  {  printf("輸入錯(cuò)誤請(qǐng)重新輸入\n");  } } if (win >= ROWS*COLS - DEFAULT_COUNT) {  printf("恭喜你,掃雷成功\n"); } }}int main(){ int input = 0; srand((uint_t)time(NULL)); do { menu(); printf("請(qǐng)選擇:>"); scanf("%d", &input); switch (input) { case PLAY:   game();  break; case EXIT:  break; default:  printf("輸入錯(cuò)誤,請(qǐng)重新輸入\n");  break; } } while (input); system("pause\n"); return 0;}

game.c

#define _CRT_SECURE_NO_WARNINGS 1#include "game2.h"#include<stdlib.h>#include<stdio.h>#include<string.h> void init_board(char arr[ROWS + 2][COLS + 2], int row, int col,char ch){ memset(arr, ch, sizeof(char) * row * col);}void display(char arr[ROWS + 2][COLS + 2], int row, int col){ int i = 0; int j = 0; printf("  "); for (i = 0; i < col - 2; i++) { printf("%d ", i + 1); } printf("\n"); for (i = 0; i < row - 2; i++) { printf("%2d ", i + 1); for (j = 0; j < col - 2; j++) {  printf("%c ", arr[i + 1][j + 1]); } printf("\n"); }}void mine_set(char arr[ROWS + 2][COLS + 2], int row, int col){ int x = 0; int y = 0; int count = DEFAULT_COUNT; while (count) { x = rand() % 10 + 1; y = rand() % 10 + 1; if (arr[x][y] != '1') {  arr[x][y] = '1';  count--; } }}int get_mine_num(char arr[ROWS + 2][COLS + 2], int x, int y){ return (arr[x][y - 1] - '0') +   (arr[x - 1][y - 1]-'0')- +   (arr[x - 1][y]-'0') +   (arr[x - 1][y + 1]-'0') +   (arr[x][y + 1]-'0') +   (arr[x + 1][y + 1]-'0') +   (arr[x + 1][y]-'0') +   (arr[x + 1][y - 1]-'0');//返回周圍雷的個(gè)數(shù)}

game.h

#ifndef __GAME_H__#define __GAME_H__ #define ROWS 10#define COLS 10#define DEFAULT_COUNT 20typedef unsigned int uint_t;//類型重命名 #include<string.h>#include<stdio.h>#include<time.h>#include<stdlib.h> void init_board(char arr[ROWS + 2][COLS + 2], int row, int col,char ch);//初始化void display(char arr[ROWS + 2][COLS + 2], int row, int col);void mine_set(char arr[ROWS + 2][COLS + 2], int row, int col);//放雷int get_mine_num(char arr[ROWS + 2][COLS + 2], int row, int col);//統(tǒng)計(jì)坐標(biāo)周圍雷的個(gè)數(shù)  #endif //__GAME_H__

感謝各位的閱讀,以上就是“C語(yǔ)言怎么實(shí)現(xiàn)簡(jiǎn)單掃雷游戲”的內(nèi)容了,經(jīng)過(guò)本文的學(xué)習(xí)后,相信大家對(duì)C語(yǔ)言怎么實(shí)現(xiàn)簡(jiǎn)單掃雷游戲這一問(wèn)題有了更深刻的體會(huì),具體使用情況還需要大家實(shí)踐驗(yàn)證。這里是創(chuàng)新互聯(lián),小編將為大家推送更多相關(guān)知識(shí)點(diǎn)的文章,歡迎關(guān)注!

名稱欄目:C語(yǔ)言怎么實(shí)現(xiàn)簡(jiǎn)單掃雷游戲
鏈接URL:http://chinadenli.net/article34/gojspe.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供服務(wù)器托管網(wǎng)站設(shè)計(jì)公司微信公眾號(hào)靜態(tài)網(wǎng)站全網(wǎng)營(yíng)銷推廣ChatGPT

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)

成都網(wǎng)站建設(shè)