<来玩啊>扫雷游戏
来源:互联网 发布:unity3d 视频教程 编辑:程序博客网 时间:2024/06/10 15:44
猜数字游戏:
http://blog.csdn.net/romantic_c/article/details/78135924
三子棋:
http://blog.csdn.net/romantic_c/article/details/78311056
关机程序:
http://blog.csdn.net/romantic_c/article/details/78093507
头文件
#ifndef __GAME_H__#define __GAME_H__#include <stdio.h>#include <stdlib.h>#include <string.h>#include <time.h>#define ROWS 11#define COLS 11#define COUNT 10void init_game(char mine[ROWS][COLS],char show[ROWS][COLS]); //初始化扫雷界面void set_mine(char mine[ROWS][COLS]); //设置雷区void display(char show[ROWS][COLS]); //打印出界面void sweep(char mine[ROWS][COLS], char show[ROWS][COLS]); //开始扫雷int get_mine(char mine[ROWS][COLS], int x, int y); //附近雷的个数#endif//__GAME_H__
源文件
#include "game.h"void init_game(char mine[ROWS][COLS],char show[ROWS][COLS])//初始化扫雷界面{ int i=0; int j=0; for(i=0;i<ROWS;i++) { for(j=0;j<COLS;j++) { mine[i][j]='0'; show[i][j]='*'; } }}void display(char show[ROWS][COLS]) //打印出界面{ int i = 0; int j = 0; printf(" "); for (i = 1; i < COLS - 1; i++) { printf(" %d ", i); } printf("\n"); for (i = 1; i < ROWS - 1; i++) { printf("%d", i); for (j = 1; j < COLS - 1; j++) { printf(" %c ", show[i][j]); } printf("\n"); }}void set_mine(char mine[ROWS][COLS]) //设置雷区{ int count = COUNT; int x = 0; int y = 0; srand((unsigned)time(NULL)); while (count) { x = rand()%9+1; y = rand()%9+1; if (mine[x][y] == '0') { mine[x][y] = '1'; count--; } }}int get_mine(char mine[ROWS][COLS], int x, int y) //附近雷的个数{ int count = 0; if (mine[x - 1][y - 1] == '1') count++; //坐标位置的上3个 if (mine[x - 1][y] == '1') count++; if (mine[x - 1][y + 1] == '1') count++; if (mine[x][y - 1] == '1') count++; //坐标位置的左右 if (mine[x][y + 1] == '1') count++; if (mine[x + 1][y - 1] == '1') count++; //坐标位置的下3个 if (mine[x + 1][y] == '1') count++; if (mine[x + 1][y + 1] == '1') count++; return count;}void sweep(char mine[ROWS][COLS], char show[ROWS][COLS])//开始扫雷{ int count = 0; int x = 0; int y = 0; while(count!=((ROWS-2)*(COLS-2)-COUNT)) { printf("\n"); printf("请输入坐标>:"); scanf("%d%d", &x, &y); if (mine[x][y] == '1') { printf("踩雷了!\n"); display(mine); return; } else { int ret = get_mine(mine, x, y); show[x][y] = ret + '0'; printf("\n"); display(show); count++; } } printf("恭喜你赢了!\n"); display(mine);}#include <stdio.h>#include <windows.h>#include <stdlib.h>#include <time.h>#include "game.h"void game()//游戏函数{ char mine[ROWS][COLS]; char show[ROWS][COLS]; srand((unsigned)time(NULL)); init_game(mine, show); display(show); set_mine(mine); sweep(mine, show);}void menu()//菜单函数{ printf("-------------------------\n"); printf("--------- 1.play --------\n"); printf("--------- 0.exit --------\n"); printf("-------------------------\n");}int main(){ int input=0; int i=0; do { if(i!=0) { Sleep(5000);//延迟 } system("cls");//清屏 i=1; menu(); printf("请选择>:"); scanf("%d",&input); switch(input) { case 1:game(); break; case 0: break; default: printf("选择错误,请重新选择\n"); i=0; break; } } while(input); return 0;}
阅读全文
0 0
- <来玩啊>扫雷游戏
- 扫雷游戏
- 扫雷游戏
- 扫雷游戏
- 扫雷游戏
- 扫雷游戏
- 扫雷游戏
- 扫雷游戏
- 扫雷游戏
- 扫雷游戏
- 扫雷游戏
- 扫雷游戏
- 扫雷游戏
- 扫雷游戏
- 扫雷游戏
- 扫雷游戏
- 扫雷游戏
- 扫雷游戏
- LuoguP1311[NOIP2011] 选择客栈 解题报告【前缀和+枚举(?)】
- sdnu1046选拔赛
- 51nod 1014 X^2 Mod P【暴力】
- 某小公司RESTful、共用接口、前后端分离、接口约定的实践
- 欢迎使用CSDN-markdown编辑器
- <来玩啊>扫雷游戏
- Java多线程系列(九)—CountDownLatch源码分析
- vnc setup
- 本地缓存GuavaCache
- 用栈和队列实现魔王语言
- java 向上转型和向下转型
- 【Java-集合】HashMap-Hash冲突解决
- C++ static
- 股票量化分析(12)——第三个策略(kdj策略)