Advertisement
CrewLab

day 03_6

May 20th, 2019
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.19 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 Les3
  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',' ','X',' ',' ',' ',' ','#' },
  20.                 {'#','*',' ',' ',' ',' ',' ',' ',' ',' ',' ','#' },
  21.                 {'#',' ','*',' ',' ',' ',' ',' ',' ',' ',' ','#' },
  22.                 {'#',' ',' ',' ',' ',' ',' ','*',' ',' ',' ','#' },
  23.                 {'#',' ',' ','*',' ',' ',' ',' ',' ',' ',' ','#' },
  24.                 {'#',' ',' ',' ',' ',' ','X',' ',' ',' ','X','#' },
  25.                 {'#','#','#','#','#','#','#','#','#','#','#','#' }
  26.             };
  27.  
  28.             char[] bag = new char[0];
  29.  
  30.             int userX = 3, userY = 3;
  31.  
  32.             while (true)
  33.             {
  34.                 Console.SetCursorPosition(20, 0);
  35.                 Console.Write("Сумка: ");
  36.                 for (int i = 0; i < bag.Length; i++)
  37.                     Console.Write(bag[i] + " | ");
  38.  
  39.                 Console.SetCursorPosition(0, 0);
  40.                 for (int i = 0; i < map.GetLength(0); i++)
  41.                 {
  42.                     for (int j = 0; j < map.GetLength(1); j++)
  43.                     {
  44.                         Console.Write(map[i, j]);
  45.                     }
  46.                     Console.WriteLine();
  47.                 }
  48.  
  49.                 Console.SetCursorPosition(userY, userX);
  50.                 Console.Write('@');
  51.  
  52.                 ConsoleKeyInfo charKey = Console.ReadKey(true);
  53.  
  54.                 switch (charKey.Key)
  55.                 {
  56.                     case ConsoleKey.LeftArrow:
  57.                         if (map[userX, userY - 1] != '#')
  58.                             userY--;
  59.                         break;
  60.                     case ConsoleKey.RightArrow:
  61.                         if (map[userX, userY + 1] != '#')
  62.                             userY++;
  63.                         break;
  64.                     case ConsoleKey.UpArrow:
  65.                         if (map[userX - 1, userY] != '#')
  66.                             userX--;
  67.                         break;
  68.                     case ConsoleKey.DownArrow:
  69.                         if (map[userX + 1, userY] != '#')
  70.                             userX++;
  71.                         break;
  72.                 }
  73.  
  74.                 if (map[userX, userY] == 'X')
  75.                 {
  76.                     map[userX, userY] = 'o';
  77.  
  78.                     char[] tempBag = new char[bag.Length + 1];
  79.                     for (int i = 0; i < bag.Length; i++)
  80.                     {
  81.                         tempBag[i] = bag[i];
  82.                     }
  83.                     tempBag[tempBag.Length - 1] = 'X';
  84.                     bag = tempBag;
  85.                 }
  86.                 if (map[userX, userY] == '*')
  87.                 {
  88.                     char[,] gam_ov =
  89.                     {
  90.                     {'#','#','#','#','#','#','#','#','#','#','#','#' },
  91.                     {'#',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','#' },
  92.                     {'#',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','#' },
  93.                     {'#','G','A','M','E',' ',' ','O','V','E','R','#' },
  94.                     {'#',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','#' },
  95.                     {'#',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','#' },
  96.                     {'#',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','#' },
  97.                     {'#',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','#' },
  98.                     {'#','#','#','#','#','#','#','#','#','#','#','#' }
  99.                     };
  100.                     //map = gam_ov;
  101.                     Console.SetCursorPosition(0, 0);
  102.                     for (int i = 0; i < gam_ov.GetLength(0); i++)
  103.                     {
  104.                         for (int j = 0; j < gam_ov.GetLength(1); j++)
  105.                             Console.Write(gam_ov[i, j]);
  106.                         Console.WriteLine();
  107.                     }
  108.                     break;
  109.  
  110.                 }
  111.  
  112.             }
  113.  
  114.         }
  115.     }
  116. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement