Advertisement
Guest User

Untitled

a guest
Jun 24th, 2019
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.89 KB | None | 0 0
  1. using System;
  2.  
  3. namespace ConsoleApp1
  4. {
  5.     class Program
  6.     {
  7.         static int stephenRow;
  8.         static int stephenCol;
  9.  
  10.         static void Main(string[] args)
  11.         {
  12.             int sizeOfMatrix = int.Parse(Console.ReadLine());
  13.  
  14.             char[][] galaxy = new char[sizeOfMatrix][];
  15.  
  16.             FillMatrix(galaxy);
  17.  
  18.             int energy = 0;
  19.  
  20.  
  21.             FindStephen(galaxy);
  22.  
  23.             while (true)
  24.             {
  25.                 string direction = Console.ReadLine();
  26.  
  27.                 if (direction == "end")
  28.                 {
  29.                     break;
  30.                 }
  31.  
  32.                 if (direction == "up")
  33.                 {
  34.                     if (stephenRow - 1 >= 0)
  35.                     {
  36.                         stephenRow--;
  37.                         galaxy[stephenRow][stephenCol] = 'S';
  38.  
  39.                     }
  40.                     else if (direction == "down")
  41.                     {
  42.                         if (stephenRow + 1 < galaxy.Length)
  43.                         {
  44.                             stephenRow++;
  45.                         }
  46.                     }
  47.                     else if (direction == "left")
  48.                     {
  49.                         if (stephenCol - 1 >= 0)
  50.                         {
  51.                             stephenCol--;
  52.                         }
  53.                     }
  54.                     else if (direction == "right")
  55.                     {
  56.                         if (stephenRow + 1 < galaxy[stephenRow].Length)
  57.                         {
  58.                             stephenCol++;
  59.  
  60.                         }
  61.                     }
  62.  
  63.                     char symbolOnNextStep = galaxy[stephenRow][stephenCol];
  64.                     if (symbolOnNextStep == '-')
  65.                     {
  66.                         galaxy[stephenRow][stephenCol] = 'S';
  67.                     }
  68.  
  69.                 }
  70.                 PrintMatrix(galaxy);
  71.             }
  72.  
  73.         }
  74.         private static void PrintMatrix(char[][] galaxy)
  75.         {
  76.             for (int row = 0; row < galaxy.Length; row++)
  77.             {
  78.  
  79.                 Console.WriteLine(string.Join("", galaxy[row]));
  80.             }
  81.         }
  82.  
  83.  
  84.         private static void FindStephen(char[][] galaxy)
  85.         {
  86.             for (int row = 0; row < galaxy.Length; row++)
  87.             {
  88.                 for (int col = 0; col < galaxy[row].Length; col++)
  89.                 {
  90.                     if (galaxy[row][col] == 'S')
  91.                     {
  92.                         stephenRow = row;
  93.                         stephenCol = col;
  94.                     }
  95.                 }
  96.             }
  97.  
  98.         }
  99.  
  100.         private static void FillMatrix(char[][] galaxy)
  101.         {
  102.             for (int row = 0; row < galaxy.Length; row++)
  103.             {
  104.                 var data = Console.ReadLine().ToCharArray();
  105.  
  106.                 galaxy[row] = data;
  107.             }
  108.         }
  109.     }
  110.  
  111.  
  112. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement