´ÙÀ½ÀÇ °£´Ü °ÔÀÓÀº 10x10 Ç÷¹ÀÌ ±×¶ó¿îµå¿¡¼ ij¸¯ÅÍ 'C' °¡ ¸ó½ºÅÍ 'M'À» Àâ¾Æ¸ÔÀ¸¸é 1Á¡¾¿ ȹµæÇÏ´Â °ÔÀÓÀÇ Ãʱâ¹öÀüÀÌ´Ù.
- ij¸¯ÅÍ À̵¿Àº (w:À§, s: ¾Æ·¡, a: ¿ÞÂÊ, d: ¿À¸¥ÂÊ)
- Ãʱ⠸ó½ºÅÍ °³¼ö´Â 5°³
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 | #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; // ÄÜ¼Ö Ä¿¼ À§Ä¡ ¼³Á¤ 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'; } // ¸ÞÀÎ ÇÔ¼ö 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); } Sleep(200); } return 0; } | cs |


ds_simple_game_initial.txt [3 KB]
ÀڷᱸÁ¶ ½Ç½À°Ô½ÃÆÇ