Advertisement
Galina841130

Re-volt

Feb 18th, 2022
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 11.35 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3.  
  4. namespace _02.Re_volt
  5. {
  6.     class Program
  7.     {
  8.         static void Main(string[] args)
  9.         {
  10.             int n = int.Parse(Console.ReadLine());
  11.             int commandCount = int.Parse(Console.ReadLine());
  12.             char[,] matrix = new char[n, n];
  13.             int playerRow = -1;
  14.             int playerCol = -1;
  15.  
  16.             for (int row = 0; row < n; row++)
  17.             {
  18.                 string columnInput = Console.ReadLine();
  19.                 for (int col = 0; col < n; col++)
  20.                 {
  21.                     matrix[row, col] = columnInput[col];
  22.                     if (matrix[row, col] == 'f')
  23.                     {
  24.                         playerRow = row;
  25.                         playerCol = col;
  26.                     }
  27.                 }
  28.             }
  29.  
  30.             for (int i = 0; i < commandCount; i++)
  31.             {
  32.                 string command = Console.ReadLine();
  33.                 switch (command)
  34.                 {
  35.                     case "up":
  36.                         matrix[playerRow, playerCol] = '-';
  37.                         playerRow--;
  38.                         if (!IsInside(matrix, playerRow, playerCol))
  39.                         {
  40.                             playerRow = n - 1;
  41.  
  42.                             if (matrix[playerRow, playerCol] == 'F')
  43.                             {
  44.                                 matrix[playerRow, playerCol] = 'f';
  45.                                 Console.WriteLine("Player won!");
  46.                                 PrintMatrix(matrix);
  47.                                 return;
  48.                             }
  49.                             matrix[playerRow, playerCol] = 'f';
  50.                         }
  51.                         else
  52.                         {
  53.                             if (matrix[playerRow, playerCol] == 'F')
  54.                             {
  55.                                 matrix[playerRow, playerCol] = 'f';
  56.                                 Console.WriteLine("Player won!");
  57.                                 PrintMatrix(matrix);
  58.                                 return;
  59.                             }
  60.                             else if (matrix[playerRow, playerCol] == 'T')
  61.                             {
  62.                                 playerRow++;
  63.                                 matrix[playerRow, playerCol] = 'f';
  64.                             }
  65.                             else if (matrix[playerRow, playerCol] == 'B')
  66.                             {
  67.                                 playerRow--;
  68.                                 if (!IsInside(matrix, playerRow, playerCol))
  69.                                 {
  70.                                     playerRow = n - 1;
  71.                                 }
  72.                                 if (matrix[playerRow, playerCol] == 'F')
  73.                                     {
  74.                                         matrix[playerRow, playerCol] = 'f';
  75.                                         Console.WriteLine("Player won!");
  76.                                         PrintMatrix(matrix);
  77.                                         return;
  78.                                     }
  79.                                 matrix[playerRow, playerCol] = 'f';
  80.                             }
  81.                             else
  82.                             {
  83.                                 matrix[playerRow, playerCol] = 'f';
  84.                             }
  85.                         }
  86.                         break;
  87.                     case "down":
  88.                         matrix[playerRow, playerCol] = '-';
  89.                         playerRow++;
  90.                         if (!IsInside(matrix, playerRow, playerCol))
  91.                         {
  92.                             playerRow = 0;
  93.                             if (matrix[playerRow, playerCol] == 'F')
  94.                             {
  95.                                 matrix[playerRow, playerCol] = 'f';
  96.                                 Console.WriteLine("Player won!");
  97.                                 PrintMatrix(matrix);
  98.                                 return;
  99.                             }
  100.                             matrix[playerRow, playerCol] = 'f';
  101.                         }
  102.                         else
  103.                         {
  104.                             if (matrix[playerRow, playerCol] == 'F')
  105.                             {
  106.                                 matrix[playerRow, playerCol] = 'f';
  107.                                 Console.WriteLine("Player won!");
  108.                                 PrintMatrix(matrix);
  109.                                 return;
  110.                             }
  111.                             else if (matrix[playerRow, playerCol] == 'T')
  112.                             {
  113.                                 playerRow--;
  114.                                 matrix[playerRow, playerCol] = 'f';
  115.                             }
  116.                             else if (matrix[playerRow, playerCol] == 'B')
  117.                             {
  118.                                 playerRow++;
  119.                                 if (!IsInside(matrix, playerRow, playerCol))
  120.                                 {
  121.                                     playerRow = 0;
  122.                                 }
  123.                                 if (matrix[playerRow, playerCol] == 'F')
  124.                                 {
  125.                                     matrix[playerRow, playerCol] = 'f';
  126.                                     Console.WriteLine("Player won!");
  127.                                     PrintMatrix(matrix);
  128.                                     return;
  129.                                 }
  130.                                 matrix[playerRow, playerCol] = 'f';
  131.                             }
  132.                             else
  133.                             {
  134.                                 matrix[playerRow, playerCol] = 'f';
  135.                             }
  136.                         }
  137.                         break;
  138.                     case "left":
  139.                         matrix[playerRow, playerCol] = '-';
  140.                         playerCol--;
  141.                         if (!IsInside(matrix, playerRow, playerCol))
  142.                         {
  143.                             playerCol = n - 1;
  144.                             if (matrix[playerRow, playerCol] == 'F')
  145.                             {
  146.                                 matrix[playerRow, playerCol] = 'f';
  147.                                 Console.WriteLine("Player won!");
  148.                                 PrintMatrix(matrix);
  149.                                 return;
  150.                             }
  151.                             matrix[playerRow, playerCol] = 'f';
  152.                         }
  153.                         else
  154.                         {
  155.                             if (matrix[playerRow, playerCol] == 'F')
  156.                             {
  157.                                 matrix[playerRow, playerCol] = 'f';
  158.                                 Console.WriteLine("Player won!");
  159.                                 PrintMatrix(matrix);
  160.                                 return;
  161.                             }
  162.                             else if (matrix[playerRow, playerCol] == 'T')
  163.                             {
  164.                                 playerCol++;
  165.                                 matrix[playerRow, playerCol] = 'f';
  166.                             }
  167.                             else if (matrix[playerRow, playerCol] == 'B')
  168.                             {
  169.                                 playerCol--;
  170.                                 if (!IsInside(matrix, playerRow, playerCol))
  171.                                 {
  172.                                     playerCol = n - 1;
  173.                                 }
  174.                                 if (matrix[playerRow, playerCol] == 'F')
  175.                                 {
  176.                                     matrix[playerRow, playerCol] = 'f';
  177.                                     Console.WriteLine("Player won!");
  178.                                     PrintMatrix(matrix);
  179.                                     return;
  180.                                 }
  181.                                 matrix[playerRow, playerCol] = 'f';
  182.                             }
  183.                             else
  184.                             {
  185.                                 matrix[playerRow, playerCol] = 'f';
  186.                             }
  187.                         }
  188.                         break;
  189.                     case "right":
  190.                         matrix[playerRow, playerCol] = '-';
  191.                         playerCol++;
  192.                         if (!IsInside(matrix, playerRow, playerCol))
  193.                         {
  194.                             playerCol = 0;
  195.                             if (matrix[playerRow, playerCol] == 'F')
  196.                             {
  197.                                 matrix[playerRow, playerCol] = 'f';
  198.                                 Console.WriteLine("Player won!");
  199.                                 PrintMatrix(matrix);
  200.                                 return;
  201.                             }
  202.                             matrix[playerRow, playerCol] = 'f';
  203.                         }
  204.                         else
  205.                         {
  206.                             if (matrix[playerRow, playerCol] == 'F')
  207.                             {
  208.                                 matrix[playerRow, playerCol] = 'f';
  209.                                 Console.WriteLine("Player won!");
  210.                                 PrintMatrix(matrix);
  211.                                 return;
  212.                             }
  213.                             else if (matrix[playerRow, playerCol] == 'T')
  214.                             {
  215.                                 playerCol--;
  216.                                 matrix[playerRow, playerCol] = 'f';
  217.                             }
  218.                             else if (matrix[playerRow, playerCol] == 'B')
  219.                             {
  220.                                 playerCol++;
  221.                                 if (!IsInside(matrix, playerRow, playerCol))
  222.                                 {
  223.                                     playerCol = 0;
  224.                                 }
  225.                                 if (matrix[playerRow, playerCol] == 'F')
  226.                                 {
  227.                                     matrix[playerRow, playerCol] = 'f';
  228.                                     Console.WriteLine("Player won!");
  229.                                     PrintMatrix(matrix);
  230.                                     return;
  231.                                 }
  232.                                 matrix[playerRow, playerCol] = 'f';
  233.                             }
  234.                             else
  235.                             {
  236.                                 matrix[playerRow, playerCol] = 'f';
  237.                             }
  238.                         }
  239.                         break;
  240.                 }
  241.             }
  242.             Console.WriteLine("Player lost!");
  243.             PrintMatrix(matrix);
  244.         }
  245.  
  246.         private static bool IsInside(char[,] matrix, int row, int col)
  247.         {
  248.             return row >= 0 && row < matrix.GetLength(0) && col >= 0 && col < matrix.GetLength(1);
  249.         }
  250.         private static void PrintMatrix(char[,] matrix)
  251.         {
  252.             for (int row = 0; row < matrix.GetLength(0); row++)
  253.             {
  254.                 for (int col = 0; col < matrix.GetLength(1); col++)
  255.                 {
  256.                     Console.Write(matrix[row, col]);
  257.                 }
  258.                 Console.WriteLine();
  259.             }
  260.         }
  261.     }
  262. }
  263.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement