#include <turboc.h>
#define MAX 10
struct BOOM {
int map;
int block;
int flag;
};
int Clear_Check(struct BOOM boom[MAX][MAX],int Boom_Check){
int Count = 0;
int i,j;
for(i=0;i<MAX;i++){
for(j=0;j<MAX;j++){
if(boom[i][j].block == 1)
Count++;
}
}
gotoxy(0,MAX+1);
printf("Block_Count = %d \n",Count);
if( ( Count == ((MAX-2)*(MAX-2) - MAX) ) && Boom_Check == MAX){
return 1; // 참
}else{
return 0; // 거짓
}
}
int Check_Count(struct BOOM boom[MAX][MAX],int i,int j){
int Count =0;
int x,y;
for(x=-1;x<=1;x++){
for(y=-1;y<=1;y++){
if(boom[i+x][j+y].map == 10){
Count++;
}
}
}
return Count;
}
void Print_MAP(struct BOOM boom[MAX][MAX]){
int i,j;
gotoxy(0,0);
for(i=0;i<MAX;i++){
for(j=0;j<MAX;j++){
if(boom[i][j].block == 0){
switch(boom[i][j].map){
case 9:
textcolor(15);
printf("▧");
break;
default:
textcolor(2);
printf("□");
break;
}
}else{
switch(boom[i][j].map){
case 0:
printf(" ");
break;
case 1:
textcolor(11);
printf("①");
break;
case 2:
textcolor(14);
printf("②");
break;
case 3:
textcolor(13);
printf("③");
break;
case 4:
textcolor(8);
printf("④");
break;
case 5:
textcolor(9);
printf("⑤");
break;
case 9:
textcolor(15);
printf("▧");
break;
case 10:
textcolor(RED);
printf("※");
break;
}
}
if(boom[i][j].block == 0 && boom[i][j].flag == 1 ){
textcolor(BLUE);
printf("\b\b▶");
}
}
printf("\n");
}
}
int main(){
struct BOOM boom[MAX][MAX];
int i,j;
int x,y;
int X,Y;
char ch;
int Boom_Check=0;
for(i=0;i<MAX;i++){
for(j=0;j<MAX;j++){
if(i==0||j==0|| i == MAX-1 || j == MAX-1){
boom[i][j].map = 9;
}else{
boom[i][j].map = 0;
boom[i][j].block = 0;
boom[i][j].flag = 0;
}
}
}
//지뢰 심기
for(i=0;i<MAX;i++){
x = baserand(1,MAX-2);
y = baserand(1,MAX-2);
if(boom[x][y].map != 10){
boom[x][y].map = 10;
}else{
i--;
continue;
}
}
//Count 세기
for(i=1;i<MAX-1;i++){
for(j=1;j<MAX-1;j++){
if(boom[i][j].map != 10){
boom[i][j].map = Check_Count(boom,i,j);
}
}
}
X = Y = 2;
Print_MAP(boom);
while(1){
gotoxy(0,MAX+3);
printf(" X = %2d , Y = %2d \n",X,Y);
printf(" Count = %2d \n",boom[Y][X].map);
printf(" Boom Check = %2d\n",Boom_Check);
gotoxy(X*2,Y);
ch = getch();
switch(ch){
case UP:
if(Y!=1)Y--;
break;
case DOWN:
if(Y!=MAX-2)Y++;
break;
case LEFT:
if(X!=1)X--;
break;
case RIGHT:
if(X!=MAX-2)X++;
break;
case 'f':
if(boom[Y][X].block == 0){
if(boom[Y][X].flag == 1){
boom[Y][X].flag = 0;
if(boom[Y][X].map == 10){
Boom_Check--;
}
}else{
boom[Y][X].flag = 1;
if(boom[Y][X].map == 10){
Boom_Check++;
}
}
}
break;
case ' ':
boom[Y][X].block = 1;
if(boom[Y][X].map == 10){
gotoxy(0,MAX+6);
textcolor(WHITE);
for(i=0;i<MAX;i++){
for(j=0;j<MAX;j++){
if(boom[i][j].map==10){
boom[i][j].block = 1;
}
}
}
Print_MAP(boom);
printf("지뢰를 밟았습니다 \n");
printf("게임을 끝내겠습니다...\n");
return 0;
}
break;
}
Print_MAP(boom);
if(Clear_Check(boom,Boom_Check/*클리어 조건*/) == 1 ){
gotoxy(0,MAX+7);
printf("게임을 클리어 하셨습니다 \n");
printf("수고하셨습니다 ^^ \n");
break;
}
}
return 0;
}
아직 구현할게 남았고...
쌤 ver.이다
어렵다....