Beispiel #1
0
 private static void FindSam(int row, int col)
 {
     if (room[row][col] == 'S')
     {
         sam = new Sam(row, col);
     }
 }
Beispiel #2
0
        private static void MoveSam(char[][] room, Sam sam, char[] moves, int i)
        {
            room[sam.Row][sam.Col] = '.';
            switch (moves[i])
            {
            case 'U':
                sam.Row--;
                break;

            case 'D':
                sam.Row++;
                break;

            case 'L':
                sam.Col--;
                break;

            case 'R':
                sam.Col++;
                break;

            default:
                break;
            }
            room[sam.Row][sam.Col] = 'S';
        }
Beispiel #3
0
 public void SamIntercept(int[] getEnemy, Room room, Sam sam)
 {
     if (room.room[getEnemy[0]][getEnemy[1]] == 'N' && sam.Row == getEnemy[0])
     {
         room.room[getEnemy[0]][getEnemy[1]] = 'X';
         Console.WriteLine("Nikoladze killed!");
         room.PrintingRoom();
         return;
     }
 }
Beispiel #4
0
        public int[] GetEnemy(char[][] room, Sam sam)
        {
            int[] getEnemy = new int[2];
            for (int j = 0; j < room[sam.Row].Length; j++)
            {
                if (room[sam.Row][j] != '.' && room[sam.Row][j] != 'S')
                {
                    getEnemy[0] = sam.Row;

                    getEnemy[1] = j;
                }
            }
            return(getEnemy);
        }
Beispiel #5
0
        static void Main()
        {
            int rows = int.Parse(Console.ReadLine());

            room = InitializeRoom(rows);

            var moves = Console.ReadLine().ToCharArray();

            sam = GetSamPosition(room);

            for (int i = 0; i < moves.Length; i++)
            {
                MoveGuards(room);

                int[] getEnemy     = new int[2];
                bool  isSamSpotted = CheckIfSamSpotted(room, getEnemy);
                if (isSamSpotted)
                {
                    break;
                }

                MoveSam(room, sam, moves, i);

                for (int j = 0; j < room[sam.Row].Length; j++)
                {
                    if (room[sam.Row][j] != '.' && room[sam.Row][j] != 'S')
                    {
                        getEnemy[0] = sam.Row;
                        getEnemy[1] = j;
                    }
                }

                if (room[getEnemy[0]][getEnemy[1]] == 'N' && sam.Row == getEnemy[0])
                {
                    room[getEnemy[0]][getEnemy[1]] = 'X';
                    Console.WriteLine("Nikoladze killed!");
                    for (int row = 0; row < room.Length; row++)
                    {
                        for (int col = 0; col < room[row].Length; col++)
                        {
                            Console.Write(room[row][col]);
                        }
                        Console.WriteLine();
                    }

                    break;
                }
            }
        }
Beispiel #6
0
 public void EnemyIntercept(Sam sam, int[] getEnemy, Room room)
 {
     if (sam.Col < getEnemy[1] && room.room[getEnemy[0]][getEnemy[1]] == 'd' && getEnemy[0] == sam.Row)
     {
         room.room[sam.Row][sam.Col] = 'X';
         Console.WriteLine($"Sam died at {sam.Row}, {sam.Col}");
         room.PrintingRoom();
     }
     else if (getEnemy[1] < sam.Col && room.room[getEnemy[0]][getEnemy[1]] == 'b' && getEnemy[0] == sam.Row)
     {
         room.room[sam.Row][sam.Col] = 'X';
         Console.WriteLine($"Sam died at {sam.Row}, {sam.Col}");
         room.PrintingRoom();
     }
 }
Beispiel #7
0
        private static Sam GetSamPosition(char[][] room)
        {
            Sam sam = new Sam();

            for (int row = 0; row < room.Length; row++)
            {
                for (int col = 0; col < room[row].Length; col++)
                {
                    if (room[row][col] == 'S')
                    {
                        sam.Row = row;
                        sam.Col = col;
                    }
                }
            }

            return(sam);
        }
Beispiel #8
0
        public void StartMission()
        {
            Nikoladze.FindPosition(matrix);
            Sam.FindPostion(matrix);

            while (Sam.Directions.Count > 0)
            {
                Guard.MoveGuards(matrix);
                Sam.IsAlive(matrix);

                var direction = Sam.Directions.Dequeue();
                Sam.Move(matrix, direction);

                if (Sam.Row == Nikoladze.Row)
                {
                    Nikoladze.SamWon(matrix);
                    Sam.MissionOver("Nikoladze killed!", matrix);
                }
            }
        }
Beispiel #9
0
 public Engine(int rows)
 {
     this.newEnemy = new Enemy();
     this.newRoom  = new Room(rows);
     this.sam      = new Sam(this.newRoom.room);
 }
Beispiel #10
0
        public static void Main()
        {
            int n = int.Parse(Console.ReadLine());

            char[][] matrix = new char[n][];

            for (int i = 0; i < n; i++)
            {
                matrix[i] = Console.ReadLine().ToCharArray();
            }

            int samRow = 0;
            int samCol = 0;

            for (int i = 0; i < matrix.Length; i++)
            {
                samCol = Array.IndexOf(matrix[i], 'S');
                if (samCol != -1)
                {
                    samRow = i;
                    break;
                }
            }

            int nikolaiRow = 0;
            int nikolaiCol = 0;

            for (int i = 0; i < matrix.Length; i++)
            {
                nikolaiCol = Array.IndexOf(matrix[i], 'N');
                if (nikolaiCol != -1)
                {
                    nikolaiRow = i;
                    break;
                }
            }

            var commands = Console.ReadLine().ToCharArray();

            var sam = new Sam
            {
                X = samRow,
                Y = samCol
            };

            for (int i = 0; i < commands.Length; i++)
            {
                int oldRow = samRow;
                int oldCol = samCol;

                char command = commands[i];

                MovingEnemies(matrix);

                if ((matrix[samRow].Contains('b') && samCol > Array.IndexOf(matrix[samRow], 'b')) || matrix[samRow].Contains('d') && samCol < Array.IndexOf(matrix[samRow], 'd'))
                {
                    matrix[oldRow][oldCol] = '.';
                    matrix[samRow][samCol] = 'X';
                    Console.WriteLine($"Sam died at {samRow}, {samCol}");
                    PrintMatrix(matrix);
                    break;
                }

                switch (command)
                {
                case 'U': samRow--; break;

                case 'L': samCol--; break;

                case 'R': samCol++; break;

                case 'D': samRow++; break;
                }

                if (matrix[samRow][samCol] == 'b' || matrix[samRow][samCol] == 'd')
                {
                    matrix[oldRow][oldCol] = '.';
                    matrix[samRow][samCol] = 'S';
                }

                if (samRow == nikolaiRow)
                {
                    matrix[samRow][samCol]         = 'S';
                    matrix[nikolaiRow][nikolaiCol] = 'X';
                    Console.WriteLine("Nikoladze killed!");
                    matrix[oldRow][oldCol] = '.';
                    PrintMatrix(matrix);
                    break;
                }

                matrix[oldRow][oldCol] = '.';
            }
        }