fork download
  1. #include <stdio.h>
  2. #include <conio.h>
  3. #include <stdlib.h>
  4. #include <Windows.h>
  5.  
  6. #define MAX 14
  7. #define GOAL 8
  8.  
  9.  
  10. enum colorName
  11. {
  12. BLACK,
  13. D_BLUE,
  14. D_GREEN,
  15. D_SKYBLUE,
  16. D_RED,
  17. D_VIOLET,
  18. D_YELLOW,
  19. GRAY,
  20. D_GRAY,
  21. BLUE,
  22. GREEN,
  23. SKYBLUE,
  24. RED,
  25. VIOLET,
  26. YELLOW,
  27. WHITE,
  28. };
  29.  
  30. void color(int bgColor, int textColor)
  31. {
  32. SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), bgColor*16+textColor);
  33. }
  34.  
  35.  
  36. int main(void)
  37. {
  38. int map[15][15]=
  39. {
  40. {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1},
  41. {1,0,1,0,0,0,0,0,0,0,0,0,0,0,1},
  42. {1,0,1,0,1,1,1,1,1,1,1,1,1,0,1},
  43. {1,0,1,0,1,0,0,0,0,0,0,0,1,0,1},
  44. {1,0,1,0,1,0,1,1,1,1,1,0,1,0,1},
  45. {1,0,1,0,1,0,1,0,0,0,0,0,1,0,1},
  46. {1,0,1,0,1,0,1,1,1,1,1,0,1,0,1},
  47. {1,0,1,0,1,0,1,3,0,0,1,0,1,0,1},
  48. {1,0,1,0,1,0,1,1,1,0,1,0,1,0,1},
  49. {1,0,1,0,1,0,1,0,0,0,1,0,1,0,1},
  50. {1,0,1,0,1,0,1,0,1,1,1,0,1,0,1},
  51. {1,0,1,0,1,0,1,0,0,0,0,0,1,0,1},
  52. {1,0,1,0,1,0,1,1,1,1,1,1,1,0,1},
  53. {1,0,0,0,1,0,0,0,0,0,0,0,0,0,1},
  54. {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1},
  55. };
  56.  
  57. int myPosition_X=1, myPosition_Y=1;
  58. int i, j, k;
  59. int wallDetected=0;
  60. int moveCount=0;
  61. int loop=1;
  62.  
  63. char input = 0;
  64.  
  65. do
  66. {
  67. system("cls");
  68.  
  69. map[myPosition_Y][myPosition_X]=2;
  70.  
  71. for (i=0;i<=MAX;i++)
  72. {
  73. for (j=0;j<=MAX;j++)
  74. {
  75. if (map[i][j]==1)
  76. {
  77. color(BLACK, WHITE);
  78. printf("■");
  79. }
  80.  
  81. else if (map[i][j]==0)
  82. {
  83. color(BLACK, WHITE);
  84. printf(" ");
  85. }
  86.  
  87. else if (map[i][j]==2)
  88. {
  89. color(BLACK, RED);
  90. printf("♂");
  91. }
  92.  
  93. else if (map[i][j]==3)
  94. {
  95. color(BLACK, RED);
  96. printf("♀");
  97. }
  98. }
  99.  
  100. printf("\t\t");
  101.  
  102. for (k=0;k<=MAX;k++)
  103. {
  104. printf("%d ",map[i][k]);
  105. }
  106.  
  107. printf("\n");
  108. }
  109.  
  110. printf("\n");
  111.  
  112. color(BLACK,YELLOW);
  113. printf("x : ");
  114.  
  115. color(BLACK,WHITE);
  116. printf("%d\t", myPosition_X+1);
  117.  
  118. color(BLACK,YELLOW);
  119. printf("y : ");
  120.  
  121. color(BLACK,WHITE);
  122. printf("%d\n\n", -(myPosition_Y+1));
  123.  
  124. color(BLACK,YELLOW);
  125. printf("움직인 횟수 : ");
  126.  
  127. color(BLACK,WHITE);
  128. printf("%d\n\n", moveCount);
  129.  
  130. if (wallDetected==1)
  131. {
  132. color(BLACK,YELLOW);
  133. printf("SYSTEM : ");
  134.  
  135. color(BLACK,WHITE);
  136. printf("으악! 벽이다. \n\n");
  137. }
  138. input=_getch();
  139.  
  140. switch (input)
  141. {
  142.  
  143. case 72 :
  144.  
  145. moveCount++;
  146. wallDetected=0;
  147.  
  148. map[myPosition_Y][myPosition_X]=0;
  149. myPosition_Y--;
  150.  
  151. if (map[myPosition_Y][myPosition_X]==1)
  152. {
  153. moveCount--;
  154. wallDetected=1;
  155.  
  156. myPosition_Y++;
  157. }
  158.  
  159. else if (map[myPosition_Y][myPosition_X]==3)
  160. loop=0;
  161.  
  162. break;
  163.  
  164. case 75 :
  165.  
  166. moveCount++;
  167. wallDetected=0;
  168.  
  169. map[myPosition_Y][myPosition_X]=0;
  170. myPosition_X--;
  171.  
  172. if (map[myPosition_Y][myPosition_X]==1)
  173. {
  174. moveCount--;
  175. wallDetected=1;
  176.  
  177. myPosition_X++;
  178. }
  179.  
  180. else if (map[myPosition_Y][myPosition_X]==3)
  181. loop=0;
  182.  
  183. break;
  184.  
  185. case 77 :
  186.  
  187. moveCount++;
  188. wallDetected=0;
  189.  
  190. map[myPosition_Y][myPosition_X]=0;
  191. myPosition_X++;
  192.  
  193. if (map[myPosition_Y][myPosition_X]==1)
  194. {
  195. moveCount--;
  196. wallDetected=1;
  197.  
  198. myPosition_X--;
  199. }
  200.  
  201. else if (map[myPosition_Y][myPosition_X]==3)
  202. loop=0;
  203.  
  204. break;
  205.  
  206. case 80 :
  207.  
  208. moveCount++;
  209. wallDetected=0;
  210.  
  211. map[myPosition_Y][myPosition_X]=0;
  212. myPosition_Y++;
  213.  
  214. if (map[myPosition_Y][myPosition_X]==1)
  215. {
  216. moveCount--;
  217. wallDetected=1;
  218.  
  219. myPosition_Y--;
  220. }
  221.  
  222. else if (map[myPosition_Y][myPosition_X]==3)
  223. loop=0;
  224.  
  225. break;
  226.  
  227. case 27 :
  228.  
  229. loop=0;
  230.  
  231. break;
  232. }
  233.  
  234. } while(loop);
  235.  
  236. return 0;
  237. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.c:2:19: fatal error: conio.h: No such file or directory
compilation terminated.
stdout
Standard output is empty