Advertisement
Guest User

Untitled

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