Advertisement
Guest User

Untitled

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