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 CSharpLightTask
- {
- class Program
- {
- static void Main(string[] args)
- {
- bool isPlaying = true;
- int playerX, playerY;
- int playerDX = 0, playerDY = 0;
- char[,] map = { { '#','#','#','#','#'},
- { '#',' ',' ',' ','#'},
- { '#',' ','@',' ','#'},
- { '#',' ',' ',' ','#'},
- { '#','#','#','#','#'} };
- DrawMap(map, out playerX, out playerY);
- while (isPlaying)
- {
- Console.CursorVisible = false;
- if (Console.KeyAvailable)
- {
- 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;
- }
- if (map[playerX + playerDX, playerY + playerDY] != '#')
- {
- Console.SetCursorPosition(playerY, playerX);
- Console.Write(" ");
- playerX += playerDX;
- playerY += playerDY;
- Console.SetCursorPosition(playerY, playerX);
- Console.Write('@');
- }
- }
- }
- Console.ReadKey();
- }
- static void DrawMap(char[,] map, out int playerX, out int playerY)
- {
- playerX = 0;
- playerY = 0;
- for (int i = 0; i < map.GetLength(0); i++)
- {
- for (int j = 0; j < map.GetLength(1); j++)
- {
- Console.Write(map[i, j]);
- if (map[i, j] == '@')
- {
- playerX = i;
- playerY = j;
- }
- }
- Console.WriteLine();
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement