Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace _02.Sneaking
- {
- class Program
- {
- static void Main()
- {
- //Initial setup and room(matrix) setup
- var rows = int.Parse(Console.ReadLine());
- var room = new char[rows][];
- var samRow = 0;
- var samIndex = 0;
- for (int i = 0; i < rows; i++)
- {
- char[] layout = Console.ReadLine().ToArray();
- room[i] = layout;
- for (int j = 0; j < room[i].Length; j++)
- {
- if (room[i][j] == 'S')
- {
- samRow = i;
- samIndex = j;
- }
- }
- }
- //Getting the moves and starting the game
- var moves = Console.ReadLine();
- var nRow = 0;
- var nIndex = 0;
- foreach (var move in moves)
- {
- for (int i = 0; i < rows; i++)
- {
- //Move enemies and set Nikoladze's position
- for (int j = 0; j < room[i].Length; j++)
- {
- //Set Nikoladze's position
- if (room[i].ElementAt(j) == 'N')
- {
- nRow = i;
- nIndex = j;
- }
- //Enemies 'd' Ai
- if (room[i].ElementAt(j) == 'd')
- {
- var enemyRow = i;
- var enemyIndex = j;
- if (enemyIndex == 0)
- {
- room[i][j] = 'b';
- }
- else
- {
- room[i][j] = '.';
- room[i][j - 1] = 'd';
- }
- continue;
- }
- //Enemies 'b' Ai
- if (room[i].ElementAt(j) == 'b')
- {
- var enemyRow = i;
- var enemyIndex = j;
- if (enemyIndex == room[i].Length - 1)
- {
- room[i][j] = 'd';
- }
- else
- {
- room[i][j] = '.';
- room[i][j + 1] = 'b';
- j++;
- }
- }
- }
- }
- //Move Sam
- if (move == 'U')
- {
- for (int i = 0; i < samIndex; i++)
- {
- if (room[samRow][i] == 'b')
- {
- //tuka pravish console write line i resultati i laina shtoto Sam umira
- return;
- }
- }
- for (int i = samIndex + 1; i < room[samRow].Length; i++)
- {
- if (room[samRow][i] == 'd')
- {
- //tuka pravish console write line i resultati i laina shtoto Sam umira
- return;
- }
- }
- room[samRow][samIndex] = '.';
- samRow--;
- room[samRow][samIndex] = 'S';
- if (samRow == nRow)
- {
- room[nRow][nIndex] = 'X';
- //tuka umira Nikoladze i pak pishes resultata
- return;
- }
- }
- if (move == 'D')
- {
- for (int i = 0; i < samIndex; i++)
- {
- if (room[samRow][i] == 'b')
- {
- //tuka pravish console write line i resultati i laina shtoto Sam umira
- return;
- }
- }
- for (int i = samIndex + 1; i < room[samRow].Length; i++)
- {
- if (room[samRow][i] == 'd')
- {
- //tuka pravish console write line i resultati i laina shtoto Sam umira
- return;
- }
- }
- room[samRow][samIndex] = '.';
- samRow++;
- room[samRow][samIndex] = 'S';
- if (samRow == nRow)
- {
- room[nRow][nIndex] = 'X';
- //tuka umira Nikoladze i pak pishes resultata
- return;
- }
- }
- if (move == 'L')
- {
- for (int i = 0; i < samIndex; i++)
- {
- if (room[samRow][i] == 'b')
- {
- //tuka pravish console write line i resultati i laina shtoto Sam umira
- return;
- }
- }
- for (int i = samIndex + 1; i < room[samRow].Length; i++)
- {
- if (room[samRow][i] == 'd')
- {
- //tuka pravish console write line i resultati i laina shtoto Sam umira
- return;
- }
- }
- room[samRow][samIndex] = '.';
- samIndex--;
- room[samRow][samIndex] = 'S';
- if (samRow == nRow)
- {
- room[nRow][nIndex] = 'X';
- //tuka umira Nikoladze i pak pishes resultata
- return;
- }
- }
- if (move == 'R')
- {
- for (int i = 0; i < samIndex; i++)
- {
- if (room[samRow][i] == 'b')
- {
- //tuka pravish console write line i resultati i laina shtoto Sam umira
- return;
- }
- }
- for (int i = samIndex + 1; i < room[samRow].Length; i++)
- {
- if (room[samRow][i] == 'd')
- {
- //tuka pravish console write line i resultati i laina shtoto Sam umira
- return;
- }
- }
- room[samRow][samIndex] = '.';
- samIndex++;
- room[samRow][samIndex] = 'S';
- if (samRow == nRow)
- {
- room[nRow][nIndex] = 'X';
- //tuka umira Nikoladze i pak pishes resultata
- return;
- }
- }
- if (move == 'W')
- {
- for (int i = 0; i < samIndex; i++)
- {
- if (room[samRow][i] == 'b')
- {
- //tuka pravish console write line i resultati i laina shtoto Sam umira
- return;
- }
- }
- for (int i = samIndex + 1; i < room[samRow].Length; i++)
- {
- if (room[samRow][i] == 'd')
- {
- //tuka pravish console write line i resultati i laina shtoto Sam umira
- return;
- }
- }
- if (samRow == nRow)
- {
- room[nRow][nIndex] = 'X';
- //tuka umira Nikoladze i pak pishes resultata
- return;
- }
- }
- }
- /* TUK SA METODITE KOITO AKO BESHE POGLEDNAL ZA 1MINUTA SHTESHE DA RAZBERESH
- //Print Result function
- void PrintResult()
- {
- foreach (var row in room)
- {
- if (row.Contains('S'))
- {
- Console.WriteLine("Nikoladze killed!");
- break;
- }
- if (row.Contains('N'))
- {
- Console.WriteLine($"Sam died at {samRow}, {samIndex}");
- break;
- }
- }
- foreach (var row in room)
- {
- Console.WriteLine(row);
- }
- return;
- }
- //Caugth by enemy
- bool CaughtByEnemy(char[][] field, int rowSam, int colSam)
- {
- for (int col = 0; col < colSam; col++)
- {
- if (field[rowSam][col] == 'b')
- {
- return true;
- }
- }
- for (int col = colSam + 1; col < field[rowSam].Length; col++)
- {
- if (field[rowSam][col] == 'd')
- {
- return true;
- }
- }
- return false;
- }
- //Nikoladze killed
- bool NikoladzeKilled()
- {
- if (samRow == nRow)
- {
- room[nRow][nIndex] = 'X';
- return true;
- }
- return false;
- }*/
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement