//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "Unit1.h"
#include <iostream.h>
#include <stdlib.h>
#include <time.h>
using namespace std;
//---------------------------------------------------------------------------
#pragma package(smart_init)
void BuLei(); // 布雷
void ClearBomb(); // 输入下标(横轴坐标和纵轴坐标)
void Result(int i, int j); // 判断输入的结果
void Welcome();
char unit[10][10];
char tempUnit[10][10];
char bomb;
int leiNum; // 雷的个数
int main()
{
bomb = '#';
leiNum = 20;
Welcome();
system("pause");
return 0;
}
void Welcome()
{
cout << endl;
cout << " ************************************\n";
cout << " ************ 扫雷 ************\n";
cout << " ************************************\n";
cout << " ************ 0 进入游戏 ************\n";
cout << " ************ ************\n";
cout << " ************ 1 退出游戏 ************\n";
cout << " ************************************\n";
cout << " *********************作者:海豚天使*\n";
cout << " ************************************\n";
int choice;
cin >> choice;
switch (choice)
{
case 0 :
BuLei();
break;
case 1 :
system("pause");
break;
default :
cout << "请正确操作!" << endl;
break;
}
}
void BuLei()
{
int i,j,x,y;
for (i = 0; i < 10; i++)
{
for (j = 0; j < 10; j++)
{
unit[i][j] = '0';
tempUnit[i][j] = '0';
}
}
srand(time(NULL));
for (int lei = 0; lei < leiNum; lei++)
{
i = rand()%10;
j = rand()%10;
if (unit[i][j]!=bomb)
{
unit[i][j] = bomb; // 随机布雷
}
else
{
continue;
}
}
for (i = 0; i < 10; i++)
{
for (j = 0; j < 10; j++)
{
if (unit[i][j]==bomb)
{
if (i > 0 && i < 9 )
{
if (j > 0 && j < 9)
{
if (unit[i-1][j-1]!=bomb)
{
unit[i-1][j-1] += 1;
}
if(unit[i-1][j]!=bomb)
{
unit[i-1][j] += 1;
}
if (unit[i-1][j+1]!=bomb)
{
unit[i-1][j+1] += 1;
}
if (unit[i][j-1]!=bomb)
{
unit[i][j-1] += 1;
}
if (unit[i][j+1]!=bomb)
{
unit[i][j+1] += 1;
}
if (unit[i+1][j-1]!=bomb)
{
unit[i+1][j-1] += 1;
}
if (unit[i+1][j]!=bomb)
{
unit[i+1][j] += 1;
}
if (unit[i+1][j+1]!=bomb)
{
unit[i+1][j+1] += 1;
}
}
else if (j == 0)
{
if(unit[i-1][0]!=bomb)
{
unit[i-1][0] += 1;
}
if (unit[i-1][1]!=bomb)
{
unit[i-1][1] += 1;
}
if (unit[i][1]!=bomb)
{
unit[i][1] += 1;
}
if (unit[i+1][0]!=bomb)
{
unit[i+1][0] += 1;
}
if (unit[i+1][1]!=bomb)
{
unit[i+1][1] += 1;
}
}
else if (j == 9)
{
if (unit[i-1][8]!=bomb)
{
unit[i-1][8] += 1;
}
if (unit[i-1][9]!=bomb)
{
unit[i-1][9] += 1;
}
if (unit[i][8]!=bomb)
{
unit[i][8] += 1;
}
if (unit[i+1][8]!=bomb)
{
unit[i+1][8] += 1;
}
if (unit[i+1][9]!=bomb)
{
unit[i+1][9] += 1;
}
}
}
else if (i==0)
{
if (j == 0)
{
if(unit[0][1]!=bomb)
{
unit[0][1] += 1;
}
if(unit[1][0]!=bomb)
{
unit[1][0] += 1;
}
if(unit[1][1]!=bomb)
{
unit[1][1] += 1;
}
}
else if (j == 9)
{
if(unit[0][8]!=bomb)
{
unit[0][8] += 1;
}
if(unit[1][8]!=bomb)
{
unit[1][8] += 1;
}
if(unit[1][9]!=bomb)
{
unit[1][9] += 1;
}
}
else
{
if(unit[0][j-1]!=bomb)
{
unit[0][j-1] += 1;
}
if(unit[0][j+1]!=bomb)
{
unit[0][j+1] += 1;
}
if(unit[1][j-1]!=bomb)
{
unit[1][j-1] += 1;
}
if(unit[1][j]!=bomb)
{
unit[1][j] += 1;
}
if(unit[1][j+1]!=bomb)
{
unit[1][j+1] += 1;
}
}
}
else if (i==9)
{
if (j == 0)
{
if(unit[8][0]!=bomb)
{
unit[8][0] += 1;
}
if(unit[8][1]!=bomb)
{
unit[8][1] += 1;
}
if(unit[9][1]!=bomb)
{
unit[9][1] += 1;
}
}
else if (j==9)
{
if(unit[8][8]!=bomb)
{
unit[8][8] += 1;
}
if(unit[8][9]!=bomb)
{