U E D R , A S I H C RSS

김��/연구중/지뢰찾기

지뢰찾기미완성

연구중....(대단한건아니지만 너무어렵네 ㅠㅠㅠ)

코드

~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;
			
			}
		}
	}	
}

/////////////////////////////////////////////////////////

스�린샷

mine1.JPG
mine2.JPG

후기


찾기 기능만 넣었는� ㅡ,.ㅡ;;대략 200��밖�;;
�저히 깃발꽃기랑 근처� 마�없으면 다 보�게 하는건 못하겟�� ㅠ
비주얼�� �릭같�게 없으니 단순히 X,Y좌표 방� ㅡ,.ㅡ;;;
역시 힘들어 ㅠ

나�게 할�


�..��.ㅎㅎ 나는 지뢰 파�� 만들고 있는�.. 옆�서 지뢰찾기를 만들다닛..
네가 심으면 내가 찾는거�? ㅎㅎㅎㅎ 둘� 붙여놓으면 �겠네..ㅎㅎㅎ
지뢰 파�� 알고리즘� 아무것� 없는 빈칸 주위를 찾는 알고리즘� 만들어 �서 그런�..ㅎㅎ
마ì�¸ì—†ìœ¼ë©´ 찾는거.. ìž¬ê·€í˜¸ìœ ì�¨ë¨¹ìœ¼ë©´ 편하다우..ã…Žã…Žã…Ž
ㅎㅎㅎ 그럼 수고하�구^^ - 조현태
┗�! 나중� 재개할때 꼭�먹�게! -김��

Valid XHTML 1.0! Valid CSS! powered by MoniWiki
last modified 2021-02-07 05:28:49
Processing time 0.0055 sec