Advertisement
Guest User

Untitled

a guest
Feb 17th, 2020
275
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 5.84 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3.  
  4. namespace _02._Tron_Racers
  5. {
  6.     class Program
  7.     {
  8.         static void Main(string[] args)
  9.         {
  10.             int size = int.Parse(Console.ReadLine());
  11.  
  12.             char[,] matrix = new char[size, size];
  13.             int Frow = 0;
  14.             int Fcol = 0;
  15.             int Srow = 0;
  16.             int Scol = 0;
  17.             int newRowF = 0;
  18.             int newColF = 0;
  19.             int newRowS = 0;
  20.             int newColS = 0;
  21.  
  22.             for (int row = 0; row < size; row++)
  23.             {
  24.                 string currRow = Console.ReadLine();
  25.  
  26.                 for (int col = 0; col < size; col++)
  27.                 {
  28.                     if (currRow[col] == 'f')
  29.                     {
  30.                         Frow = row;
  31.                         Fcol = col;
  32.                     }
  33.                     else if (currRow[col] == 's')
  34.                     {
  35.                         Srow = row;
  36.                         Scol = col;
  37.                     }
  38.                     matrix[row, col] = currRow[col];
  39.                 }
  40.             }
  41.  
  42.             while (true)
  43.             {
  44.                 string[] command = Console.ReadLine().Split();
  45.  
  46.                 string cmdF = command[0];
  47.                 string cmdS = command[1];
  48.  
  49.                 if (cmdF == "up")
  50.                 {
  51.                      newRowF = Frow - 1;
  52.                      newColF = Fcol;
  53.  
  54.                     if (newRowF < 0)
  55.                     {
  56.                         newRowF = size - 1;
  57.                     }
  58.                     if (matrix[newRowF, newColF] == 's')
  59.                     {
  60.                         matrix[newRowF, newColF] = 'x';
  61.                         break;
  62.                     }
  63.                     matrix[newRowF, newColF] = 'f';
  64.                 }
  65.                 if (cmdS == "up")
  66.                 {
  67.                      newRowS = Srow - 1;
  68.                      newColS = Scol;
  69.  
  70.                     if (newRowS < 0)
  71.                     {
  72.                         newRowS = size - 1;
  73.                     }
  74.                     if (matrix[newRowS, newColS] == 'f')
  75.                     {
  76.                         matrix[newRowS, newColS] = 'x';
  77.                         break;
  78.                     }
  79.                     matrix[newRowS, newColS] = 's';
  80.                 }
  81.                 if (cmdF == "down")
  82.                 {
  83.                      newRowF = Frow + 1;
  84.                      newColF = Fcol;
  85.  
  86.                     if (newRowF >= size)
  87.                     {
  88.                         newRowF = 0;
  89.                     }
  90.                     if (matrix[newRowF, newColF] == 's')
  91.                     {
  92.                         matrix[newRowF, newColF] = 'x';
  93.                         break;
  94.                     }
  95.                     matrix[newRowF, newColF] = 'f';
  96.                 }
  97.                 if (cmdS == "down")
  98.                 {
  99.                      newRowS = Srow + 1;
  100.                      newColS = Scol;
  101.  
  102.                     if (newRowS >= size)
  103.                     {
  104.                         newRowS = 0;
  105.                     }
  106.                     if (matrix[newRowS, newColS] == 'f')
  107.                     {
  108.                         matrix[newRowS, newColS] = 'x';
  109.                         break;
  110.                     }
  111.                     matrix[newRowS, newColS] = 's';
  112.                 }
  113.                 if (cmdF == "left")
  114.                 {
  115.                      newRowF = Frow;
  116.                      newColF = Fcol - 1;
  117.  
  118.                     if (newColF < 0)
  119.                     {
  120.                         newColF = size - 1;
  121.                     }
  122.                     if (matrix[newRowF, newColF] == 's')
  123.                     {
  124.                         matrix[newRowF, newColF] = 'x';
  125.                         break;
  126.                     }
  127.                     matrix[newRowF, newColF] = 'f';
  128.                 }
  129.                 if (cmdS == "left")
  130.                 {
  131.                      newRowS = Srow;
  132.                      newColS = Scol - 1;
  133.  
  134.                     if (newRowS < 0)
  135.                     {
  136.                         newColS = size - 1;
  137.                     }
  138.                     if (matrix[newRowS, newColS] == 'f')
  139.                     {
  140.                         matrix[newRowS, newColS] = 'x';
  141.                         break;
  142.                     }
  143.                     matrix[newRowS, newColS] = 's';
  144.                 }
  145.                 if (cmdF == "right")
  146.                 {
  147.                      newRowF = Frow;
  148.                      newColF = Fcol + 1;
  149.  
  150.                     if (newColF >= size)
  151.                     {
  152.                         newColF = 0;
  153.                     }
  154.                     if (matrix[newRowF, newColF] == 's')
  155.                     {
  156.                         matrix[newRowF, newColF] = 'x';
  157.                         break;
  158.                     }
  159.                     matrix[newRowF, newColF] = 'f';
  160.                 }
  161.                 if (cmdS == "right")
  162.                 {
  163.                      newRowS = Srow;
  164.                      newColS = Scol + 1;
  165.  
  166.                     if (newRowS >= size)
  167.                     {
  168.                         newColS = 0;
  169.                     }
  170.                     if (matrix[newRowS, newColS] == 'f')
  171.                     {
  172.                         matrix[newRowS, newColS] = 'x';
  173.                         break;
  174.                     }
  175.                     matrix[newRowS, newColS] = 's';
  176.                 }
  177.  
  178.                 Frow = newRowF;
  179.                 Fcol = newColF;
  180.  
  181.                 Srow = newRowS;
  182.                 Scol = newColS;
  183.             }
  184.  
  185.             for (int row = 0; row < size; row++)
  186.             {
  187.                 for (int col = 0; col < size; col++)
  188.                 {
  189.                     Console.Write(matrix[row, col]);
  190.                 }
  191.                 Console.WriteLine();
  192.             }
  193.         }
  194.     }
  195. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement