Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Linq;
- using System.Text;
- using System.Collections.Generic;
- using System.Text.RegularExpressions;
- namespace Exercise
- {
- class Program
- {
- public static void Main(string[] args)
- {
- int parisEnergy = int.Parse(Console.ReadLine());
- int sizeOfMatrix = int.Parse(Console.ReadLine());
- var matrix = new char[sizeOfMatrix, sizeOfMatrix];
- int parisRow = int.MinValue;
- int parisCol = int.MinValue;
- for (int row = 0; row < matrix.GetLength(0); row++)
- {
- string currentRow = Console.ReadLine();
- for (int col = 0; col < matrix.GetLength(1); col++)
- {
- matrix[row, col] = currentRow[col];
- if (currentRow[col] == 'P')
- {
- parisRow = row;
- parisCol = col;
- }
- }
- }
- matrix[parisRow, parisCol] = '-';
- while (true)
- {
- var enemySpawn = Console.ReadLine()
- .Split(" ", StringSplitOptions.RemoveEmptyEntries)
- .ToArray();
- string parisDirection = enemySpawn[0];
- int enemyRow = int.Parse(enemySpawn[1]);
- int enemyCol = int.Parse(enemySpawn[2]);
- if (enemyRow >= 0 && enemyRow < matrix.GetLength(0) &&
- enemyCol >= 0 && enemyCol < matrix.GetLength(1))
- {
- matrix[enemyRow, enemyCol] = 'S';
- }
- parisEnergy--;
- if (parisDirection == "up")
- {
- if (parisRow - 1 >= 0 && parisRow - 1 < matrix.GetLength(0))
- {
- parisRow--;
- }
- }
- else if (parisDirection == "down")
- {
- if (parisRow + 1 >= 0 && parisRow + 1 < matrix.GetLength(0))
- {
- parisRow++;
- }
- }
- else if (parisDirection == "left")
- {
- if (parisCol - 1 >= 0 && parisCol - 1 < matrix.GetLength(1))
- {
- parisCol--;
- }
- }
- else if (parisDirection == "right")
- {
- if (parisCol + 1 >= 0 && parisCol + 1 < matrix.GetLength(1))
- {
- parisCol++;
- }
- }
- if (matrix[parisRow, parisCol] == 'H')
- {
- matrix[parisRow, parisCol] = '-';
- Console.WriteLine($"Paris has successfully abducted Helen! Energy left: {parisEnergy}");
- break;
- }
- if (matrix[parisRow, parisCol] == 'S')
- {
- if (parisEnergy - 2 > 0)
- {
- parisEnergy -= 2;
- matrix[parisRow, parisCol] = '-';
- }
- else
- {
- matrix[parisRow, parisCol] = 'X';
- Console.WriteLine($"Paris died at {parisRow};{parisCol}.");
- break;
- }
- }
- }
- PrintMatrix(matrix);
- }
- private static void PrintMatrix(char[,] matrix)
- {
- for (int row = 0; row < matrix.GetLength(0); row++)
- {
- for (int col = 0; col < matrix.GetLength(1); col++)
- {
- Console.Write(matrix[row, col]);
- }
- Console.WriteLine();
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement