Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- namespace CSLight
- {
- public class Program
- {
- static char[,] map = {
- { '#', '#', '#', '#', '#', '#', '#', '#', '#', '#' },
- { '#', ' ', ' ', ' ', '#', ' ', ' ', ' ', ' ', '#' },
- { '#', ' ', '#', ' ', '#', ' ', '#', '#', ' ', '#' },
- { '#', ' ', '#', ' ', ' ', ' ', ' ', '#', ' ', '#' },
- { '#', ' ', '#', '#', '#', '#', ' ', '#', ' ', '#' },
- { '#', ' ', ' ', ' ', ' ', ' ', ' ', '#', ' ', '#' },
- { '#', '#', '#', '#', '#', '#', '#', '#', '#', '#' }
- };
- static int playerX = 1;
- static int playerY = 1;
- static void Main(string[] args)
- {
- bool isRunning = true;
- while (isRunning)
- {
- DrawMap();
- ConsoleKeyInfo keyInfo = Console.ReadKey(true);
- switch (keyInfo.Key)
- {
- case ConsoleKey.W:
- MovePlayer(0, -1);
- break;
- case ConsoleKey.S:
- MovePlayer(0, 1);
- break;
- case ConsoleKey.A:
- MovePlayer(-1, 0);
- break;
- case ConsoleKey.D:
- MovePlayer(1, 0);
- break;
- case ConsoleKey.Enter:
- isRunning = false;
- break;
- }
- }
- }
- static void DrawMap()
- {
- Console.Clear();
- for (int y = 0; y < map.GetLength(0); y++)
- {
- for (int x = 0; x < map.GetLength(1); x++)
- {
- if (x == playerX && y == playerY)
- {
- Console.Write('0');
- }
- else
- {
- Console.Write(map[y, x]);
- }
- }
- Console.WriteLine();
- }
- }
- static void MovePlayer(int deltaX, int deltaY)
- {
- int newX = playerX + deltaX;
- int newY = playerY + deltaY;
- if (newX >= 0 && newX < map.GetLength(1) && newY >= 0 && newY < map.GetLength(0))
- {
- if (map[newY, newX] != '#')
- {
- playerX = newX;
- playerY = newY;
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement