Advertisement
grafa

Re-Volt

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