#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <conio.h> // Windows Àü¿ë, Ű ÀÔ·ÂÀ» ºñµ¿±â·Î ó¸®
#include <windows.h> // ÄÜ¼Ö Ä¿¼ Á¦¾î
#define SIZE 10
#define MONSTER_COUNT 5
// °ÔÀÓ ¸Ê°ú ij¸¯ÅÍ Á¤º¸
char map[SIZE][SIZE];
int player_x = 0, player_y = 0; // ij¸¯ÅÍ Ãʱâ À§Ä¡
int score = 0;
int monster_x[MONSTER_COUNT], monster_y[MONSTER_COUNT]; // 5°³ÀÇ ¸ó½ºÅÍ À§Ä¡
// ÄÜ¼Ö Ä¿¼ À§Ä¡ ¼³Á¤
void set_cursor_position(int x, int y) {
COORD coord = { x, y };
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), coord);
}
// Ä¿¼ ¼û±â±â
void hide_cursor() {
CONSOLE_CURSOR_INFO cursorInfo;
cursorInfo.bVisible = FALSE; // Ä¿¼ ¼û±è
cursorInfo.dwSize = 1; // Ä¿¼ Å©±â
SetConsoleCursorInfo(GetStdHandle(STD_OUTPUT_HANDLE), &cursorInfo);
}
// ¸Ê ÃʱâÈ
void initialize_map() {
for (int i = 0; i < SIZE; i++) {
for (int j = 0; j < SIZE; j++) {
map[i][j] = '.'; // ºó °ø°£
}
}
// ij¸¯ÅÍ Ãʱâ À§Ä¡
map[player_y][player_x] = 'C';
// ¸ó½ºÅÍ À§Ä¡ ¼³Á¤
srand(time(NULL));
for (int i = 0; i < MONSTER_COUNT; i++) { // ¸ó½ºÅÍ 5°³ »ý¼º
int monster_x = rand() % SIZE;
int monster_y = rand() % SIZE;
if (map[monster_y][monster_x] == '.') {
map[monster_y][monster_x] = 'M';
}
else {
i--; // ÀÌ¹Ì ÀÖ´Â À§Ä¡¸é ´Ù½Ã ½Ãµµ
}
}
}
// ¸Ê Ãâ·Â
void print_map() {
set_cursor_position(0, 0); // Ä¿¼¸¦ È¸é ¸Ç À§·Î À̵¿
for (int i = 0; i < SIZE; i++) {
for (int j = 0; j < SIZE; j++) {
printf("%c ", map[i][j]);
}
printf("\n");
}
printf("\nÁ¡¼ö: %d\n", score);
}
// ij¸¯ÅÍ À̵¿
void move_player(char direction) {
// ÇöÀç À§Ä¡ ÃʱâÈ
map[player_y][player_x] = '.';
// ¹æÇâ¿¡ µû¶ó À̵¿
if (direction == 'w' && player_y > 0) player_y--; // ˤ
if (direction == 's' && player_y < SIZE - 1) player_y++; // ¾Æ·¡
if (direction == 'a' && player_x > 0) player_x--; // ¿ÞÂÊ
if (direction == 'd' && player_x < SIZE - 1) player_x++; // ¿À¸¥ÂÊ
// À̵¿ÇÑ À§Ä¡¿¡ ¸ó½ºÅͰ¡ ÀÖÀ¸¸é Á¡¼ö Áõ°¡
if (map[player_y][player_x] == 'M') {
score++;
}
// ij¸¯ÅÍ À§Ä¡ ¾÷µ¥ÀÌÆ®
map[player_y][player_x] = 'C';
}
//¸ó½ºÅͰ¡ ·£´ýÀ¸·Î ¿òÁ÷ÀÌ´Â ÄÚµå
void move_monster() {
srand(time(NULL));
for (int i = 0; i < MONSTER_COUNT; i++) {
int n = rand() % 4;
int new_monster_x = monster_x[i];
int new_monster_y = monster_y[i];
if (n == 0) new_monster_y++;
if (n == 1) new_monster_y--;
if (n == 2) new_monster_x++;
if (n == 3) new_monster_x--;
if (new_monster_x >= 0 && new_monster_x < SIZE-1 && new_monster_y >= 0 && new_monster_y < SIZE-1 && map[new_monster_y][new_monster_x] == '.') {
map[monster_y[i]][monster_x[i]] = '.';
monster_x[i] = new_monster_x;
monster_y[i] = new_monster_y;
map[monster_y[i]][monster_x[i]] = 'M';
}
}
}
// ¸ÞÀÎ ÇÔ¼ö
int main() {
char input;
initialize_map();
system("cls"); // Ãʱâ ȸé Á¤¸®
hide_cursor(); // Ä¿¼ ¼û±â±â
while (1) {
print_map();
// Ű ÀÔ·Â ´ë±â
if (_kbhit()) {
input = _getch(); // Ű ÀԷ¹ޱâ
if (input == 'q') { // q ÀÔ·Â ½Ã °ÔÀÓ Á¾·á
printf("°ÔÀÓ Á¾·á! ÃÖÁ¾ Á¡¼ö: %d\n", score);
break;
}
move_player(input);
}
move_monster();
Sleep(200);
}
return 0;
}