Advertisement
MrVeiran

neponimau

Mar 10th, 2019
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.09 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. using System;
  8. namespace Lesson8
  9. {
  10.     class Program
  11.     {
  12.         static void Main(string[] args)
  13.         {
  14.             Console.CursorVisible = false;
  15.             char[,] map =
  16.                 {
  17.                     { '#','#','#','#','#','#','#','#','#','#'},
  18.                     { '#','#','#','#',' ',' ',' ',' ','X','#'},
  19.                     { '#','X',' ',' ',' ','#','#','#',' ','#'},
  20.                     { '#',' ','#','#','#','X',' ',' ',' ','#'},
  21.                     { '#',' ',' ',' ','#',' ','#','#','#','#'},
  22.                     { '#','#','#',' ','#',' ',' ',' ',' ','#'},
  23.                     { '#',' ',' ',' ','#',' ','#','#',' ','#'},
  24.                     { '#',' ','#','#','#',' ','X','#',' ','#'},
  25.                     { '#',' ',' ',' ','#','#',' ','#',' ','#'},
  26.                     { '#','X','#','X',' ',' ',' ','#',' ','#'},
  27.                     { '#','#','#','#','#','#','#','#','П','#'}
  28.                 };
  29.             char[] bag = new char[0];
  30.  
  31.             int userX = 8, userY = 9;
  32.  
  33.             while (true)
  34.             {
  35.                 Console.SetCursorPosition(20, 0);
  36.                 Console.Write("Сумка: ");
  37.                 for (int i = 0; i < bag.Length; i++)
  38.                     Console.Write(bag[i] + " | ");
  39.  
  40.                 Console.SetCursorPosition(0, 0);
  41.                 for (int i = 0; i < map.GetLength(0); i++)
  42.                 {
  43.                     for (int j = 0; j < map.GetLength(1); j++)
  44.                     {
  45.                         Console.Write(map[i, j]);
  46.                     }
  47.                     Console.WriteLine();
  48.                 }
  49.                 Console.SetCursorPosition(userX, userY);
  50.                 Console.Write('@');
  51.                 ConsoleKeyInfo charKey = Console.ReadKey();
  52.  
  53.                 switch (charKey.Key)
  54.                 {
  55.                     case ConsoleKey.UpArrow:
  56.                         if (map[userX, userY - 1] != '#')
  57.                             userY--;
  58.                         break;
  59.                     case ConsoleKey.DownArrow:
  60.                         if (map[userX, userY + 1] != '#')
  61.                             userY++;
  62.                         break;
  63.                     case ConsoleKey.LeftArrow:
  64.                         if (map[userX - 1, userY] != '#')
  65.                             userX--;
  66.                         break;
  67.                     case ConsoleKey.RightArrow:
  68.                         if (map[userX + 1, userY] != '#')
  69.                             userX++;
  70.                         break;
  71.                 }
  72.  
  73.                 if (map[userY, userX] == 'X')
  74.                 {
  75.                     map[userY, userX] = 'o';
  76.                     char[] tempBag = new char[bag.Length + 1];
  77.                     for (int i = 0; i < bag.Length; i++)
  78.                     {
  79.                         tempBag[i] = bag[i];
  80.                     }
  81.                     tempBag[tempBag.Length - 1] = 'X';
  82.                     bag = tempBag;
  83.                 }
  84.  
  85.             }
  86.  
  87.         }
  88.     }
  89. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement