扫雷游戏
OftenSendACat · · 个人记录
纯自制扫雷游戏,没有参考任何其他的东西
实际上早就做出来了,但是怕被抄袭,一只没敢发
直到我同学在他博客里疯狂晒代码,我才忍不住发的
规则
#include <iostream>
#include <windows.h>
#include <cstdlib>
#include <ctime>
#include <iomanip>
using namespace std;
#define ll long long
struct pst{
ll x;
ll y;
}que[110];
ll cx[8] = {-1,-1,-1,0,0,1,1,1};
ll cy[8] = {-1,0,1,-1,1,-1,0,1};
ll back[11][11] = {0};
char front[11][11];
ll cc;
void Bfs(ll X,ll Y){
ll h = 1;
ll t = 0;
t ++;
que[t].x = X;
que[t].y = Y;
front[X][Y] = back[X][Y] + '0';
while(h <= t){
for(ll i = 0;i <= 7;i ++){
ll nx = cx[i] + que[h].x;
ll ny = cy[i] + que[h].y;
if(1 <= nx && nx <= 10
&& 1 <= ny && ny <= 10){
if(back[nx][ny] == -1){
return;
}
t ++;
que[t].x = nx;
que[t].y = ny;
front[nx][ny] = back[nx][ny] + '0';
}
}
h ++;
}
}
ll inx,iny,op;
bool Check(){
for(ll i = 1;i <= 10;i ++){
for(ll j = 1;j <= 10;j ++){
if(!(back[i][j] == -1 && front[i][j] == 'x')){
return 0;
}
}
}
return 1;
}
int main(){
srand(time(0));
system("cls");
for(ll i = 1;i <= 10;i ++){
for(ll j = 1;j <= 10;j ++){
ll a = rand() % 10;
if(a == 0){
back[i][j] = -1;
}
}
}
for(ll i = 1;i <= 10;i ++){
for(ll j = 1;j <= 10;j ++){
if(back[i][j] == -1){
for(ll k = 0;k <= 7;k ++){
ll nx = cx[k] + i;
ll ny = cy[k] + j;
if(back[nx][ny] != -1){
back[nx][ny] ++;
}
}
}
}
}
for(ll i = 1;i <= 10;i ++){
for(ll j = 1;j <= 10;j ++){
front[i][j] = '#';
cout << setw(3) << front[i][j];
}
cout << endl;
}
while(1){
cc = 0;
cin >> inx >> iny >> op;
system("cls");
if(op == 0){
if(back[inx][iny] == -1){
cout << "boom!!!" << endl << endl;
system("pause");
system("cls");
for(ll i = 1;i <= 10;i ++){
for(ll j = 1;j <= 10;j ++){
if(back[i][j] == -1){
front[i][j] = '*';
}
cout << setw(3) << front[i][j];
}
cout << endl;
}
cout << endl;
system("pause");
return 0;
}
else{
Bfs(inx,iny);
}
}
else if(op == 1){
front[inx][iny] = 'x';
if(Check()){
cout << "You Win!!!" << endl << endl;
system("pause");
return 0;
}
}
for(ll i = 1;i <= 10;i ++){
for(ll j = 1;j <= 10;j ++){
cout << setw(3) << front[i][j];
}
cout << endl;
}
}
cout << endl << endl;
system("pause");
return 0;
}