Advertisement
tehKaiN

napierdalanka 27.05.2015

May 27th, 2015
174
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.00 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace napierdalanka
  8. {
  9.     class  map
  10.     {
  11.         static Byte bX;
  12.         static Byte bY;
  13.         static Char[,] aData;
  14.  
  15.         static public void generate(Byte x, Byte y)
  16.         {
  17.             bX = x;
  18.             bY = y;
  19.             aData = new Char[bX, bY];
  20.             for(x = 0; x != bX; ++x)
  21.             {
  22.                 for(y = 0; y != bY; ++y)
  23.                 {
  24.                     if (x == 0 || x == bX - 1 || y == 0 || y == bY - 1)
  25.                         aData[x, y] = '#';
  26.                     else
  27.                         aData[x, y] = ' ';
  28.                 }
  29.             }
  30.             display();
  31.         }
  32.  
  33.         static public void display()
  34.         {
  35.             Byte x, y;
  36.             for (x = 0; x != bX; ++x)
  37.             {
  38.                 for (y = 0; y != bY; ++y)
  39.                 {
  40.                     if (aData[x, y] != ' ')
  41.                     {
  42.                         Console.SetCursorPosition(x, y);
  43.                         Console.Write(aData[x, y]);
  44.                     }
  45.                 }
  46.             }
  47.         }
  48.     }
  49.  
  50.     class entity
  51.     {
  52.         Byte bPosX;
  53.         Byte bPosY;
  54.         Char cAppearance;
  55.  
  56.         public void draw()
  57.         {
  58.             Console.SetCursorPosition(bPosX, bPosY);
  59.             Console.Write(cAppearance);
  60.     }
  61.  
  62.         public entity(Byte x, Byte y, Char c)
  63.         {
  64.             bPosX = x;
  65.             bPosY = y;
  66.             cAppearance = c;
  67.             draw();
  68.         }
  69.         public void erase()
  70.         {
  71.             Console.SetCursorPosition(bPosX, bPosY);
  72.             Console.Write(' ');
  73.         }
  74.  
  75.         public void move(SByte dx, SByte dy)
  76.         {
  77.             erase();
  78.             bPosX = (Byte)(bPosX+dx);
  79.             bPosY = (Byte)(bPosY+dy);
  80.             draw();
  81.         }
  82.  
  83.     }
  84.  
  85.     class Program
  86.     {
  87.         static void Main(string[] args)
  88.         {
  89.             Console.CursorVisible = false;
  90.             entity oPlayer = new entity(5, 5, '\x02');
  91.             map.generate(79, 24);
  92.  
  93.             while (true)
  94.             {
  95.                 if (Console.KeyAvailable) {
  96.                     ConsoleKey kk = Console.ReadKey(true).Key;
  97.  
  98.                     switch (kk)
  99.                     {
  100.                         case ConsoleKey.Escape:
  101.                             return;
  102.                         case ConsoleKey.W:
  103.                             oPlayer.move(0, -1);
  104.                             break;
  105.                         case ConsoleKey.S:
  106.                             oPlayer.move(0, 1);
  107.                             break;
  108.                         case ConsoleKey.A:
  109.                             oPlayer.move(-1, 0);
  110.                             break;
  111.                         case ConsoleKey.D:
  112.                             oPlayer.move(1, 0);
  113.                             break;
  114.                     }
  115.                 }
  116.             }
  117.         }
  118.     }
  119. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement