Advertisement
Guest User

Untitled

a guest
Mar 24th, 2018
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.92 KB | None | 0 0
  1.  
  2. #include <stdlib.h>
  3. #include <iostream>
  4. #include <string>
  5. #include <stdio.h>
  6. #include <conio.h>
  7.  
  8. using namespace std;
  9.  
  10. int const a = 40, b = 80;
  11.  
  12. char map[a][b];
  13.  
  14. char ch = 'W';
  15.  
  16. int x = b / 2, y = a / 2, z = 0;
  17.  
  18. void drawturtele(int i, int j, int z)
  19. {
  20. map[i - 1][j - 1] = ch;
  21. map[i][j] = ch;
  22. map[i + 1][j + 1] = ch;
  23. map[i - 1][j + 1] = ch;
  24. map[i + 1][j - 1] = ch;
  25. map[i - 1][j] = ch;
  26. map[i][j - 1] = ch;
  27. map[i + 1][j] = ch;
  28. map[i][j + 1] = ch;
  29. switch (z)
  30. {
  31. case 0:
  32. map[i - 2][j] = ch;
  33. break;
  34. case 1:
  35. map[i][j + 2] = ch;
  36. break;
  37. case 2:
  38. map[i + 2][j] = ch;
  39. break;
  40. case 3:
  41. map[i][j - 2] = ch;
  42. break;
  43. }
  44. }
  45.  
  46. void deleteturtele()
  47. {
  48. {
  49. map[y - 1][x - 1] = ' ';
  50. map[y][x] = ' ';
  51. map[y + 1][x + 1] = ' ';
  52. map[y - 1][x + 1] = ' ';
  53. map[y + 1][x - 1] = ' ';
  54. map[y - 1][x] = ' ';
  55. map[y][x - 1] = ' ';
  56. map[y + 1][x] = ' ';
  57. map[y][x + 1] = ' ';
  58. switch (z)
  59. {
  60. case 0: map[y - 2][x] = ' ';
  61. break;
  62. case 1: map[y][x + 2] = ' ';
  63. break;
  64. case 2: map[y + 2][x] = ' ';
  65. break;
  66. case 3: map[y][x - 2] = ' ';
  67. break;
  68. }
  69. }
  70. }
  71.  
  72. void move(string napr, int shag)
  73. {
  74. deleteturtele();
  75. if (napr == "vpered")
  76. {
  77. switch (z)
  78. {
  79. case 0: y = y - shag;
  80. break;
  81. case 1: x = x + shag;
  82. break;
  83. case 2: y = y + shag;
  84. break;
  85. case 3: x = x - shag;
  86. break;
  87. }
  88. }
  89. if (napr == "vlevo")
  90. {
  91. switch (z)
  92. {
  93. case 0: x = x - shag;
  94. break;
  95. case 1: y = y - shag;
  96. break;
  97. case 2: x = x + shag;
  98. break;
  99. case 3: y = y + shag;
  100. break;
  101. }
  102.  
  103. }
  104. if (napr == "vpravo")
  105. {
  106. switch (z)
  107. {
  108. case 0: x = x + shag;
  109. break;
  110. case 1: y = y + shag;
  111. break;
  112. case 2: x = x - shag;
  113. break;
  114. case 3: y = y - shag;
  115. break;
  116. }
  117.  
  118. }
  119. if (napr == "nazad")
  120. {
  121. switch (z)
  122. {
  123. case 0: y = y + shag;
  124. break;
  125. case 1: x = x - shag;
  126. break;
  127. case 2: y = y - shag;
  128. break;
  129. case 3: x = x + shag;
  130. break;
  131. }
  132.  
  133. }
  134.  
  135. }
  136.  
  137. void povorot(string napr)
  138. {
  139. deleteturtele();
  140. if (napr == "vpravo")
  141. {
  142. z++;
  143. if (z == 4)
  144. {
  145. z = 0;
  146. }
  147. }
  148. if (napr == "vlevo")
  149. {
  150. z--;
  151. if (z == -1)
  152. {
  153. z = 3;
  154. }
  155. }
  156. }
  157.  
  158. void povtor(int kol, string d1, string d2)
  159. {
  160. if (d1 == "povorot")
  161. for (int i = 0; i < kol; i++)
  162. {
  163. povorot(d2);
  164. }
  165. if ((d1 == "vpered") or (d1 == "nazad") or (d1 == "vpravo") or (d1 == "vlevo"))
  166. {
  167. for (int i = 0; i < kol; i++)
  168. move(d1, atoi(d2.c_str()));
  169. }
  170.  
  171. }
  172.  
  173.  
  174.  
  175. void drawmap() //заполнение массива map
  176. {
  177.  
  178. for (int i = 0; i < b; i++)
  179. {
  180. map[0][i] = '#';
  181. }
  182. for (int i = 1; i < a - 1; i++)
  183. for (int j = 0; j < b; j++)
  184. {
  185. if ((j == 0) || (j == b - 1))
  186. map[i][j] = '#';
  187. if ((i == y) && (j == x))
  188. drawturtele(y, x, z);
  189.  
  190. }
  191. for (int i = 0; i < b; i++)
  192. {
  193. map[a - 1][i] = '#';
  194. }
  195. }
  196.  
  197. void draw() //вывод массива map
  198. {
  199. for (int i = 0; i < a; i++)
  200. {
  201. for (int j = 0; j < b; j++)
  202. {
  203. cout << map[i][j];
  204. }
  205. cout << endl;
  206. }
  207. }
  208.  
  209.  
  210.  
  211.  
  212. int main()
  213. {
  214. drawmap();
  215. draw();
  216. string lala;
  217. string buffer[4];
  218. int buff = 0;
  219. int w = 100;
  220. while (w)
  221. {
  222. cout<<"Komandi:\npovorot vlevo, vpravo.\nvpered n, nazad n, vlevo n, vpravo n\npovtori n komanda.";
  223. getline(cin, lala);
  224. int k = 0;
  225. for (int i = 0; i < lala.length(); i++)
  226. {
  227. if (lala[i] != ' ')
  228. {
  229. buffer[k] += lala[i];
  230. }
  231. else k++;
  232. }
  233.  
  234. if (buffer[0] == "povorot")
  235. {
  236. povorot(buffer[1]);
  237. }
  238.  
  239. if ((buffer[0] == "vpered") or (buffer[0] == "vpravo") or (buffer[0] == "vlevo") or (buffer[0] == "nazad"))
  240. {
  241. move(buffer[0], atoi(buffer[1].c_str()));
  242. }
  243.  
  244. if (buffer[0] == "povtori")
  245. {
  246. povtor(atoi(buffer[1].c_str()), buffer[2], buffer[3]);
  247. }
  248.  
  249. if (lala == "Vixod")
  250. return 0;
  251.  
  252. lala = "";
  253. for (int i = 0; i < 4; i++)
  254. buffer[i] = "";
  255. system("cls");
  256. drawmap();
  257. draw();
  258.  
  259. }
  260.  
  261.  
  262.  
  263.  
  264.  
  265. system("pause");
  266. return 0;
  267. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement