AlexRaynor

3.2 Game

Sep 8th, 2019
156
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.99 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.                 Console.SetCursorPosition(0, 0);
  34.                 for (int i = 0; i < map.GetLength(0); i++)
  35.                 {
  36.                     for (int j = 0; j < map.GetLength(1); j++)
  37.                     {
  38.                         Console.Write(map[i, j]);
  39.                     }
  40.                     Console.WriteLine();
  41.                 }
  42.  
  43.                 Console.SetCursorPosition(0, 15);
  44.                 Console.Write("Сумка: ");
  45.                 for (int i = 0; i < bag.Length; i++)
  46.                 {
  47.                     Console.Write(bag[i] + " ");
  48.                 }
  49.  
  50.                 Console.SetCursorPosition(userY, userX);
  51.                 Console.Write('@');
  52.  
  53.                 ConsoleKeyInfo charKey = Console.ReadKey();
  54.  
  55.                 switch (charKey.Key)
  56.                 {
  57.                     case ConsoleKey.UpArrow:
  58.                         if (map[userX - 1, userY] != '#')
  59.                             userX--;
  60.                         break;
  61.                     case ConsoleKey.DownArrow:
  62.                         if (map[userX + 1, userY] != '#')
  63.                             userX++;
  64.                         break;
  65.                     case ConsoleKey.LeftArrow:
  66.                         if (map[userX, userY - 1] != '#')
  67.                             userY--;
  68.                         break;
  69.                     case ConsoleKey.RightArrow:
  70.                         if (map[userX, userY + 1] != '#')
  71.                             userY++;
  72.                         break;
  73.  
  74.                         // Отклыдываем "Яйца" на карту.
  75.                     case ConsoleKey.Spacebar:
  76.  
  77.                         if (map[userX - 1, userX + 1] != '#' && bag.Length > 1)
  78.                         {
  79.                                 map[userX+1, userY] = 'X';
  80.  
  81.                             char[] tempBag = new char[bag.Length - 1];
  82.                             for (int i = 0; i < bag.Length-1; i++)
  83.                             {
  84.                                 tempBag[i] = bag[i];
  85.                             }
  86.  
  87.                             tempBag[tempBag.Length-1] = ' ';
  88.  
  89.                             bag = tempBag;
  90.  
  91.  
  92.                         }
  93.  
  94.                         break;
  95.  
  96.                 }
  97.  
  98.                 if (map[userX, userY] == 'X')
  99.                 {
  100.                     map[userX, userY] = 'o';
  101.  
  102.                     char[] tempBag = new char[bag.Length + 1];
  103.                     for (int i = 0; i < bag.Length; i++)
  104.                     {
  105.                         tempBag[i] = bag[i];
  106.                     }
  107.                     tempBag[tempBag.Length - 1] = 'X';
  108.  
  109.                     bag = tempBag;
  110.                 }
  111.  
  112.  
  113.  
  114.  
  115.  
  116.             }
  117.         }
  118.     }
  119. }
Advertisement
Add Comment
Please, Sign In to add comment