Advertisement
SLENSER

Untitled

May 19th, 2019
193
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.43 KB | None | 0 0
  1. namespace Les3
  2. {
  3.     class Program
  4.     {
  5.         static void Main(string[] args)
  6.         {
  7.             bool start = false;
  8.             bool lose = false;
  9.            
  10.             while (start == false)
  11.             {
  12.                 Console.WriteLine("Правило игры - Собрать все X и не наступить на *\nНажмите 'enter',чтобы начать игру");
  13.                 ConsoleKeyInfo startGame = Console.ReadKey();
  14.                 if (startGame.Key == ConsoleKey.Enter)
  15.                 {
  16.                     start = true;
  17.                     Console.Clear();
  18.                 } else
  19.                 {
  20.                     Console.Clear();
  21.                 }
  22.             }
  23.            
  24.             Console.CursorVisible = false;
  25.             char X = 'X',player = '@';
  26.             char[,] map =
  27.             {
  28.                 {'#','#','#','#','#','#','#','#','#','#','#','#' },
  29.                 {'#',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','#' },
  30.                 {'#','*',' ','*', X ,' ', X ,' ','*',' ',' ','#' },
  31.                 {'#',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','#' },
  32.                 {'#',' ', X ,' ',' ',' ', X ,' ',' ','*',' ','#' },
  33.                 {'#',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','#' },
  34.                 {'#',' ',' ','*',' ','*',' ',' ',' ',' ',' ','#' },
  35.                 {'#','*',' ',' ','*',' ', X ,' ','*',' ', X ,'#' },
  36.                 {'#','#','#','#','#','#','#','#','#','#','#','#' }
  37.             };
  38.  
  39.             char[] bag = new char[0];
  40.  
  41.             int userX = 3, userY = 3;
  42.  
  43.             while (start == true)
  44.             {
  45.                 Console.SetCursorPosition(20, 0);
  46.                 Console.Write("Сумка: ");
  47.                 for (int i = 0; i < bag.Length; i++)
  48.                     Console.Write(bag[i] + " | ");
  49.  
  50.                 Console.SetCursorPosition(0, 0);
  51.                 for (int i = 0; i < map.GetLength(0); i++)
  52.                 {
  53.                     for (int j = 0; j < map.GetLength(1); j++)
  54.                     {
  55.                         Console.Write(map[i, j]);
  56.                     }
  57.                     Console.WriteLine();
  58.                 }
  59.  
  60.                 Console.SetCursorPosition(userY, userX);
  61.                 Console.Write(player);
  62.  
  63.                 ConsoleKeyInfo charKey = Console.ReadKey(true);
  64.  
  65.                 if (lose == false)
  66.                 {
  67.                     switch (charKey.Key)
  68.                     {
  69.                         case ConsoleKey.LeftArrow:
  70.                             if (map[userX, userY - 1] != '#')
  71.                                 userY--;
  72.                             break;
  73.                         case ConsoleKey.RightArrow:
  74.                             if (map[userX, userY + 1] != '#')
  75.                                 userY++;
  76.                             break;
  77.                         case ConsoleKey.UpArrow:
  78.                             if (map[userX - 1, userY] != '#')
  79.                                 userX--;
  80.                             break;
  81.                         case ConsoleKey.DownArrow:
  82.                             if (map[userX + 1, userY] != '#')
  83.                                 userX++;
  84.                             break;
  85.                     }
  86.                 }
  87.  
  88.                 if (map[userX, userY] == X)
  89.                 {
  90.                     map[userX, userY] = 'o';
  91.  
  92.                     char[] tempBag = new char[bag.Length + 1];
  93.                     for (int i = 0; i < bag.Length; i++)
  94.                     {
  95.                         tempBag[i] = bag[i];
  96.                     }
  97.                     tempBag[tempBag.Length - 1] = X;
  98.                     bag = tempBag;
  99.                 }
  100.                if(map[userX,userY] == '*')
  101.                 {
  102.                     lose = true;
  103.                     player = '1';
  104.                     Console.SetCursorPosition(0, 10);
  105.                     Console.WriteLine("Вы наступили на мину,которая заполнила всю карту единицами и проиграли :(.");
  106.                     Console.WriteLine("");
  107.  
  108.                     for (int i = 0; i < map.GetLength(0); i++)
  109.                     {
  110.                         for (int j = 0; j < map.GetLength(1); j++)
  111.                         {
  112.                             map[i, j] = '1';
  113.                            
  114.                         }
  115.                     }
  116.                    
  117.                 }
  118.  
  119.             }
  120.  
  121.         }
  122.     }
  123. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement