Advertisement
silvana1303

tron racers

Oct 24th, 2020 (edited)
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.22 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3. using System.Text;
  4.  
  5. namespace BookWorm
  6. {
  7.     class Program
  8.     {
  9.         static void Main(string[] args)
  10.         {
  11.             int n = int.Parse(Console.ReadLine());
  12.  
  13.             string[,] matrix = new string[n, n];
  14.  
  15.             int firstRow = 0;
  16.             int firstCol = 0;
  17.  
  18.             int secondRow = 0;
  19.             int secondCol = 0;
  20.  
  21.             bool dead = false;
  22.  
  23.  
  24.             for (int i = 0; i < n; i++)
  25.             {
  26.                 string input = Console.ReadLine();
  27.  
  28.                 for (int j = 0; j < n; j++)
  29.                 {
  30.                     matrix[i, j] = input[j].ToString();
  31.  
  32.                     if (matrix[i, j] == "f")
  33.                     {
  34.                         firstRow = i;
  35.                         firstCol = j;
  36.                     }
  37.  
  38.                     else if (matrix[i, j] == "s")
  39.                     {
  40.                         secondRow = i;
  41.                         secondCol = j;
  42.                     }
  43.                 }
  44.             }
  45.  
  46.             while (true)
  47.             {
  48.                 string[] command = Console.ReadLine().Split().ToArray();
  49.  
  50.                 if (command[0] == "up")
  51.                 {
  52.                     firstRow--;
  53.  
  54.                     if (firstRow < 0)
  55.                     {
  56.                         firstRow = n - 1;
  57.                     }
  58.                 }
  59.                 else if (command[0] == "down")
  60.                 {
  61.                     firstRow++;
  62.  
  63.                     if (firstRow > n - 1)
  64.                     {
  65.                         firstRow = 0;
  66.                     }
  67.                 }
  68.                 else if (command[0] == "left")
  69.                 {
  70.                     firstCol--;
  71.  
  72.                     if (firstCol < 0)
  73.                     {
  74.                         firstCol = n - 1;
  75.                     }
  76.                 }
  77.                 else if (command[0] == "right")
  78.                 {
  79.                     firstCol++;
  80.  
  81.                     if (firstCol > n - 1)
  82.                     {
  83.                         firstCol = 0;
  84.                     }
  85.                 }
  86.  
  87.                 if (matrix[firstRow, firstCol] == "*")
  88.                 {
  89.                     matrix[firstRow, firstCol] = "f";
  90.                 }
  91.                 else if(matrix[firstRow, firstCol] == "s")
  92.                 {
  93.                     matrix[firstRow, firstCol] = "x";
  94.                     dead = true;
  95.                 }
  96.  
  97.                 if (dead)
  98.                 {
  99.                     break;
  100.                 }
  101.  
  102.                 if (command[1] == "up")
  103.                 {
  104.                     secondRow--;
  105.  
  106.                     if (secondRow < 0)
  107.                     {
  108.                         secondRow = n - 1;
  109.                     }
  110.                 }
  111.                 else if (command[1] == "down")
  112.                 {
  113.                     secondRow++;
  114.  
  115.                     if (secondRow > n - 1)
  116.                     {
  117.                         secondRow = 0;
  118.                     }
  119.                 }
  120.                 else if (command[1] == "left")
  121.                 {
  122.                     secondCol--;
  123.  
  124.                     if (secondCol < 0)
  125.                     {
  126.                         secondCol = n - 1;
  127.                     }
  128.                 }
  129.                 else if (command[1] == "right")
  130.                 {
  131.                     secondCol++;
  132.  
  133.                     if (secondCol > n - 1)
  134.                     {
  135.                         secondCol = 0;
  136.                     }
  137.                 }
  138.  
  139.                 if (matrix[secondRow, secondCol] == "*")
  140.                 {
  141.                     matrix[secondRow, secondCol] = "s";
  142.                 }
  143.                 else if(matrix[secondRow, secondCol] == "f")
  144.                 {
  145.                     matrix[secondRow, secondCol] = "x";
  146.                     dead = true;
  147.                 }
  148.  
  149.                 if (dead)
  150.                 {
  151.                     break;
  152.                 }
  153.             }
  154.  
  155.             for (int i = 0; i < n; i++)
  156.             {
  157.                 for (int j = 0; j < n; j++)
  158.                 {
  159.                     Console.Write(matrix[i,j]);
  160.                 }
  161.  
  162.                 Console.WriteLine();
  163.             }
  164.  
  165.  
  166.         }
  167.  
  168.  
  169.     }
  170.  
  171. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement