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 napierdalanka
- {
- class map
- {
- static Byte bX;
- static Byte bY;
- static Char[,] aData;
- static public void generate(Byte x, Byte y)
- {
- bX = x;
- bY = y;
- aData = new Char[bX, bY];
- for(x = 0; x != bX; ++x)
- {
- for(y = 0; y != bY; ++y)
- {
- if (x == 0 || x == bX - 1 || y == 0 || y == bY - 1)
- aData[x, y] = '#';
- else
- aData[x, y] = ' ';
- }
- }
- display();
- }
- static public void display()
- {
- Byte x, y;
- for (x = 0; x != bX; ++x)
- {
- for (y = 0; y != bY; ++y)
- {
- if (aData[x, y] != ' ')
- {
- Console.SetCursorPosition(x, y);
- Console.Write(aData[x, y]);
- }
- }
- }
- }
- }
- class entity
- {
- Byte bPosX;
- Byte bPosY;
- Char cAppearance;
- public void draw()
- {
- Console.SetCursorPosition(bPosX, bPosY);
- Console.Write(cAppearance);
- }
- public entity(Byte x, Byte y, Char c)
- {
- bPosX = x;
- bPosY = y;
- cAppearance = c;
- draw();
- }
- public void erase()
- {
- Console.SetCursorPosition(bPosX, bPosY);
- Console.Write(' ');
- }
- public void move(SByte dx, SByte dy)
- {
- erase();
- bPosX = (Byte)(bPosX+dx);
- bPosY = (Byte)(bPosY+dy);
- draw();
- }
- }
- class Program
- {
- static void Main(string[] args)
- {
- Console.CursorVisible = false;
- entity oPlayer = new entity(5, 5, '\x02');
- map.generate(79, 24);
- while (true)
- {
- if (Console.KeyAvailable) {
- ConsoleKey kk = Console.ReadKey(true).Key;
- switch (kk)
- {
- case ConsoleKey.Escape:
- return;
- case ConsoleKey.W:
- oPlayer.move(0, -1);
- break;
- case ConsoleKey.S:
- oPlayer.move(0, 1);
- break;
- case ConsoleKey.A:
- oPlayer.move(-1, 0);
- break;
- case ConsoleKey.D:
- oPlayer.move(1, 0);
- break;
- }
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement