Advertisement
Guest User

Untitled

a guest
Sep 25th, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.26 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace _8.RadioActiveBunnies
  6. {
  7. class Program
  8. {
  9. static void Main(string[] args)
  10. {
  11. int[] input = Console.ReadLine().Split(' ', StringSplitOptions.RemoveEmptyEntries).Select(int.Parse).ToArray();
  12. int rows = input[0];
  13. int columns = input[1];
  14.  
  15. char[,] lair = new char[rows, columns];
  16.  
  17. string winOrLose = string.Empty;
  18. bool deadPlayer = false;
  19. for (int i = 0; i < rows; i++)
  20. {
  21. char[] symbols = Console.ReadLine().ToCharArray();
  22. for (int j = 0; j < columns; j++)
  23. {
  24. lair[i, j] = symbols[j];
  25. }
  26. }
  27. char[] directions = Console.ReadLine().ToCharArray();
  28.  
  29. int endRow = -1;
  30. int endColumn = -1;
  31. for (int i = 0; i < directions.Length; i++)
  32. {
  33. int playerRow = -1;
  34. int playerColumn = -1;
  35.  
  36. if (directions[i] == 'L')
  37. {
  38. for (int k = 0; k < lair.GetLength(0); k++)
  39. {
  40. for (int l = 0; l < lair.GetLength(1); l++)
  41. {
  42. if (lair[k, l] == 'P')
  43. {
  44. playerRow = k;
  45. playerColumn = l;
  46. break;
  47. }
  48. }
  49. if (playerRow != -1)
  50. {
  51. break;
  52. }
  53. }
  54. lair[playerRow, playerColumn] = '.';
  55.  
  56. if (playerColumn - 1 < 0)
  57. {
  58. endRow = playerRow;
  59. endColumn = playerColumn;
  60. winOrLose = "won";
  61.  
  62. }
  63. else
  64. {
  65. if (lair[playerRow, playerColumn - 1] == 'B' || lair[playerRow, playerColumn - 1] == 'N')
  66. {
  67. winOrLose = "dead";
  68. endRow = playerRow;
  69. endColumn = playerColumn - 1;
  70. deadPlayer = true;
  71. }
  72. else
  73. {
  74. lair[playerRow, playerColumn - 1] = 'P';
  75. }
  76.  
  77. }
  78. }
  79.  
  80. if (directions[i] == 'R')
  81. {
  82. for (int k = 0; k < lair.GetLength(0); k++)
  83. {
  84. for (int l = 0; l < lair.GetLength(1); l++)
  85. {
  86. if (lair[k, l] == 'P')
  87. {
  88. playerRow = k;
  89. playerColumn = l;
  90. break;
  91. }
  92. }
  93. if (playerRow != -1)
  94. {
  95. break;
  96. }
  97. }
  98.  
  99. lair[playerRow, playerColumn] = '.';
  100.  
  101. if (playerColumn + 1 > lair.GetLength(1) - 1)
  102. {
  103. endRow = playerRow;
  104. endColumn = playerColumn;
  105. winOrLose = "won";
  106.  
  107. }
  108. else
  109. {
  110. if (lair[playerRow, playerColumn + 1] == 'B' || lair[playerRow, playerColumn - 1] == 'N')
  111. {
  112. winOrLose = "dead";
  113. endRow = playerRow;
  114. endColumn = playerColumn + 1;
  115. deadPlayer = true;
  116. }
  117. else
  118. {
  119. lair[playerRow, playerColumn + 1] = 'P';
  120. }
  121.  
  122. }
  123. }
  124.  
  125. if (directions[i] == 'U')
  126. {
  127. for (int k = 0; k < lair.GetLength(0); k++)
  128. {
  129. for (int l = 0; l < lair.GetLength(1); l++)
  130. {
  131. if (lair[k, l] == 'P')
  132. {
  133. playerRow = k;
  134. playerColumn = l;
  135. break;
  136. }
  137. }
  138. if (playerRow != -1)
  139. {
  140. break;
  141. }
  142. }
  143. lair[playerRow, playerColumn] = '.';
  144.  
  145. if (playerRow - 1 < 0)
  146. {
  147. endRow = playerRow;
  148. endColumn = playerColumn;
  149. winOrLose = "won";
  150.  
  151. }
  152. else
  153. {
  154. if (lair[playerRow - 1, playerColumn] == 'B' || lair[playerRow, playerColumn - 1] == 'N')
  155. {
  156. winOrLose = "dead";
  157. endRow = playerRow - 1;
  158. endColumn = playerColumn;
  159. deadPlayer = true;
  160. }
  161. else
  162. {
  163. lair[playerRow - 1, playerColumn] = 'P';
  164. }
  165. }
  166. }
  167.  
  168. if (directions[i] == 'D')
  169. {
  170. for (int k = 0; k < lair.GetLength(0); k++)
  171. {
  172. for (int l = 0; l < lair.GetLength(1); l++)
  173. {
  174. if (lair[k, l] == 'P')
  175. {
  176. playerRow = k;
  177. playerColumn = l;
  178. break;
  179. }
  180. }
  181. if (playerRow != -1)
  182. {
  183. break;
  184. }
  185. }
  186.  
  187. lair[playerRow, playerColumn] = '.';
  188.  
  189. if (playerRow + 1 > lair.GetLength(0) - 1)
  190. {
  191.  
  192. endRow = playerRow;
  193. endColumn = playerColumn;
  194. winOrLose = "won";
  195.  
  196. }
  197. else
  198. {
  199. if (lair[playerRow + 1, playerColumn] == 'B' || lair[playerRow, playerColumn - 1] == 'N')
  200. {
  201. winOrLose = "dead";
  202. endRow = playerRow + 1;
  203. endColumn = playerColumn;
  204. deadPlayer = true;
  205. }
  206. else
  207. {
  208. lair[playerRow + 1, playerColumn] = 'P';
  209. }
  210.  
  211. }
  212. }
  213.  
  214.  
  215. bool checkerForPlayer = false;
  216. for (int p = 0; p < lair.GetLength(0); p++)
  217. {
  218. for (int b = 0; b < lair.GetLength(1); b++)
  219. {
  220. if (lair[p, b] == 'B')
  221. {
  222. int bunnyRow = p;
  223. int bunnyColumn = b;
  224.  
  225. if (bunnyRow - 1 >= 0)
  226. {
  227. if (lair[bunnyRow - 1, bunnyColumn] == 'P')
  228. {
  229. checkerForPlayer = true;
  230. endRow = bunnyRow - 1;
  231. endColumn = bunnyColumn;
  232. winOrLose = "dead";
  233. }
  234.  
  235. lair[bunnyRow - 1, bunnyColumn] = 'N';
  236. }
  237. if (bunnyRow + 1 < lair.GetLength(0))
  238. {
  239. if (lair[bunnyRow + 1, bunnyColumn] == 'P')
  240. {
  241. checkerForPlayer = true;
  242. endRow = bunnyRow + 1;
  243. endColumn = bunnyColumn;
  244. winOrLose = "dead";
  245. }
  246.  
  247. lair[bunnyRow + 1, bunnyColumn] = 'N';
  248. }
  249. if (bunnyColumn - 1 >= 0)
  250. {
  251. if (lair[bunnyRow, bunnyColumn - 1] == 'P')
  252. {
  253. checkerForPlayer = true;
  254. endRow = bunnyRow;
  255. endColumn = bunnyColumn - 1;
  256. winOrLose = "dead";
  257. }
  258.  
  259. lair[bunnyRow, bunnyColumn - 1] = 'N';
  260. }
  261. if (bunnyColumn + 1 < lair.GetLength(1))
  262. {
  263. if (lair[bunnyRow, bunnyColumn + 1] == 'P')
  264. {
  265. checkerForPlayer = true;
  266. endRow = bunnyRow;
  267. endColumn = bunnyColumn + 1;
  268. winOrLose = "dead";
  269. }
  270.  
  271. lair[bunnyRow, bunnyColumn + 1] = 'N';
  272. }
  273.  
  274.  
  275. }
  276. }
  277. }
  278. for (int a = 0; a < lair.GetLength(0); a++)
  279. {
  280. for (int s = 0; s < lair.GetLength(1); s++)
  281. {
  282. if (lair[a, s] == 'N')
  283. {
  284. lair[a, s] = 'B';
  285. }
  286. }
  287. }
  288.  
  289. if (checkerForPlayer == true)
  290. {
  291. break;
  292. }
  293. if (deadPlayer)
  294. {
  295. break;
  296. }
  297. if (winOrLose == "won" || winOrLose == "dead")
  298. {
  299. break;
  300. }
  301.  
  302. }
  303.  
  304. for (int i = 0; i < lair.GetLength(0); i++)
  305. {
  306. for (int j = 0; j < lair.GetLength(1); j++)
  307. {
  308. Console.Write(lair[i, j]);
  309. }
  310. Console.WriteLine();
  311. }
  312. Console.WriteLine($"{winOrLose}: {endRow} {endColumn}");
  313.  
  314.  
  315. }
  316. }
  317. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement