小遊戲 掃雷

2021-07-30 10:04:16 字數 2279 閱讀 1048

c語言實現的乙個簡單的掃雷遊戲:

介面簡單,功能:首次踩雷的,會換雷。掃雷有九宮格擴撒

環境:vs2015 **如下:

game.h

#pragma once

#ifndef __game_h__

#define __game_h__

#define rows 11

#define cols 11

#define num (9)

#include #include #include #include void build_mine(char mine[rows][cols], int row, int col); //布雷

void show_mine(char mine[rows][cols], int row, int col); //雷陣封裝顯示

int clean_mine(char mine[rows][cols], char board[rows][cols], int row, int col, int count);//掃雷

void move(char mine[rows][cols], int row, int col); //首次移雷

void big_board(char mine[rows][cols], char board[rows][cols],int x, int y); //掃雷擴散,顯示玩家概率雷陣

int num_mine(char mine[rows][cols], int x, int y); //雷區概率

int jude_win(char board[rows][cols], int row, int col);//判斷成功

int get_random_num(int m, int n);

#endif //__game_h__

game.c

#define _crt_secure_no_warnings 1

#include "game.h"

void build_mine(char mine[rows][cols], int row, int col) //布雷 }}

void show_mine(char mine[rows][cols], int row, int col) //雷陣封裝顯示

printf("\n");

for (i = 1; i < row - 1; i++)

printf("\n"); }}

int clean_mine(char mine[rows][cols], char board[rows][cols], int row, int col, int count)//掃雷

else if ((mine[x][y] == '1') && (count == 1))

else if((count != 1)&& (mine[x][y] == '1'))

} else

if (jude_win(board,rows,cols))//判斷掃雷成功

//else show_mine(board, rows, cols);//玩家雷陣封裝顯示

return 2;

}void move(char mine[rows][cols], int x, int y) //首次移雷

else goto ret2;

}void big_board(char mine[rows][cols], char board[rows][cols], int x, int y) //掃雷擴散,顯示玩家概率雷陣

int num_mine(char mine[rows][cols], int x, int y) //雷區概率

int jude_win(char board[rows][cols], int row, int col) //判斷成功

} if (c == num + 1)

return 1;

return 0;

}

test,c

#define _crt_secure_no_warnings 1

#include "game.h"

void menu()

void game()

} while (jud);

}enum option //列舉

;int main()

} while (input);

return 0;

}

小遊戲 掃雷

實現乙個掃雷遊戲 1.設定兩個陣列 mine row col 表示布雷,show row col 顯示掃雷情況 顯示周圍有幾個雷 因為統計四周,邊緣位置不好實現,所以把二維陣列的行和列都加二,這樣無論是否在邊緣都可以當做一種情況來實現。2.初始化mine和show,show mine 0 3.set...

掃雷小遊戲

game.h 標頭檔案 ifndef game h define game h include include include include define row 12 define col 12 define count 10 棋盤中雷的總數 extern char show mine row ...

掃雷小遊戲

include include include include include define rows 11 行數 define cols 11 列數 define leicount 10 雷數 int dir 8 2 int menu 選單函式 void display char show row...