#include #include #include #include /* * < »ç°Ý°ÔÀÓ > * * ȣȯ¼º * ÀÌ ÇÁ·Î±×·¥Àº Borland C++ 5.5 ¿¡¼­ ÄÄÆÄÀÏÇÏ°í ½ÃÇèµÇ¾ú½À´Ï´Ù. * * °ÔÀÓ¼³¸í * »ç°ÝÀåÀº °¢°¢ Çϳª¾¿ÀÇ È­»ìÀ» Æ÷ÇÔÇϰí ÀÖ´Â ¾ÆÈ©°³ÀÇ ·¹ÀÎÀ¸·Î ¸¸µé¾îÁ® ÀÖ½À´Ï´Ù. * ÇÁ·Î±×·¥ÀÌ ½ÃÀÛµÇ¸é ·¹ÀÎÀÇ ¿À¸¥ÂÊ¿¡ ÇѰ³ÀÇ Å¸°Ù(X)ÀÌ ³ªÅ¸³³´Ï´Ù. * ´ç½ÅÀÇ °úÁ¦´Â È­»ìµé ÁßÀÇ Çϳª·Î Ÿ°ÙÀ» ¸ÂÃß´Â °Í ÀÔ´Ï´Ù. * È­»ìÀ» ½î·Á¸é ·¹ÀÎ ¹øÈ£¸¦ ´©¸£¸é µË´Ï´Ù. * 25°³ÀÇ Å¸°ÙÀÌ ³ªÅ¸³­ ÈÄ¿¡, °ÔÀÓÀº ³¡³ª°í, ÃÖÁ¾Á¡¼ö°¡ Ãâ·ÂµË´Ï´Ù. * * ³­À̵µ º¯°æÇϱâ * ³­À̵µ¸¦ º¯°æÇÏ·Á¸é ShootArrow(int)ÇÔ¼öÀÇ µÎ¹øÂ° for·çÇÁ¸¦ º¯°æÇؼ­ È­»ìÀÇ ¼Óµµ¸¦ º¯°æÇÏ¸é µË´Ï´Ù. * È­»ìÀÌ ÃµÃµÈ÷ ³ª°¥¼ö·Ï ¸ÂÃß±â±îÁöÀÇ ½Ã°£À» ¼ÒºñÇϹǷΠ³­À̵µ´Â ³ô¾ÆÁý´Ï´Ù. * PlayGame(void)ÇÔ¼öÀÇ TIME_LIMIT°ªÀ» 2ÃÊ·Î ¸ÂÃß¾î ³õ¾Ò±â ¶§¹®¿¡ * È­»ìÀÌ ¹ß»çµÇ´Âµ¥ 2Ãʰ¡ °É¸°´Ù¸é °ÔÀÓÀÌ ¾ÈµÇÁÒ. ¿ª½Ã Á¦Çѽ𣵵 ¸¶À½´ë·Î ¼öÁ¤Çϼ¼¿ä. */ #define true 1 #define false 0 typedef int bool; void ShowScore(int); int PlayGame(void); void EraseTarget(int); void ShootArrow(int); int ShowTarget(void); void DrawScreen(void); int main(void) { int score; srand((unsigned) time(NULL)); DrawScreen(); score = PlayGame(); ShowScore(score); return 0; } void DrawScreen(void) { int x; clrscr(); gotoxy(20, 11); printf("°ÔÀÓÀ» ½ÃÀÛÇÏ·Á¸é ¾Æ¹«Å°³ª ´©¸£¼¼¿ä."); getch(); clrscr(); for (x = 1; x <= 10; x++) { // ·çÇÁ´Â Çѹø¿¡ ÇÑ °³ÀÇ ÇìÀκ®°ú ÇѰ³ÀÇ È­»ìÀ» ±×¸°´Ù. gotoxy(1, x * 2 + 2); printf("-----------------------------------"); if (x < 10) { gotoxy(1, x * 2 + 3); printf("%d%s", x, " >>-->"); } } } void EraseTarget(int target_position) { gotoxy(60, target_position * 2 + 3); printf(" "); } int PlayGame(void) { int score = 0; int target_position; long start_time; bool shot_fired; int num; // °ªÀ¸·Î ÀúÀåÇÏ´Â ¼ýÀÚŰ const int TIME_LIMIT = 2; // ÇÑ Å¸°Ù´ç Á¦Çѽð£ 2ÃÊ int x; for (x = 1; x <= 20; x++) { // ÀÌ ·çÇÁ´Â 25°³ÀÇ Å¸°ÙÀ» ºÎ¿©ÇÑ´Ù. target_position = ShowTarget(); start_time = time(NULL); // ¿©±â¿¡¼­ ½ÃÀ۽ð£ÀÌ ÀúÀåµÈ´Ù. shot_fired = false; // Á¦Çѽð£°ú ³²Àº È­»ì°³¼ö¸¦ ¾Ë·ÁÁÜ gotoxy(44, 2); printf("%s%d%s", "³²Àº È­»ì: ", 21 - x, " "); gotoxy(10, 2); printf("%s%d%s", "ÇÑ Å¸°Ù ´ç ½Ã°£Á¦ÇÑ ", TIME_LIMIT, "ÃÊ"); do { // ¼±¼ö°¡ »ç°ÝÀ» ÇÒ ¶§±îÁö Ű ÀÔ·ÂÀ» ±â´Ù¸°´Ù. num = getch() - '0'; if (num >= 1 && num <= 9) { ShootArrow(num); shot_fired = true; } } while (!shot_fired); // ½Ã°£ ¾È¿¡(2ÃÊ) Ÿ°ÙÀ» ¸ÂÃß¾úÀ» ¶§ ½ÇÇàµÈ´Ù. if ((time(NULL) < start_time + TIME_LIMIT) && num == target_position) { putchar('\a'); ++score; } EraseTarget(target_position); } return score; } void ShootArrow(int a) { // ÆÄ¶ó¹ÌÅÍ a´Â ¹ß»çÇÑ È­»ìÀÇ ¹øÈ£ int x; long delay; for (x = 4; x <= 60; x++) { gotoxy(x, a * 2 + 3); // ·çÇÁÀÇ ¸Å ȸ¸¶´Ù È­»ìÀ» 1¹®ÀÚ¾¿ ¿À¸¥ÂÊÀ¸·Î ¿òÁ÷ÀδÙ. printf(">>-->"); for (delay = 0; delay < 3999999; delay++) // ÀÌ ÄÚµå·Î È­»ìÀÇ ¼ÓµµÁ¶ÀýÀ» ÇÑ´Ù. ½Ã½ºÅÛÀÇ ¼º´É¿¡ µû¶ó ´Ù¸£´Ù. continue; gotoxy(x, a * 2 + 3); printf(" "); } gotoxy(4, a * 2 + 3); printf(">>-->"); } void ShowScore(int score) { gotoxy(60, 20); printf("-----------------"); gotoxy(60, 21); printf("%s%d", " Your score is ", score); gotoxy(60, 22); printf("-----------------"); } int ShowTarget(void) { int p = rand() % 9 + 1; // ÀÌ ³­¼ö´Â Ÿ°ÙÀÌ ³ªÅ¸³¯ ·¹ÀιøÈ£ÀÌ´Ù. 1 ~ 9 gotoxy(60, p * 2 + 3); printf("X"); return p; }