// 10 x 10 이차원 배열
// 1, 0 으로 랜덤한 값이 저장되어 있음
// 1 : 폭탄 0 : 안전지대
// 플레이어 -> 정수를 두 개 입력 ( 2, 3 )
// 컴퓨터 -> 랜덤하게 두 자리 지정 ( 1, 4 )
// 폭탄을 밟으면 게임 오버
// 게임 오버까지 계속 진행
// 플레이어 win! / 컴퓨터 win!
// 1,0 표시하다가 완성하면 x로 덮어주기
// 건드린 공간은 0,1로 재표시
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <Windows.h>
void main() {
srand(time(NULL));
int map[10][10];
char x_map[10][10];
int player_x, player_y, com_x, com_y;
// 폭탄게임 초기화
for (int i = 0; i < 10; i++) {
for (int j = 0; j < 10; j++) {
map[i][j] = rand() % 4;
x_map[i][j] = 'X';
}
}
while (1) {
// 컴퓨터의 랜덤선택
com_x = rand() % 10 + 1;
com_y = rand() % 10 + 1;
if (x_map[com_x - 1][com_y - 1] == '1' || x_map[com_x - 1][com_y - 1] == '0') {
continue;
}
for (int i = 0; i < 10; i++) {
for (int j = 0; j < 10; j++) {
printf(" %c l", x_map[i][j]);
}
printf("\n");
printf("----------------------------------------");
printf("\n");
}
printf("x좌표와 y좌표를 입력하세요! : ");
scanf("%d %d", &player_x, &player_y);
if (player_x < 1 || player_x > 10 || player_y < 1 || player_y > 10) {
printf("잘못된 범위입니다. 다시 입력하세요!\n");
continue;
}
else if (x_map[player_x - 1][player_y - 1] == '1' || x_map[player_x - 1][player_y - 1] == '0') {
printf("이미 선택된 자리입니다. 다른 자리를 입력하세요!\n");
continue;
}
if (map[player_x - 1][player_y - 1] == 1) {
x_map[player_x - 1][player_y - 1] = '*';
printf("컴퓨터 win!\n");
break;
}
else {
x_map[player_x - 1][player_y - 1] = '0';
}
Sleep(1000);
printf("컴퓨터의 선택 : %d %d\n", com_x, com_y);
if (map[com_x - 1][com_y - 1] == 1) {
x_map[com_x - 1][com_y - 1] = '*';
printf("플레이어 win!\n");
break;
}
else {
x_map[com_x - 1][com_y - 1] = '0';
}
Sleep(1000);
system("cls");
}
Sleep(1000);
system("cls");
printf("결과를 공개합니다! \n\n");
for (int i = 0; i < 10; i++) {
for (int j = 0; j < 10; j++) {
printf(" %c l", x_map[i][j]);
}
printf("\n");
printf("----------------------------------------");
printf("\n");
}
}