¶
....(한 ㅠㅠㅠ)
¶
~cpp
#include <iostream.h>
#include <stdlib.h>
#include <time.h>
static int space[16][16];
static int gameover=1; //0 한
void mine_confirm(int X, int Y); // 확
void mine_update(int X, int Y); //
void mine_newgame(); // 화
void mine_show(); // 화
void mine_menu(); //
/////////////////////////////////////////////////////////
void main()
{
mine_newgame();
mine_show();
while(gameover)
{
mine_menu();
}
}
/////////////////////////////////////////////////////////
void mine_menu() //
{
int num_x,num_y;
while(1){
num_x = 0;
num_y = 0;
cout << "X 표 ? (1~20): ";
cin >> num_x;
cout << "Y 표 ? (1~20): ";
cin >> num_y;
if (1<=num_x<=20)
if (1<=num_y<=20)
break;
cout << "하." << endl;
}
mine_confirm(num_x-1,num_y-1);
}
void mine_show()
{
int a,b;
cout << endl << endl<< endl<< endl<< endl<< endl<< endl;
cout << " ====== 1.00======" << endl;
for (a=0 ; a!=16 ; a++){
cout << " ";
for (b=0 ; b!=16 ; b++){
switch(space[b][a]){
case 10 :
cout << "■";
break;
case 9 :
cout << "■";
break;
default :
cout << space[b][a] << " " ;
}
}
cout << endl;
}
}
/////////////////////////////////////////////////////////
void mine_update(int X, int Y)
{
int mine_count;
mine_count = 0;
if(X-1 >= 0 && Y-1 >= 0){
if (space[X-1][Y-1] == 9){
mine_count++;
}
}
if(Y-1 >= 0){
if (space[X][Y-1] == 9){
mine_count++;
}
}
if(X+1 <= 15 && Y-1 >= 0){
if (space[X+1][Y-1] == 9){
mine_count++;
}
}
if(X-1 >= 0 ){
if (space[X-1][Y] == 9){
mine_count++;
}
}
if(X+1 <= 15){
if (space[X+1][Y] == 9){
mine_count++;
}
}
if(X-1 >= 0 && Y+1 <= 15){
if (space[X-1][Y+1] == 9){
mine_count++;
}
}
if(Y+1 <= 15){
if (space[X][Y+1] == 9){
mine_count++;
}
}
if(X+1 <=15 && Y+1 <= 15){
if (space[X+1][Y+1] == 9){
mine_count++;
}
}
space[X][Y] = mine_count;
mine_show();
}
///////////////////////////////////////////////////////////
void mine_confirm(int X, int Y)
{
if (space[X][Y] ==9){
gameover = 0;
cout << endl<< endl<< endl<< endl;
cout << endl << " ====YOU step MINE AND BOOM====";
cout << endl << " ============GAME OVER=============" <<endl;
int a,b;
for (a=0 ; a!=16 ; a++){
cout << " ";
for (b=0 ; b!=16 ; b++){
switch(space[b][a]){
case 10 :
cout << "■";
break;
case 9 :
cout << "⊙";
break;
default :
cout << space[b][a] << " " ;
}
}
cout << endl;
}
char c;
cout << "하?(y/n) : ";
cin >> c ;
if (c == 'y'){
gameover = 1;
mine_newgame();
mine_show();
}
}
else if(space[X][Y] ==10)
mine_update(X,Y);
}
/////////////////////////////////////////////////////////
void mine_newgame()
{
int i;
int a,b;
for (a=0 ; a!=16 ; a++){
for (b=0 ; b!=16 ; b++){
space[b][a] = 10;
}
} // 화
srand(time(NULL)); //
for (i=0;i!=40;i++){
while(1) {
int x,y;
x=rand()%15+0;
y=rand()%15+0;
if (space[x][y] != 9){
space[x][y] = 9;
break;
}
}
}
}
/////////////////////////////////////////////////////////
크 ¶
¶
ㅡ,.ㅡ;; 200;;
히 하 하 ㅠ
클 히 X,Y표 ㅡ,.ㅡ;;;
힘 ㅠ










