Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- namespace Les3
- {
- class Program
- {
- static void Main(string[] args)
- {
- bool start = false;
- bool lose = false;
- while (start == false)
- {
- Console.WriteLine("Правило игры - Собрать все X и не наступить на *\nНажмите 'enter',чтобы начать игру");
- ConsoleKeyInfo startGame = Console.ReadKey();
- if (startGame.Key == ConsoleKey.Enter)
- {
- start = true;
- Console.Clear();
- } else
- {
- Console.Clear();
- }
- }
- Console.CursorVisible = false;
- char X = 'X',player = '@';
- char[,] map =
- {
- {'#','#','#','#','#','#','#','#','#','#','#','#' },
- {'#',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','#' },
- {'#','*',' ','*', X ,' ', X ,' ','*',' ',' ','#' },
- {'#',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','#' },
- {'#',' ', X ,' ',' ',' ', X ,' ',' ','*',' ','#' },
- {'#',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','#' },
- {'#',' ',' ','*',' ','*',' ',' ',' ',' ',' ','#' },
- {'#','*',' ',' ','*',' ', X ,' ','*',' ', X ,'#' },
- {'#','#','#','#','#','#','#','#','#','#','#','#' }
- };
- char[] bag = new char[0];
- int userX = 3, userY = 3;
- while (start == true)
- {
- Console.SetCursorPosition(20, 0);
- Console.Write("Сумка: ");
- for (int i = 0; i < bag.Length; i++)
- Console.Write(bag[i] + " | ");
- Console.SetCursorPosition(0, 0);
- for (int i = 0; i < map.GetLength(0); i++)
- {
- for (int j = 0; j < map.GetLength(1); j++)
- {
- Console.Write(map[i, j]);
- }
- Console.WriteLine();
- }
- Console.SetCursorPosition(userY, userX);
- Console.Write(player);
- ConsoleKeyInfo charKey = Console.ReadKey(true);
- if (lose == false)
- {
- switch (charKey.Key)
- {
- case ConsoleKey.LeftArrow:
- if (map[userX, userY - 1] != '#')
- userY--;
- break;
- case ConsoleKey.RightArrow:
- if (map[userX, userY + 1] != '#')
- userY++;
- break;
- case ConsoleKey.UpArrow:
- if (map[userX - 1, userY] != '#')
- userX--;
- break;
- case ConsoleKey.DownArrow:
- if (map[userX + 1, userY] != '#')
- userX++;
- break;
- }
- }
- if (map[userX, userY] == X)
- {
- map[userX, userY] = 'o';
- char[] tempBag = new char[bag.Length + 1];
- for (int i = 0; i < bag.Length; i++)
- {
- tempBag[i] = bag[i];
- }
- tempBag[tempBag.Length - 1] = X;
- bag = tempBag;
- }
- if(map[userX,userY] == '*')
- {
- lose = true;
- player = '1';
- Console.SetCursorPosition(0, 10);
- Console.WriteLine("Вы наступили на мину,которая заполнила всю карту единицами и проиграли :(.");
- Console.WriteLine("");
- for (int i = 0; i < map.GetLength(0); i++)
- {
- for (int j = 0; j < map.GetLength(1); j++)
- {
- map[i, j] = '1';
- }
- }
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement