• º» °Ô½ÃÆÇÀº ¼ö¾÷½Ã°£¿¡ Çлýµé ½Ç½ÀÀ» À§ÇÑ °Ô½ÃÆÇÀÔ´Ï´Ù.
  • º» °Ô½ÃÆÇ¿¡ ¿Ã¶ó¿Í ÀÖ´Â ÇÁ·Î±×·¥Àº ´ëºÎºÐ ¿Ã¹Ù¸£Áö ¾ÊÀº ÇÁ·Î±×·¥ÀÔ´Ï´Ù.
        À̱âÁ¤
        15ÁÖÂ÷ ½Ç½À



    #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 monster_x[MONSTER_COUNT], monster_y[MONSTER_COUNT]; //Ãß°¡
    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;*/
            monster_x[i] = rand() % SIZE;
            monster_y[i] = rand() % SIZE;
            if (map[monster_y[i]][monster_x[i]] == '.') {
                map[monster_y[i]][monster_x[i]] = '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() {
        for (int i = 0; i < MONSTER_COUNT; i++) {

            int prev_y = monster_y[i], prev_x = monster_x[i];

            // ÇöÀç À§Ä¡ ÃʱâÈ­
            map[monster_y[i]][monster_x[i]] = '.';
            int direction = rand() % 4;

            switch (direction)
            {
            case 0: if (monster_y[i] > 0) monster_y[i]--; //À§
                break;
            case 1: if (monster_y[i] < SIZE - 1) monster_y[i]++; //¾Æ·¡
                break;
            case 2: if (monster_x[i] > 0) monster_x[i]--; //¿ÞÂÊ
                break;
            case 3: if (monster_x[i] < SIZE - 1) monster_x[i]++; //¿À¸¥ÂÊ
                break;
            }

            if (map[monster_y[i]][monster_x[i]] == '.') map[monster_y[i]][monster_x[i]] = 'M';
            else map[prev_y][prev_x] = 'M';
        }
    }

    // ¸ÞÀÎ ÇÔ¼ö
    int main() {
        char input;
        initialize_map();
        system("cls");  // Ãʱâ È­¸é Á¤¸®
        hide_cursor();  // Ä¿¼­ ¼û±â±â

        while (1) {
            print_map();
            move_monster();

            // Ű ÀÔ·Â ´ë±â
            if (_kbhit()) {
                input = _getch();  // Ű ÀԷ¹ޱâ
                if (input == 'q') {  // q ÀÔ·Â ½Ã °ÔÀÓ Á¾·á
                    printf("°ÔÀÓ Á¾·á! ÃÖÁ¾ Á¡¼ö: %d\n", score);
                    break;
                }
                move_player(input);
            }
            Sleep(200);
        }

        return 0;
    }

      µî·ÏÀÏ : 2024-12-10 [14:49] Á¶È¸ : 70 ´Ù¿î : 0   
     
    ¡ä ´ÙÀ½±Û15ÁÖÂ÷ ½Ç½À
    Çлý½Ç½À °Ô½ÃÆÇ
    ¹øÈ£ ¨Ï Á¦ ¸ñ À̸§ Á¶È¸ µî·ÏÀÏ
    108 ¿äûÇϽŠÀÚ·áÀÔ´Ï´Ù. ÇÁ·Î±×·¡¹Ö¾ð¾î Çѹμ­ 14 03-28
    107 15ÁÖÂ÷ ½Ç½À ÇÁ·Î±×·¡¹Ö¾ð¾î À̱âÁ¤ 70 12-10
    106 ¦¦❶ 15ÁÖÂ÷ ½Ç½À (¿À·ù ¼öÁ¤) ÇÁ·Î±×·¡¹Ö¾ð¾î Á¤¼ºÈÆ 79 12-10
    105 °ÔÀӽǽÀ ÇÁ·Î±×·¡¹Ö¾ð¾î . 99 12-10
    104 ¦¦❶ °ÔÀӽǽÀ (¿À·ù ¼öÁ¤) ÇÁ·Î±×·¡¹Ö¾ð¾î Á¤¼ºÈÆ 76 12-10
    103 ÀüÈ­¹øÈ£ ¼öÁ¤ÇÏ´Â ÇÁ·Î±×·¥ ÇÁ·Î±×·¡¹Ö¾ð¾î ÀÓÀç¸ð 96 12-03
    102 14ÁÖÂ÷ ½Ç½À ÇÁ·Î±×·¡¹Ö¾ð¾î Â÷»ó¹Î 91 12-03
    101 °áÁ¤ Æ®¸® ÀڷᱸÁ¶ À̱âÁ¤ 137 11-26
    100 ¾ß±¸½Ç½ÀN ÇÁ·Î±×·¡¹Ö¾ð¾î ÃÖÇö¿ì 184 11-19
    99 ¾ß±¸½Ç½À ÇÁ·Î±×·¡¹Ö¾ð¾î ¹éÀμ­ 161 11-19
    98 11ÁÖÂ÷ ½Ç½À ÇÁ·Î±×·¡¹Ö¾ð¾î ÀüÈ£¼º 174 11-12
    97 Å¥¸¦ ÀÌ¿ëÇÑ ³Êºñ ¿ì¼± Ž»ö ÇÁ·Î±×·¡¹Ö¾ð¾î ÀÓÀç¸ð 245 10-29
    96 Å¥¸¦ ÀÌ¿ëÇÑ ³Êºñ ¿ì¼± Ž»ö BFS ±¸Çö ÀڷᱸÁ¶ À̱âÁ¤ 239 10-29
    95 Á¶°Ç¹® µµÀü°úÁ¦1 ÇÁ·Î±×·¡¹Ö¾ð¾î ÃÖÇö¿ì 308 04-12
    94 4¿ù12ÀÏ ¼¼¼ö ºñ±³ ½Ç½À ÇÁ·Î±×·¡¹Ö¾ð¾î À±¿µ¹Î 295 04-12

    [1][2][3][4][5][6][7][8]