Advertisement
silvana1303

revolt

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