bullit3189

Sneaking

May 30th, 2019
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.73 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3. using System.Collections.Generic;
  4. using System.Text;
  5.  
  6. public class Program
  7. {
  8.  
  9. public static void Main()
  10. {
  11. int rows = int.Parse(Console.ReadLine());
  12.  
  13. char[][]jagged = new char[rows][];
  14.  
  15. int samRow = -1;
  16. int samCol = -1;
  17. int nikoRow = -1;
  18. int nikoCol = -1;
  19.  
  20. for(int row=0; row<rows; row++)
  21. {
  22. string currRow = Console.ReadLine();
  23. jagged[row] = new char[currRow.Length];
  24.  
  25. for(int col=0; col<jagged[row].Length; col++)
  26. {
  27. jagged[row][col] = currRow[col];
  28.  
  29. if(jagged[row][col] == 'S')
  30. {
  31. samRow = row;
  32. samCol = col;
  33. }
  34. else if (jagged[row][col] == 'N')
  35. {
  36. nikoRow = row;
  37. nikoCol = col;
  38. }
  39. }
  40. }
  41.  
  42. jagged[samRow][samCol] = '.';
  43.  
  44. char[] commands = Console.ReadLine().ToCharArray();
  45.  
  46. foreach(var command in commands)
  47. {
  48. EnemiesMoves(jagged);
  49.  
  50. if(KillSam (jagged, samRow,samCol))
  51. {
  52. jagged[samRow][samCol]='X';
  53. Console.WriteLine("Sam died at {0}, {1}",samRow,samCol);
  54. PrintMatrix (jagged);
  55. return;
  56. }
  57.  
  58. switch(command)
  59. {
  60. case 'U': samRow--; break;
  61. case 'D': samRow++; break;
  62. case 'L': samCol--; break;
  63. case 'R': samCol++; break;
  64. }
  65.  
  66. if(samRow == nikoRow)
  67. {
  68. jagged[nikoRow][nikoCol] = 'X';
  69. jagged[samRow][samCol] = 'S';
  70. Console.WriteLine("Nikoladze killed!");
  71. PrintMatrix (jagged);
  72. return;
  73. }
  74. else if (jagged[samRow][samCol] == 'b' || jagged[samRow][samCol] == 'd')
  75. {
  76. jagged[samRow][samCol] = '.';
  77. }
  78. }
  79. }
  80. public static void PrintMatrix (char[][] jagged)
  81. {
  82. foreach (var row in jagged)
  83. {
  84. Console.WriteLine(row);
  85. }
  86. }
  87.  
  88.  
  89. public static bool KillSam (char[][] jagged,int samRow, int samCol)
  90. {
  91. if(jagged[samRow].Contains('b'))
  92. {
  93. int colIndex = Array.IndexOf(jagged[samRow],'b');
  94.  
  95. if(samCol>colIndex)
  96. {
  97. return true;
  98. }
  99. }
  100. else if (jagged[samRow].Contains('d'))
  101. {
  102. int colIndex = Array.IndexOf(jagged[samRow],'d');
  103.  
  104. if(samCol<colIndex)
  105. {
  106. return true;
  107. }
  108. }
  109. return false;
  110. }
  111.  
  112. public static void EnemiesMoves (char[][] jagged)
  113. {
  114. for(int row=0; row<jagged.Length; row++)
  115. {
  116. for(int col=0; col<jagged[row].Length; col++)
  117. {
  118. if(jagged[row][col]=='b')
  119. {
  120. jagged[row][col]='.';
  121.  
  122. if(col==jagged[row].Length-1)
  123. {
  124. jagged[row][col]='d';
  125. }
  126. else
  127. {
  128. jagged[row][col+1]='b';
  129. break;
  130. }
  131. }
  132. else if (jagged[row][col]=='d')
  133. {
  134. jagged[row][col]='.';
  135.  
  136. if(col==0)
  137. {
  138. jagged[row][col]='b';
  139. }
  140. else
  141. {
  142. jagged[row][col-1]='d';
  143. }
  144. }
  145. }
  146. }
  147. }
  148. }
Add Comment
Please, Sign In to add comment