مین روب در C++
#include
#include
#include
//------------sourcea.ir----------------------------------//
#include
#include
void replay();
int random(int, int);
void reveal(int);
void main()
{
clrscr();
int b;
cout << "Enter number of squares per side (2 - 10)"<<'\n' ;
cin >> b;
int board[10][10]; //0 - 8 = # of mines, 9 is mine
int revealed[10][10]; //1 is revealed
int i = 0;
int j = 0;
int x = 0;
int y = 0;
int z; //number of mines
int q;
int t = 0; //game over input
int dead = 0;
do
{
cout << "How many mines? (1 - " << ((b*b)-1) << ")" << endl;
cin >> z;
}while(z <= 0 && z >= ((b*b)-1));
for(i=0;i= 0)
if(board[y-1][x] != 9)
board[y-1][x]++;
if((y-1) >= 0 && (x-1) >= 0)
if(board[y-1][x-1] != 9)
board[y-1][x-1]++;
if((x-1) >= 0)
if(board[y][x-1] != 9)
board[y][x-1]++;
if((y+1) < b)
if(board[y+1][x] != 9)
board[y+1][x]++;
if((y+1) < b && (x+1) < b)
if(board[y+1][x+1] != 9)
board[y+1][x+1]++;
if((x+1) < b)
if(board[y][x+1] != 9)
board[y][x+1]++;
if((y-1) >= 0 && (x+1) < b)
if(board[y-1][x+1] != 9)
board[y-1][x+1]++;
if((y+1) < b && (x-1) >= 0)
if(board[y+1][x-1] != 9)
board[y+1][x-1]++;
}
}while(z>0);
for(i = 0; i < b; i++)
for(j=0;j= ((b*b) - z))
{
cout << "You win!" << endl;
dead = 1;
}
if(dead == 0)
{
cout << "X: ";
cin >> x;
cout << "Y: ";
cin >> y;
}
if(board[y][x] == 9)
{
system ("clear");
cout << "You hit a mine!" << endl;
cout << " ";
for(i=0;i(y-2)&&i<(y+2))
if(j>(x-2)&&j<(x+2))
if(board[i][j]!=9)
revealed[i][j]=1;
}
}
}
if(board[y][x]>0 && board[y][x]<9)
revealed[y][x] = 1;
} while(dead == 0);
if (dead == 1)
replay();
}
void replay()
{
char a;
cout << "1) Replay 2) Quit" << endl;
cin >> a;
switch(a)
{
case '1':
main();
break;
case '2':
cout << "Quit" << endl;
break;
default:
cout << "Invalid input" << endl;
replay();
break;
}
}
void reveal(int x)
{
if(x == 0)
cout << "o|";
else if(x == 9)
cout << "x|";
else
cout << x << "|";
}
int random(int i, int b)
{
long ran;
int t = time(0);
int s;
srand(t);
s = ran;
ran = rand();
ran >>= ran / (ran * i) + (i * 1337);
ran = ran % b;
return ran;
}
توضیحات:
صورت سوال:
مین روب در C++
بازی مین روب (Minesweeper) به زبان c++ نوشته شده.
شما میتوانید سوالات خود را از طریق ایمیل پشتیبانی – تماس با ما – یا در قسمت نظرات سوال خود را بپرسید.
موفق باشید
A.J