Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- namespace _02._Sneaking
- {
- using System;
- public class Sneaking
- {
- public static void Main()
- {
- int n = int.Parse(Console.ReadLine()); // начално число
- char[][] room = new char[n][]; // нов назъбен масив със Н-редици
- int samRow = -1; // координатите на Сам
- int samCol = -1;
- int nikoladzeRow = -1; // координатите на Нико
- int nikoladzeCol = -1;
- FillTheRoom();
- for (int i = 0; i < n; i++)
- {
- room[i] = Console.ReadLine().ToCharArray(); // четене на матрицата от конзолата
- for (int j = 0; j < room[i].Length; j++) // минаване през настоящия ред
- {
- if (room[i][j] == 'S') // ако видиш Сам - запази му координатите
- {
- samCol = j;
- samRow = i;
- room[i][j] = '.'; // сложи точка на мястото на Сам вместо S, после ще се принтира
- }
- else if (room[i][j] == 'N') // ако видиш Нико
- {
- nikoladzeRow = i; // запази и неговите
- nikoladzeCol = j;
- }
- }
- }
- string directions = Console.ReadLine(); // четене на посоки
- foreach (char direction in directions)
- {
- // Move enemies
- bool[,] movedThisTurn = new bool[n, room[0].Length];
- for (int row = 0; row < n; row++) // минава през всяка една от редиците
- {
- for (int col = 0; col < room[row].Length; col++) // и колоните
- {
- if (movedThisTurn[row, col])
- {
- continue;
- }
- if (room[row][col] == 'b') // ако на реда има 'b'
- {
- if (col == room[row].Length - 1) // ако б се намира в края
- {
- room[row][col] = 'd'; // превърни го в д
- }
- else // ако не е в края
- {
- room[row][col] = '.'; // направи мястото зад него на точка
- room[row][col + 1] = 'b'; // и мястото вд
- movedThisTurn[row, col + 1] = true;
- }
- }
- else if (room[row][col] == 'd')
- {
- if (col == 0)
- {
- room[row][col] = 'b';
- }
- else
- {
- room[row][col] = '.';
- room[row][col - 1] = 'd';
- movedThisTurn[row, col - 1] = true;
- }
- }
- }
- }
- // Check if Sam should die
- bool samDead = false;
- for (int col = 0; col < room[samRow].Length; col++)
- {
- if (room[samRow][col] == 'b' && samCol > col ||
- room[samRow][col] == 'd' && samCol < col)
- {
- samDead = true;
- break;
- }
- }
- if (samDead)
- {
- room[samRow][samCol] = 'X';
- Console.WriteLine($"Sam died at {samRow}, {samCol}");
- break;
- }
- // Move Sam
- if (direction == 'U')
- {
- samRow--;
- }
- else if (direction == 'D')
- {
- samRow++;
- }
- else if (direction == 'L')
- {
- samCol--;
- }
- else if (direction == 'R')
- {
- samCol++;
- }
- // Check if Sam kills Nikoladze
- if (samRow == nikoladzeRow)
- {
- room[nikoladzeRow][nikoladzeCol] = 'X';
- room[samRow][samCol] = 'S';
- Console.WriteLine("Nikoladze killed!");
- break;
- }
- // Remove enemy if killed by Sam
- room[samRow][samCol] = '.';
- }
- for (int row = 0; row < n; row++)
- {
- Console.WriteLine(new string(room[row]));
- }
- }
- private static void FillTheRoom()
- {
- throw new NotImplementedException();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement