Advertisement
bonumopus

BraveNewWorld

May 10th, 2020
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.94 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 BraveNewWorld
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             Console.CursorVisible = false;
  14.             int playerX = 7; int playerY = 3;
  15.             int playerDX = 0; int playerDY = 0;
  16.  
  17.             string[,] map = { { "#","#","#","#","#","#","#","#","#","#"},
  18.                 { "#"," "," "," "," "," "," "," "," ","#" },
  19.                 { "#"," "," ","#"," "," "," "," "," ","#"},
  20.                 { "#"," "," ","#"," "," "," "," "," ","#"},
  21.                 { "#"," "," ","#","#","#"," "," "," ","#"},
  22.                 { "#"," "," "," "," ","#"," "," "," ","#"},
  23.                 { "#"," "," "," "," ","#"," "," "," ","#"},
  24.                 { "#"," "," "," "," ","#"," "," "," ","#"},
  25.                 { "#"," "," "," "," "," "," "," "," ","#"},
  26.                 { "#","#","#","#","#","#","#","#","#","#"} };
  27.  
  28.             DrawMap(map, ref playerX, ref playerY);
  29.  
  30.             while (true)
  31.             {          
  32.                 if (Console.KeyAvailable)
  33.                 {
  34.                     ConsoleKeyInfo key = Console.ReadKey(true);
  35.  
  36.                     switch (key.Key)
  37.                     {
  38.                         case ConsoleKey.UpArrow:
  39.                             playerDX = -1; playerDY = 0;
  40.                             break;
  41.                         case ConsoleKey.DownArrow:
  42.                             playerDX = 1; playerDY = 0;
  43.                             break;
  44.                         case ConsoleKey.LeftArrow:
  45.                             playerDX = 0; playerDY = -1;
  46.                             break;
  47.                         case ConsoleKey.RightArrow:
  48.                             playerDX = 0; playerDY = 1;
  49.                             break;
  50.                     }
  51.  
  52.                     if(map[playerX + playerDX, playerY + playerDY] != "#")
  53.                     {
  54.                         Console.SetCursorPosition(playerY, playerX);
  55.                         Console.Write(" ");
  56.                         playerX += playerDX; playerY += playerDY;
  57.                         Console.SetCursorPosition(playerY, playerX);
  58.                         Console.Write("@");
  59.                     }
  60.                 }
  61.             }
  62.  
  63.         }
  64.  
  65.         static void DrawMap(string[,] map, ref int playerX, ref int playerY)
  66.         {
  67.  
  68.             for (int i = 0; i < map.GetLength(0); i++)
  69.             {
  70.                 for (int j = 0; j < map.GetLength(1); j++)
  71.                 {
  72.                     Console.Write(map[i, j]);
  73.                 }
  74.                 Console.WriteLine();
  75.             }
  76.             Console.SetCursorPosition(playerY, playerX);
  77.             Console.Write("@");
  78.             Console.SetCursorPosition(0, 12);
  79.             Console.Write("Для управления используйти клавиши со стрелками");
  80.         }
  81.  
  82.     }
  83. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement