Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace C_Sharp_Junior
- {
- class Program
- {
- static void Main(string[] args)
- {
- Console.CursorVisible = false;
- Console.WriteLine("Найди выход.Цель игры: Попасть игроком на клетку обозначеной знаком 'X'");
- Console.ReadLine();
- Console.Clear();
- bool isEndGame = true;
- char signEndGame = 'X';
- char signGameObstacle = '#';
- int playerPositionX = 1;
- int playerPositionY = 1;
- int possiblePlayerPositionX = 1;
- int possiblePlayerPositionY = 1;
- char[,] map = {{'#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#'},
- {'#',' ',' ',' ',' ',' ','#',' ',' ','#',' ',' ',' ',' ',' ',' ','#'},
- {'#',' ','#','#','#',' ','#',' ',' ','#','#','#','#','#','#',' ','#'},
- {'#',' ',' ',' ','#',' ','#',' ',' ',' ',' ',' ',' ',' ',' ',' ','#'},
- {'#','#','#',' ','#',' ','#',' ',' ',' ',' ',' ',' ',' ','#',' ','#'},
- {'#',' ','#',' ','#','#','#',' ',' ','#','#',' ','#','#','#',' ','#'},
- {'#',' ','#',' ',' ',' ',' ',' ',' ','#',' ',' ','#','X','#',' ','#'},
- {'#',' ',' ',' ','#','#','#',' ',' ','#',' ',' ','#',' ',' ',' ','#'},
- {'#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#'}};
- DrawMap(map);
- while (isEndGame != false)
- {
- DrawPlayer(playerPositionX, playerPositionY);
- GetDirection(ref possiblePlayerPositionX, ref possiblePlayerPositionY);
- isEndGame = CheckingSign(map, playerPositionX, playerPositionY, possiblePlayerPositionX, possiblePlayerPositionY, signEndGame);
- if (CheckingSign(map, playerPositionX, playerPositionY, possiblePlayerPositionX, possiblePlayerPositionY, signGameObstacle))
- {
- Move(ref playerPositionX, ref playerPositionY, possiblePlayerPositionX, possiblePlayerPositionY);
- }
- }
- Console.Clear();
- Console.WriteLine("Поздравляю. Вы выиграли.");
- Console.ReadLine();
- }
- static void DrawMap(char[,] map)
- {
- 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();
- }
- }
- static bool CheckingSign(char[,] map, int playerPositionX, int playerPositionY, int possiblePlayerPositionX, int possiblePlayerPositionY, char sign)
- {
- return map[playerPositionX + possiblePlayerPositionX, playerPositionY + possiblePlayerPositionY] != sign;
- }
- static void Move(ref int playerPositionX, ref int playerPositionY, int possiblePlayerPositionX, int possiblePlayerPositionY)
- {
- Console.SetCursorPosition(playerPositionY, playerPositionX);
- Console.Write(" ");
- playerPositionX += possiblePlayerPositionX;
- playerPositionY += possiblePlayerPositionY;
- Console.SetCursorPosition(playerPositionY, playerPositionX);
- Console.Write("@");
- }
- static void GetDirection(ref int possiblePlayerPositionX, ref int possiblePlayerPositionY)
- {
- bool directionDefinitely = false;
- while (directionDefinitely == false)
- {
- if (Console.KeyAvailable)
- {
- ConsoleKeyInfo key = Console.ReadKey(true);
- switch (key.Key)
- {
- case ConsoleKey.UpArrow:
- possiblePlayerPositionX = -1; possiblePlayerPositionY = 0;
- break;
- case ConsoleKey.DownArrow:
- possiblePlayerPositionX = 1; possiblePlayerPositionY = 0;
- break;
- case ConsoleKey.LeftArrow:
- possiblePlayerPositionX = 0; possiblePlayerPositionY = -1;
- break;
- case ConsoleKey.RightArrow:
- possiblePlayerPositionX = 0; possiblePlayerPositionY = 1;
- break;
- }
- directionDefinitely = true;
- }
- }
- }
- static void DrawPlayer(int playerPositionX, int playerPositionY)
- {
- Console.SetCursorPosition(playerPositionY, playerPositionX);
- Console.Write("@");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement