Advertisement
radostina92

Miner

Jan 13th, 2021
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 6.44 KB | None | 0 0
  1. using System;
  2.  
  3. namespace miner
  4. {
  5.     class miner
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             int n = int.Parse(Console.ReadLine());
  10.             var command = Console.ReadLine().Split();
  11.             var matrix = new char[n, n];
  12.             int currentRow = 0;
  13.             int currentCol = 0;
  14.             for (int i = 0; i < n; i++)
  15.             {
  16.                 var lines = Console.ReadLine().ToCharArray();
  17.                 for (int j = 0; j < n; j++)
  18.                 {
  19.                     matrix[i, j] = lines[j];
  20.                 }
  21.             }
  22.             int coalCounter = 0;
  23.             for (int row = 0; row < n; row++)
  24.             {
  25.                 for (int col = 0; col < n; col++)
  26.                 {
  27.                     if (matrix[row, col] == 's')
  28.                     {
  29.                         for (int i = 0; i < command.Length; i++)
  30.                         {
  31.  
  32.                             if (command[i] == "up")
  33.                             {
  34.                                 if (row - 1 >= 0)
  35.                                 {
  36.                                     currentRow = row - 1;
  37.                                     currentCol = col;
  38.                                     if (matrix[currentRow, currentCol] == 'c')
  39.                                         {
  40.                                             coalCounter++;
  41.                                             matrix[currentRow, currentCol] = '*';
  42.                                         }
  43.                                         else if (matrix[currentRow, currentCol] == 'e')
  44.                                         {
  45.                                             Console.WriteLine($"Game over! ({currentRow}, {currentCol})");
  46.                                             return;
  47.                                         }
  48.                                     row = row - 1;
  49.                                    
  50.                                 }
  51.                             }
  52.                             else if (command[i] == "down")
  53.                             {
  54.                                 if (row + 1 < matrix.GetLength(0))
  55.                                 {
  56.                                     currentRow = row + 1;
  57.                                     currentCol = col;
  58.                                     if (matrix[currentRow, currentCol] == 'c')
  59.                                         {
  60.                                             coalCounter++;
  61.                                             matrix[currentRow, currentCol] = '*';
  62.                                         }
  63.                                         else if (matrix[currentRow, currentCol] == 'e')
  64.                                         {
  65.                                             Console.WriteLine($"Game over! ({currentRow}, {currentCol})");
  66.                                             return;
  67.                                         }
  68.                                     row = row + 1;
  69.  
  70.                                 }
  71.                             }
  72.                             else if (command[i] == "right")
  73.                             {
  74.                                 if (col + 1 < matrix.GetLength(1))
  75.                                 {
  76.                                     currentRow = row;
  77.                                     currentCol = col + 1;
  78.                                    
  79.                                     if (matrix[currentRow, currentCol] == 'c')
  80.                                         {
  81.                                             coalCounter++;
  82.                                             matrix[currentRow, currentCol] = '*';
  83.                                         }
  84.                                         else if (matrix[currentRow, currentCol] == 'e')
  85.                                         {
  86.                                             Console.WriteLine($"Game over! ({currentRow}, {currentCol})");
  87.                                             return;
  88.                                         }
  89.                                     col = col + 1;
  90.  
  91.                                 }
  92.                             }
  93.                             else if (command[i] == "left")
  94.                             {
  95.                                 if (col - 1 >= 0)
  96.                                 {
  97.                                     currentRow = row;
  98.                                     currentCol = col - 1;
  99.                                     if (matrix[currentRow, currentCol] == 'c')
  100.                                         {
  101.                                             coalCounter++;
  102.                                             matrix[currentRow, currentCol] = '*';
  103.                                         }
  104.                                         else if (matrix[currentRow, currentCol] == 'e')
  105.                                         {
  106.                                             Console.WriteLine($"Game over! ({currentRow}, {currentCol})");
  107.                                             return;
  108.                                         }
  109.                                     col = col - 1;
  110.                                 }
  111.                             }
  112.                             int ccounter = 0;
  113.                             foreach (var item in matrix)
  114.                             {
  115.                                 if (item == 'c')
  116.                                 {
  117.                                     ccounter++;
  118.                                 }
  119.  
  120.                             }
  121.  
  122.                             if (ccounter == 0)
  123.                             {
  124.                                 Console.WriteLine($"You collected all coals! ({row}, {col})");
  125.                                 return;
  126.                             }
  127.  
  128.                             if (i == command.Length - 1)
  129.                             {
  130.                                 int cnt = 0;
  131.                                 foreach (var item in matrix)
  132.                                 {
  133.                                    
  134.                                     if (item == 'c')
  135.                                     {
  136.                                         cnt++;
  137.                                     }
  138.                                 }
  139.                                 Console.WriteLine($"{cnt} coals left. ({row}, {col})");
  140.                                 return;
  141.                             }
  142.                         }
  143.                     }
  144.                 }
  145.  
  146.             }
  147.  
  148.         }
  149.     }
  150. }
  151.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement