Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace BraveNewWorld
- {
- class Program
- {
- static void Main(string[] args)
- {
- Console.CursorVisible = false;
- int playerX = 7; int playerY = 3;
- int playerDX = 0; int playerDY = 0;
- string[,] map = { { "#","#","#","#","#","#","#","#","#","#"},
- { "#"," "," "," "," "," "," "," "," ","#" },
- { "#"," "," ","#"," "," "," "," "," ","#"},
- { "#"," "," ","#"," "," "," "," "," ","#"},
- { "#"," "," ","#","#","#"," "," "," ","#"},
- { "#"," "," "," "," ","#"," "," "," ","#"},
- { "#"," "," "," "," ","#"," "," "," ","#"},
- { "#"," "," "," "," ","#"," "," "," ","#"},
- { "#"," "," "," "," "," "," "," "," ","#"},
- { "#","#","#","#","#","#","#","#","#","#"} };
- DrawMap(map, ref playerX, ref playerY);
- while (true)
- {
- if (Console.KeyAvailable)
- {
- ChooseDirection(ref playerDX, ref playerDY);
- if (map[playerX + playerDX, playerY + playerDY] != "#")
- {
- MovePlayer(map, ref playerX, ref playerY, playerDX, playerDY);
- }
- }
- }
- }
- static void MovePlayer(string[,] map, ref int playerX, ref int playerY, int playerDX, int playerDY)
- {
- Console.SetCursorPosition(playerY, playerX);
- Console.Write(" ");
- playerX += playerDX;
- playerY += playerDY;
- Console.SetCursorPosition(playerY, playerX);
- Console.Write("@");
- }
- static void ChooseDirection(ref int playerDX, ref int playerDY)
- {
- ConsoleKeyInfo key = Console.ReadKey(true);
- switch (key.Key)
- {
- case ConsoleKey.UpArrow:
- playerDX = -1; playerDY = 0;
- break;
- case ConsoleKey.DownArrow:
- playerDX = 1; playerDY = 0;
- break;
- case ConsoleKey.LeftArrow:
- playerDX = 0; playerDY = -1;
- break;
- case ConsoleKey.RightArrow:
- playerDX = 0; playerDY = 1;
- break;
- }
- }
- static void DrawMap(string[,] map, ref int playerX, ref int playerY)
- {
- 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(playerY, playerX);
- Console.Write("@");
- Console.SetCursorPosition(0, 12);
- Console.Write("Для управления используйти клавиши со стрелками");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement