码迷,mamicode.com
首页 > 编程语言 > 详细

C++ 扫雷

时间:2016-04-09 01:35:54      阅读:254      评论:0      收藏:0      [点我收藏+]

标签:

还有些问题没有调试出!明天继续!!

 1 #include<iostream>
 2 #include<stdlib.h>
 3 #include<time.h>
 4 #include<stdio.h>
 5 using namespace std;
 6 
 7 int count = 9;//The number of bomb
 8 int x,y=0;
 9 int disbomb[11][11];//Bomb area
10 
11 void makebomb(){
12     srand((int)time(0));
13     while(count>0){
14         int x=(int)rand()%8+1;
15         int y=(int)rand()%8+1;
16             if(disbomb[x][y]!=1){
17                 disbomb[x][y]=9;
18                 count--;
19             }
20     }
21 }
22 void countbomb(){
23     for(int i=1;i<10;i++){
24         for(int j=1;j<10;j++){
25             //问题:每个数值都不为9
26             if(disbomb[x][y]!=9){//如果不是炸弹,则赋值为周围炸弹的个数和
27                 if(disbomb[x-1][y-1]==9) disbomb[x][y]+=1;
28                 if(disbomb[x][y-1]==9) disbomb[x][y]+=1;
29                 if(disbomb[x+1][y-1]==9) disbomb[x][y]+=1;
30 
31                 if(disbomb[x-1][y]==9) disbomb[x][y]+=1;
32                 if(disbomb[x+1][y]==9) disbomb[x][y]+=1;
33 
34                 if(disbomb[x-1][y+1]==9) disbomb[x][y]+=1;
35                 if(disbomb[x][y+1]==9) disbomb[x][y]+=1;
36                 if(disbomb[x+1][y+1]==9) disbomb[x][y]+=1;
37                 //测试
38                 //cout << disbomb[x][y] <<endl;
39             }
40         }
41     }
42 }
43 void Printbomb(){
44     for(int i=0;i<9;i++){
45         for(int j=0;j<9;j++){
46             cout << disbomb[i][j] <<" ";
47         }
48         cout << endl;
49     }
50 }
51 int main(){
52     printf("***************************\n");
53     printf("***********扫雷************\n");
54     printf("******author:lixiaopeng****\n");
55     printf("***************************\n");
56     for(int i=1;i<10;i++){
57             for(int j=1;j<10;j++){
58                 disbomb[i][j]=0;
59                 printf("%d ",disbomb[i][j]);
60             }
61             printf("\n");
62         }
63     makebomb();
64     countbomb();
65     cout << endl;
66     Printbomb();
67     bool flag=1;
68     while(flag)
69     {
70         printf("输入你开启的坐标:x,y\n");
71         scanf("%d%d",&x,&y);
72         if(disbomb[x][y]!=9){
73             cout<< disbomb[x][y];
74         }
75         else{
76             printf("sorry,game over\n");
77         }
78     }
79 
80 }

 

C++ 扫雷

标签:

原文地址:http://www.cnblogs.com/lixiaopengcc/p/5370475.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!