Advertisement
AlexRaynor

4.4. Brave new world

Sep 22nd, 2019
197
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.10 KB | None | 0 0
  1. using System;
  2.  
  3. namespace IMJunior
  4. {
  5.     class Program
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             Console.CursorVisible = false;
  10.  
  11.             char[,] map =
  12.             {
  13.                 {'#','#','#','#','#','#','#','#','#','#','#','#','#','#','#' },
  14.                 {'#',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','#' },
  15.                 {'#',' ',' ','X',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','#' },
  16.                 {'#',' ',' ',' ',' ',' ','X',' ',' ',' ',' ','X',' ',' ','#' },
  17.                 {'#',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','#' },
  18.                 {'#',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','#' },
  19.                 {'#',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','#' },
  20.                 {'#',' ','X',' ',' ',' ',' ',' ',' ',' ',' ','X',' ',' ','#' },
  21.                 {'#',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','#' },
  22.                 {'#',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','#' },
  23.                 {'#',' ',' ',' ',' ',' ','X',' ',' ',' ',' ',' ',' ',' ','#' },
  24.                 {'#','#','#','#','#','#','#','#','#','#','#','#','#','#','#' }
  25.             };
  26.  
  27.             char[] bag = new char[0];
  28.  
  29.             int userX = 3, userY = 3;
  30.  
  31.             while (true)
  32.             {
  33.                 DrawMap(map);    // Отрисовываем карту
  34.  
  35.                 Console.SetCursorPosition(0, 15);
  36.                 Console.Write("Сумка: ");
  37.                 for (int i = 0; i < bag.Length; i++)
  38.                 {
  39.                     Console.Write(bag[i] + " ");
  40.                 }
  41.  
  42.                 Console.SetCursorPosition(userY, userX);
  43.                 Console.Write('@');
  44.  
  45.                 ConsoleKeyInfo charKey = Console.ReadKey();
  46.  
  47.                 switch (charKey.Key)
  48.                 {
  49.                     case ConsoleKey.UpArrow:
  50.                         if (map[userX - 1, userY] != '#')
  51.                             userX--;
  52.                         break;
  53.                     case ConsoleKey.DownArrow:
  54.                         if (map[userX + 1, userY] != '#')
  55.                             userX++;
  56.                         break;
  57.                     case ConsoleKey.LeftArrow:
  58.                         if (map[userX, userY - 1] != '#')
  59.                             userY--;
  60.                         break;
  61.                     case ConsoleKey.RightArrow:
  62.                         if (map[userX, userY + 1] != '#')
  63.                             userY++;
  64.                         break;
  65.  
  66.                     // Отклыдываем "Яйца" на карту.
  67.                     case ConsoleKey.Spacebar:
  68.  
  69.                         if (map[userX - 1, userX + 1] != '#' && bag.Length > 1)
  70.                         {
  71.                             map[userX + 1, userY] = 'X';
  72.  
  73.                             char[] tempBag = new char[bag.Length - 1];
  74.                             for (int i = 0; i < bag.Length - 1; i++)
  75.                             {
  76.                                 tempBag[i] = bag[i];
  77.                             }
  78.  
  79.                             tempBag[tempBag.Length - 1] = ' ';
  80.  
  81.                             bag = tempBag;
  82.  
  83.  
  84.                         }
  85.  
  86.                         break;
  87.  
  88.                 }
  89.  
  90.                 if (map[userX, userY] == 'X')
  91.                 {
  92.                     map[userX, userY] = 'o';
  93.  
  94.                     char[] tempBag = new char[bag.Length + 1];
  95.                     for (int i = 0; i < bag.Length; i++)
  96.                     {
  97.                         tempBag[i] = bag[i];
  98.                     }
  99.                     tempBag[tempBag.Length - 1] = 'X';
  100.  
  101.                     bag = tempBag;
  102.                 }
  103.  
  104.  
  105.  
  106.  
  107.  
  108.  
  109.  
  110.             }
  111.         }
  112.  
  113.         static void DrawMap(char[,] Array)
  114.         {
  115.  
  116.             Console.SetCursorPosition(0, 0);
  117.             for (int i = 0; i < Array.GetLength(0); i++)
  118.             {
  119.                 for (int j = 0; j < Array.GetLength(1); j++)
  120.                 {
  121.                     Console.Write(Array[i, j]);
  122.                 }
  123.                 Console.WriteLine();
  124.             }
  125.  
  126.         }
  127.  
  128.  
  129.     }
  130. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement