Advertisement
Guest User

Untitled

a guest
Oct 19th, 2019
233
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 11.38 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3.  
  4. namespace Tron_Racers
  5. {
  6.     class Program
  7.     {
  8.         static void Main(string[] args)
  9.         {
  10.            
  11.             int sizeOfMatrix = int.Parse(Console.ReadLine());
  12.  
  13.             var matrix = new char[sizeOfMatrix][];
  14.  
  15.             int FirstPlayerRow = 0;
  16.             int FirstPlayerCol = 0;
  17.             int SecondPlayerRow = 0;
  18.             int SecondPlayerCol = 0;
  19.  
  20.             for (int row = 0; row < matrix.Length; row++)
  21.             {
  22.                 string currentRow = Console.ReadLine();
  23.                 int length = currentRow.Length;
  24.                 matrix[row] = new char[length];
  25.                 for (int col = 0; col < matrix[row].Length; col++)
  26.                 {
  27.                     matrix[row][col] = currentRow[col];
  28.  
  29.                     if (currentRow[col] == 'f')
  30.                     {
  31.                         FirstPlayerRow = row;
  32.                         FirstPlayerCol = col;
  33.                     }
  34.                     else if (currentRow[col] == 's')
  35.                     {
  36.                         SecondPlayerRow = row;
  37.                         SecondPlayerCol = col;
  38.                     }
  39.                 }
  40.             }
  41.  
  42.             while (true)
  43.             {
  44.                 var commands = Console.ReadLine()
  45.                     .Split(" ", StringSplitOptions.RemoveEmptyEntries)
  46.                     .ToArray();
  47.  
  48.                 string firstDirection = commands[0];
  49.                 string secondDirection = commands[1];
  50.  
  51.                 if (firstDirection == "up")
  52.                 {
  53.                     if (FirstPlayerRow - 1 >= 0)
  54.                     {
  55.                         FirstPlayerRow--;
  56.                         if (matrix[FirstPlayerRow][FirstPlayerCol] == '*')
  57.                         {
  58.                             matrix[FirstPlayerRow][FirstPlayerCol] = 'f';
  59.                         }
  60.                         else
  61.                         {
  62.                             matrix[FirstPlayerRow][FirstPlayerCol] = 'x';
  63.                             break;
  64.                         }
  65.                     }
  66.                     else if (FirstPlayerRow - 1 < 0)
  67.                     {
  68.                         FirstPlayerRow = matrix.Length - 1;
  69.                         if (matrix[FirstPlayerRow][FirstPlayerCol] == '*')
  70.                         {
  71.                             matrix[FirstPlayerRow][FirstPlayerCol] = 'f';
  72.                         }
  73.                         else
  74.                         {
  75.                             matrix[FirstPlayerRow][FirstPlayerCol] = 'x';
  76.                             break;
  77.                         }
  78.                     }
  79.                 }
  80.                 else if (firstDirection == "down")
  81.                 {
  82.                     if (FirstPlayerRow + 1 < matrix.Length)
  83.                     {
  84.                         FirstPlayerRow++;
  85.                         if (matrix[FirstPlayerRow][FirstPlayerCol] == '*')
  86.                         {
  87.                             matrix[FirstPlayerRow][FirstPlayerCol] = 'f';
  88.                         }
  89.                         else
  90.                         {
  91.                             matrix[FirstPlayerRow][FirstPlayerCol] = 'x';
  92.                             break;
  93.                         }
  94.                     }
  95.                     else if (FirstPlayerRow + 1 >= matrix.Length)
  96.                     {
  97.                         FirstPlayerRow = 0;
  98.                         if (matrix[FirstPlayerRow][FirstPlayerCol] == '*')
  99.                         {
  100.                             matrix[FirstPlayerRow][FirstPlayerCol] = 'f';
  101.                         }
  102.                         else
  103.                         {
  104.                             matrix[FirstPlayerRow][FirstPlayerCol] = 'x';
  105.                             break;
  106.                         }
  107.                     }
  108.                 }
  109.                 else if (firstDirection == "right")
  110.                 {
  111.                     if (FirstPlayerCol + 1 < matrix[FirstPlayerRow].Length)
  112.                     {
  113.                         FirstPlayerCol++;
  114.                         if (matrix[FirstPlayerRow][FirstPlayerCol] == '*')
  115.                         {
  116.                             matrix[FirstPlayerRow][FirstPlayerCol] = 'f';
  117.                         }
  118.                         else
  119.                         {
  120.                             matrix[FirstPlayerRow][FirstPlayerCol] = 'x';
  121.                             break;
  122.                         }
  123.                     }
  124.                     else if (FirstPlayerCol + 1 >= matrix.Length)
  125.                     {
  126.                         FirstPlayerCol = 0;
  127.                         if (matrix[FirstPlayerRow][FirstPlayerCol] == '*')
  128.                         {
  129.                             matrix[FirstPlayerRow][FirstPlayerCol] = 'f';
  130.                         }
  131.                         else
  132.                         {
  133.                             matrix[FirstPlayerRow][FirstPlayerCol] = 'x';
  134.                             break;
  135.                         }
  136.                     }
  137.                 }
  138.                 else if (firstDirection == "left")
  139.                 {
  140.                     if (FirstPlayerCol - 1 >= 0)
  141.                     {
  142.                         FirstPlayerCol--;
  143.                         if (matrix[FirstPlayerRow][FirstPlayerCol] == '*')
  144.                         {
  145.                             matrix[FirstPlayerRow][FirstPlayerCol] = 'f';
  146.                         }
  147.                         else
  148.                         {
  149.                             matrix[FirstPlayerRow][FirstPlayerCol] = 'x';
  150.                             break;
  151.                         }
  152.                     }
  153.                     else if (FirstPlayerCol - 1 < 0)
  154.                     {
  155.                         FirstPlayerCol = matrix[FirstPlayerRow].Length - 1;
  156.                         if (matrix[FirstPlayerRow][FirstPlayerCol] == '*')
  157.                         {
  158.                             matrix[FirstPlayerRow][FirstPlayerCol] = 'f';
  159.                         }
  160.                         else
  161.                         {
  162.                             matrix[FirstPlayerRow][FirstPlayerCol] = 'x';
  163.                             break;
  164.                         }
  165.                     }
  166.                 }
  167.                 if (secondDirection == "up")
  168.                 {
  169.                     if (SecondPlayerRow - 1 >= 0)
  170.                     {
  171.                         SecondPlayerRow--;
  172.                         if (matrix[SecondPlayerRow][SecondPlayerCol] == '*')
  173.                         {
  174.                             matrix[SecondPlayerRow][SecondPlayerCol] = 's';
  175.                         }
  176.                         else
  177.                         {
  178.                             matrix[SecondPlayerRow][SecondPlayerCol] = 'x';
  179.                             break;
  180.                         }
  181.                     }
  182.                     else if (SecondPlayerRow - 1 < 0)
  183.                     {
  184.                         SecondPlayerRow = matrix.Length - 1;
  185.                         if (matrix[SecondPlayerRow][SecondPlayerCol] == '*')
  186.                         {
  187.                             matrix[SecondPlayerRow][SecondPlayerCol] = 's';
  188.                         }
  189.                         else
  190.                         {
  191.                             matrix[SecondPlayerRow][SecondPlayerCol] = 'x';
  192.                             break;
  193.                         }
  194.                     }
  195.                 }
  196.  
  197.  
  198.                 else if (secondDirection == "down")
  199.                 {
  200.                     if (SecondPlayerRow + 1 < matrix.Length)
  201.                     {
  202.                         SecondPlayerRow++;
  203.                         if (matrix[SecondPlayerRow][SecondPlayerCol] == '*')
  204.                         {
  205.                             matrix[SecondPlayerRow][SecondPlayerCol] = 's';
  206.                         }
  207.                         else
  208.                         {
  209.                             matrix[SecondPlayerRow][SecondPlayerCol] = 'x';
  210.                             break;
  211.                         }
  212.                     }
  213.                     else if (SecondPlayerRow + 1 >= matrix.Length)
  214.                     {
  215.                         SecondPlayerRow = 0;
  216.                         if (matrix[SecondPlayerRow][SecondPlayerCol] == '*')
  217.                         {
  218.                             matrix[SecondPlayerRow][SecondPlayerCol] = 's';
  219.                         }
  220.                         else
  221.                         {
  222.                             matrix[SecondPlayerRow][SecondPlayerCol] = 'x';
  223.                             break;
  224.                         }
  225.                     }
  226.                 }
  227.                 else if (secondDirection == "right")
  228.                 {
  229.                     if (SecondPlayerCol + 1 < matrix[SecondPlayerRow].Length)
  230.                     {
  231.                         SecondPlayerCol++;
  232.                         if (matrix[SecondPlayerRow][SecondPlayerCol] == '*')
  233.                         {
  234.                             matrix[SecondPlayerRow][SecondPlayerCol] = 's';
  235.                         }
  236.                         else
  237.                         {
  238.                             matrix[SecondPlayerRow][SecondPlayerCol] = 'x';
  239.                             break;
  240.                         }
  241.                     }
  242.                     else if (SecondPlayerCol + 1 >= matrix.Length)
  243.                     {
  244.                         SecondPlayerCol = 0;
  245.                         if (matrix[SecondPlayerRow][SecondPlayerCol] == '*')
  246.                         {
  247.                             matrix[SecondPlayerRow][SecondPlayerCol] = 's';
  248.                         }
  249.                         else
  250.                         {
  251.                             matrix[SecondPlayerRow][SecondPlayerCol] = 'x';
  252.                             break;
  253.                         }
  254.                     }
  255.                 }
  256.                 else if (secondDirection == "left")
  257.                 {
  258.                     if (SecondPlayerCol - 1 >= 0)
  259.                     {
  260.                         SecondPlayerCol--;
  261.                         if (matrix[SecondPlayerRow][SecondPlayerCol] == '*')
  262.                         {
  263.                             matrix[SecondPlayerRow][SecondPlayerCol] = 's';
  264.                         }
  265.                         else
  266.                         {
  267.                             matrix[SecondPlayerRow][SecondPlayerCol] = 'x';
  268.                             break;
  269.                         }
  270.                     }
  271.                     else if (SecondPlayerCol - 1 < 0)
  272.                     {
  273.                         SecondPlayerCol = matrix[SecondPlayerRow].Length - 1;
  274.                         if (matrix[SecondPlayerRow][SecondPlayerCol] == '*')
  275.                         {
  276.                             matrix[SecondPlayerRow][SecondPlayerCol] = 's';
  277.                         }
  278.                         else
  279.                         {
  280.                             matrix[SecondPlayerRow][SecondPlayerCol] = 'x';
  281.                             break;
  282.                         }
  283.                     }
  284.                 }
  285.             }
  286.  
  287.  
  288.             PrintMatrix(matrix);
  289.  
  290.         }
  291.         private static void PrintMatrix(char[][] matrix)
  292.         {
  293.             for (int row = 0; row < matrix.Length; row++)
  294.             {
  295.                 for (int col = 0; col < matrix[row].Length; col++)
  296.                 {
  297.                     Console.Write(matrix[row][col]);
  298.                 }
  299.  
  300.                 Console.WriteLine();
  301.             }
  302.         }
  303.     }
  304. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement