Advertisement
DrDemonik

Untitled

Mar 13th, 2019
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.40 KB | None | 0 0
  1. using System;
  2. namespace Lesson8
  3. {
  4.     class Program
  5.     {
  6.         static void Main(string[] args)
  7.         {
  8.             Console.CursorVisible = false;
  9.             char[,] map =
  10.                 {
  11.                     { '#','#','#','#','#','#','#','#','#','#'},
  12.                     { '#','#','#','#',' ',' ',' ',' ','X','#'},
  13.                     { '#','X',' ',' ',' ','#','#','#',' ','#'},
  14.                     { '#',' ',' ','#','#','X',' ',' ',' ','#'},
  15.                     { '#',' ',' ',' ','#',' ','#','#','#','#'},
  16.                     { '#','#','#',' ','#',' ',' ',' ',' ','#'},
  17.                     { '#',' ',' ',' ','#',' ','#','#',' ','#'},
  18.                     { '#',' ','#','#','#',' ','X','#',' ','#'},
  19.                     { '#',' ',' ',' ','#','#',' ','#',' ','#'},
  20.                     { '#','X','#','X',' ',' ',' ','#',' ','#'},
  21.                     { '#','#','#','#','#','#','#','#','#','#'}
  22.                 };
  23.             char[] bag = new char[0];
  24.  
  25.             int userX = 3, userY = 3;
  26.  
  27.             bool exit = false;
  28.  
  29.             while (!exit)
  30.             {
  31.                 Console.SetCursorPosition(20, 0);
  32.                 Console.Write("Сумка: ");
  33.                 for (int i = 0; i < bag.Length; i++)
  34.                     Console.Write(bag[i] + " | ");
  35.  
  36.                 Console.SetCursorPosition(0, 0);
  37.                 for (int i = 0; i < map.GetLength(0); i++)
  38.                 {
  39.                     for (int j = 0; j < map.GetLength(1); j++)
  40.                     {
  41.                         Console.Write(map[i, j]);
  42.                     }
  43.                     Console.WriteLine();
  44.                 }
  45.                 Console.SetCursorPosition(userY, userX);
  46.                 Console.Write('@');
  47.                 ConsoleKeyInfo charKey = Console.ReadKey();
  48.  
  49.                 switch (charKey.Key)
  50.                 {
  51.                     case ConsoleKey.UpArrow:
  52.                         if (map[userX - 1, userY] != '#')
  53.                             userX--;
  54.  
  55.                         break;
  56.                     case ConsoleKey.DownArrow:
  57.                         if (map[userX + 1, userY] != '#')
  58.                             userX++;
  59.                         break;
  60.                     case ConsoleKey.LeftArrow:
  61.                         if (map[userX, userY - 1] != '#')
  62.                             userY--;
  63.                         break;
  64.                     case ConsoleKey.RightArrow:
  65.                         if (map[userX, userY + 1] != '#')
  66.                             userY++;
  67.                         break;
  68.                 }
  69.                 //проверка на колво призов и открытие ворот
  70.                 if (bag.Length >= 6)
  71.                     map[9,9] = 'П';
  72.  
  73.                 if (map[userX, userY] == 'X')
  74.                 {
  75.                     map[userX, userY] = '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.                 else if (map[userX, userY] == 'П')
  85.                 {
  86.                     exit = true;
  87.                 }
  88.  
  89.             }
  90.             Console.Clear();
  91.             Console.WriteLine("Поздравляю Вы выграли!");
  92.         }
  93.     }
  94. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement