Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace homework_03_2
- {
- class Program
- {
- static void Main(string[] args)
- {
- Console.CursorVisible = false;
- Random random = new Random();
- int countKey = 0;
- int live = 2;
- bool isWin = false;
- char[,] map =
- {
- {'#','#','#','#','#','#','#','#',' ',' ',' ',' ',' ',' ',' ',' ',' ','#','#','#','#','#','#','#','#' },
- {'#',' ',' ',' ',' ',' ','X','#',' ',' ',' ',' ',' ',' ',' ',' ',' ','#',' ',' ',' ',' ',' ',' ','#' },
- {'#',' ',' ',' ',' ',' ',' ','#',' ',' ',' ',' ',' ',' ',' ',' ',' ','#',' ',' ',' ',' ',' ',' ','#' },
- {'#',' ',' ',' ',' ',' ',' ','#','#','#','#','#','#','#','#','#','#','#',' ',' ',' ',' ',' ',' ','#' },
- {'#',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','<','<','<',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','#' },
- {'#',' ',' ',' ',' ',' ',' ','#','#','#','#','#','#','#','#','#','#','#',' ',' ',' ',' ',' ',' ','#' },
- {'#',' ',' ',' ',' ',' ',' ','#',' ',' ',' ',' ',' ',' ',' ',' ',' ','#',' ',' ',' ',' ',' ',' ','#' },
- {'#',' ',' ',' ',' ',' ',' ','#',' ',' ',' ',' ',' ',' ',' ',' ',' ','#',' ',' ',' ',' ',' ',' ','#' },
- {'#','X',' ',' ',' ',' ',' ','#',' ',' ',' ',' ',' ',' ',' ',' ',' ','#',' ','X',' ',' ',' ',' ','#' },
- {'#','#','#','#','#','#','#','#',' ',' ',' ',' ',' ',' ',' ',' ',' ','#','#','#','#','#','#','#','#' },
- };
- int userX = 2, userY = 3;
- // char[] bag = new char[0];
- while (live != 0)
- {
- 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();
- }
- if (countKey != 3)
- {
- Console.BackgroundColor = ConsoleColor.Red;
- Console.SetCursorPosition(0, 1);
- Console.Write('#');
- Console.BackgroundColor = ConsoleColor.Black;
- }
- else
- {
- Console.BackgroundColor = ConsoleColor.Yellow;
- Console.SetCursorPosition(1, 1);
- map[1, 0] = '-';
- Console.BackgroundColor = ConsoleColor.Black;
- }
- Console.SetCursorPosition(30, 0);
- Console.BackgroundColor = ConsoleColor.Red;
- Console.WriteLine("Задание: ");
- Console.BackgroundColor = ConsoleColor.Black;
- Console.SetCursorPosition(30, 1);
- Console.WriteLine("Найдите все ключи и выйдите из лабиринта.");
- Console.SetCursorPosition(30, 3);
- Console.Write("Жизни L : ");
- for (int i = 0; i < live; i++)
- {
- Console.Write("O");
- }
- Console.SetCursorPosition(30, 4);
- Console.WriteLine("Ключи Х : " + countKey);
- Console.SetCursorPosition(userY, userX);
- Console.Write('@');
- ConsoleKeyInfo charKey = Console.ReadKey();
- switch (charKey.Key)
- {
- case ConsoleKey.UpArrow:
- if (map[userX - 1, userY] != '#')
- userX--;
- break;
- case ConsoleKey.DownArrow:
- if (map[userX + 1, userY] != '#')
- userX++;
- break;
- case ConsoleKey.LeftArrow:
- if (map[userX, userY - 1] != '#')
- userY--;
- break;
- case ConsoleKey.RightArrow:
- if (map[userX, userY + 1] != '#')
- userY++;
- break;
- }
- if (map[userX, userY + 1] == '<')
- {
- live--;
- map[userX, userY + 1] = ' ';
- }
- else if (map[userX, userY] == 'X')
- {
- countKey++;
- map[userX, userY] = ' ';
- if (map[4, 11] == '<')
- {
- map[4, 11] = ' ';
- }
- else if (map[4, 12] == '<')
- {
- map[4, 12] = ' ';
- }
- else if (map[4, 13] == '<')
- {
- map[4, 13] = ' ';
- }
- }
- else if (map[userX, userY] == '-')
- {
- isWin = true;
- break;
- }
- Console.Clear();
- }
- Console.Clear();
- Console.SetCursorPosition(0, 0);
- Console.BackgroundColor = ConsoleColor.Red;
- if (isWin)
- Console.WriteLine("Вы выйграли!!!");
- else
- Console.WriteLine("Вы проиграли");
- Console.BackgroundColor = ConsoleColor.Black;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement