지뢰찾기미완성 ¶
연구중....(대단한건아니지만 너무어렵네 ㅠㅠㅠ)
코드 ¶
~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좌표 방식 ㅡ,.ㅡ;;;
역시 힘들어 ㅠ










