Advertisement
Guest User

02

a guest
Oct 21st, 2018
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 5.35 KB | None | 0 0
  1. namespace _02._Sneaking
  2. {
  3.     using System;
  4.  
  5.     public class Sneaking
  6.     {
  7.         public static void Main()
  8.         {
  9.             int n = int.Parse(Console.ReadLine()); // начално число
  10.  
  11.             char[][] room = new char[n][]; // нов назъбен масив със Н-редици
  12.  
  13.             int samRow = -1; // координатите на Сам
  14.             int samCol = -1;
  15.  
  16.             int nikoladzeRow = -1; // координатите на Нико
  17.             int nikoladzeCol = -1;
  18.  
  19.             FillTheRoom();
  20.  
  21.             for (int i = 0; i < n; i++)
  22.             {
  23.                 room[i] = Console.ReadLine().ToCharArray(); // четене на матрицата от конзолата
  24.                 for (int j = 0; j < room[i].Length; j++) // минаване през настоящия ред
  25.                 {
  26.                     if (room[i][j] == 'S') // ако видиш Сам - запази му координатите
  27.                     {
  28.                         samCol = j;
  29.                         samRow = i;
  30.                         room[i][j] = '.'; // сложи точка на мястото на Сам вместо S, после ще се принтира
  31.                     }
  32.                     else if (room[i][j] == 'N') // ако видиш Нико
  33.                     {
  34.                         nikoladzeRow = i; // запази и неговите
  35.                         nikoladzeCol = j;
  36.                     }
  37.                 }
  38.             }
  39.  
  40.             string directions = Console.ReadLine(); // четене на посоки
  41.  
  42.             foreach (char direction in directions)
  43.             {
  44.                 // Move enemies
  45.                 bool[,] movedThisTurn = new bool[n, room[0].Length];
  46.  
  47.                 for (int row = 0; row < n; row++) // минава през всяка една от редиците
  48.                 {
  49.                     for (int col = 0; col < room[row].Length; col++) // и колоните
  50.                     {
  51.                         if (movedThisTurn[row, col])
  52.                         {
  53.                             continue;
  54.                         }
  55.                         if (room[row][col] == 'b') // ако на реда има 'b'
  56.                         {
  57.                             if (col == room[row].Length - 1) // ако б се намира в края
  58.                             {
  59.                                 room[row][col] = 'd'; // превърни го в д
  60.                             }
  61.                             else // ако не е в края
  62.                             {
  63.                                 room[row][col] = '.'; // направи мястото зад него на точка
  64.                                 room[row][col + 1] = 'b'; // и мястото вд
  65.                                 movedThisTurn[row, col + 1] = true;
  66.                             }
  67.                         }
  68.                         else if (room[row][col] == 'd')
  69.                         {
  70.                             if (col == 0)
  71.                             {
  72.                                 room[row][col] = 'b';
  73.                             }
  74.                             else
  75.                             {
  76.                                 room[row][col] = '.';
  77.                                 room[row][col - 1] = 'd';
  78.                                 movedThisTurn[row, col - 1] = true;
  79.                             }
  80.                         }
  81.  
  82.                     }
  83.                 }
  84.  
  85.                 // Check if Sam should die
  86.                 bool samDead = false;
  87.                 for (int col = 0; col < room[samRow].Length; col++)
  88.                 {
  89.                     if (room[samRow][col] == 'b' && samCol > col ||
  90.                         room[samRow][col] == 'd' && samCol < col)
  91.                     {
  92.                         samDead = true;
  93.                         break;
  94.                     }
  95.                 }
  96.  
  97.                 if (samDead)
  98.                 {
  99.                     room[samRow][samCol] = 'X';
  100.                     Console.WriteLine($"Sam died at {samRow}, {samCol}");
  101.                     break;
  102.                 }
  103.  
  104.                 // Move Sam
  105.  
  106.                 if (direction == 'U')
  107.                 {
  108.                     samRow--;
  109.                 }
  110.                 else if (direction == 'D')
  111.                 {
  112.                     samRow++;
  113.                 }
  114.                 else if (direction == 'L')
  115.                 {
  116.                     samCol--;
  117.                 }
  118.                 else if (direction == 'R')
  119.                 {
  120.                     samCol++;
  121.                 }
  122.  
  123.                 // Check if Sam kills Nikoladze
  124.  
  125.                 if (samRow == nikoladzeRow)
  126.                 {
  127.                     room[nikoladzeRow][nikoladzeCol] = 'X';
  128.                     room[samRow][samCol] = 'S';
  129.                     Console.WriteLine("Nikoladze killed!");
  130.                     break;
  131.                 }
  132.  
  133.                 // Remove enemy if killed by Sam
  134.  
  135.                 room[samRow][samCol] = '.';
  136.             }
  137.  
  138.             for (int row = 0; row < n; row++)
  139.             {
  140.                 Console.WriteLine(new string(room[row]));
  141.             }
  142.         }
  143.  
  144.         private static void FillTheRoom()
  145.         {
  146.             throw new NotImplementedException();
  147.         }
  148.     }
  149. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement