Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace TronRacers
- {
- class Program
- {
- static void Main(string[] args)
- {
- var rows = int.Parse(Console.ReadLine());
- var cols = rows;
- var matrix = new char[rows, cols];
- var firstPlayerRow = 0;
- var firstPlayerCol = 0;
- var secondPlayerRow = 0;
- var secondPlayerCol = 0;
- for (int row = 0; row < rows; row++)
- {
- var currentArr = Console.ReadLine().ToCharArray();
- for (int col = 0; col < cols; col++)
- {
- matrix[row, col] = currentArr[col];
- if (currentArr[col] == 'f')
- {
- firstPlayerRow = row;
- firstPlayerCol = col;
- }
- else if (currentArr[col] == 's')
- {
- secondPlayerRow = row;
- secondPlayerCol = col;
- }
- }
- }
- var playerOneIsAlive = true;
- var playerTwoIsAlive = true;
- while (playerOneIsAlive && playerTwoIsAlive)
- {
- var input = Console.ReadLine()
- .Split(" ", StringSplitOptions.RemoveEmptyEntries)
- .ToArray();
- var command1 = input[0];
- //matrix[firstPlayerRow, firstPlayerCol] = 'f';
- if (command1 == "up")
- {
- if (firstPlayerRow - 1 < 0)
- {
- firstPlayerRow = rows - 1;
- }
- else
- {
- firstPlayerRow--;
- }
- if (matrix[firstPlayerRow, firstPlayerCol] == 's')
- {
- matrix[firstPlayerRow, firstPlayerCol] = 'x';
- playerOneIsAlive = false;
- break;
- }
- else
- {
- matrix[firstPlayerRow, firstPlayerCol] = 'f';
- }
- }
- else if (command1 == "down")
- {
- if (firstPlayerRow + 1 >= rows)
- {
- firstPlayerRow = 0;
- }
- else
- {
- firstPlayerRow++;
- }
- if (matrix[firstPlayerRow, firstPlayerCol] == 's')
- {
- matrix[firstPlayerRow, firstPlayerCol] = 'x';
- playerOneIsAlive = false;
- break;
- }
- else
- {
- matrix[firstPlayerRow, firstPlayerCol] = 'f';
- }
- }
- else if (command1 == "left")
- {
- if (firstPlayerCol - 1 < 0)
- {
- firstPlayerCol = cols - 1;
- }
- else
- {
- firstPlayerCol--;
- }
- if (matrix[firstPlayerRow, firstPlayerCol] == 's')
- {
- matrix[firstPlayerRow, firstPlayerCol] = 'x';
- playerOneIsAlive = false;
- break;
- }
- else
- {
- matrix[firstPlayerRow, firstPlayerCol] = 'f';
- }
- }
- else if (command1 == "right")
- {
- if (firstPlayerCol + 1 >= cols)
- {
- firstPlayerCol = 0;
- }
- else
- {
- firstPlayerCol++;
- }
- if (matrix[firstPlayerRow, firstPlayerCol] == 's')
- {
- matrix[firstPlayerRow, firstPlayerCol] = 'x';
- playerOneIsAlive = false;
- break;
- }
- else
- {
- matrix[firstPlayerRow, firstPlayerCol] = 'f';
- }
- }
- var command2 = input[1];
- if (command2 == "up")
- {
- if (secondPlayerRow - 1 < 0)
- {
- secondPlayerRow = rows - 1;
- }
- else
- {
- secondPlayerRow--;
- }
- if (matrix[secondPlayerRow, secondPlayerCol] == 'f')
- {
- matrix[secondPlayerRow, secondPlayerCol] = 'x';
- playerTwoIsAlive = false;
- break;
- }
- else
- {
- matrix[secondPlayerRow, secondPlayerCol] = 's';
- }
- }
- else if (command2 == "down")
- {
- if (secondPlayerRow + 1 >= rows)
- {
- secondPlayerRow = 0;
- }
- else
- {
- secondPlayerRow++;
- }
- if (matrix[secondPlayerRow, secondPlayerCol] == 'f')
- {
- matrix[secondPlayerRow, secondPlayerCol] = 'x';
- playerTwoIsAlive = false;
- break;
- }
- else
- {
- matrix[secondPlayerRow, secondPlayerCol] = 's';
- }
- }
- else if (command2 == "left")
- {
- if (secondPlayerCol - 1 < 0)
- {
- secondPlayerCol = cols - 1;
- }
- else
- {
- secondPlayerCol--;
- }
- if (matrix[secondPlayerRow, secondPlayerCol] == 'f')
- {
- matrix[secondPlayerRow, secondPlayerCol] = 'x';
- playerTwoIsAlive = false;
- break;
- }
- else
- {
- matrix[secondPlayerRow, secondPlayerCol] = 's';
- }
- }
- else if (command2 == "right")
- {
- if (secondPlayerCol + 1 >= cols)
- {
- secondPlayerCol = 0;
- }
- else
- {
- secondPlayerCol++;
- }
- if (matrix[secondPlayerRow, secondPlayerCol] == 'f')
- {
- matrix[secondPlayerRow, secondPlayerCol] = 'x';
- playerTwoIsAlive = false;
- break;
- }
- else
- {
- matrix[secondPlayerRow, secondPlayerCol] = 's';
- }
- }
- }
- PrintMatrix(matrix, rows);
- }
- static void PrintMatrix(char[,] matrix, int rows)
- {
- for (int row = 0; row < rows; row++)
- {
- for (int col = 0; col < rows; col++)
- {
- Console.Write($"{matrix[row,col]}");
- }
- Console.WriteLine();
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement