我正在尝试制作一种CMD“地牢爬行者”游戏。
其中的墙壁或“ #”应不可行走。
这是我的摘录或到目前为止的内容
static bool Walkable;
static string Wall = "#";
static string Player = "@";
static int PX = 52, PY = 12;
static void Main(string[] args)
{
while (true)
{
Draw();
Console.SetCursorPosition(PX, PY);
Console.Write(Player, Console.ForegroundColor = ConsoleColor.DarkYellow);
ConsoleKeyInfo mov = Console.ReadKey();
if (Walkable == true)
{
if (mov.Key == ConsoleKey.LeftArrow)
{
PX--;
Console.SetCursorPosition(PX + 1, PY);
Console.Write(" ");
}
if (mov.Key == ConsoleKey.RightArrow)
{
PX++;
Console.SetCursorPosition(PX - 1, PY);
Console.Write(" ");
}
if (mov.Key == ConsoleKey.UpArrow)
{
PY--;
Console.SetCursorPosition(PX, PY + 1);
Console.Write(" ");
}
if (mov.Key == ConsoleKey.DownArrow)
{
PY++;
Console.SetCursorPosition(PX, PY - 1);
Console.Write(" ");
}
}
}
}
static void Draw()
{
Console.ForegroundColor = ConsoleColor.White;
for (int x = 35; x <= 75; x++)
{
Console.SetCursorPosition(x, 5);
Console.Write(Wall, Walkable = false);
Console.SetCursorPosition(x, 20);
Console.Write(Wall, Walkable = false);
}
for (int y = 5; y <= 20; y++)
{
Console.SetCursorPosition(35, y);
Console.Write(Wall, Walkable = false);
Console.SetCursorPosition(75, y);
Console.Write(Wall, Walkable = false);
}
}
}
}
它写出了玩家和进行游戏的房间,但是我一生无法找到一种方法来使“ Null”或空的背景可以同时行走,因为墙壁没有,就像我不知道如何在框内填充点“”一样。或者其他的东西。
任何帮助或反馈都非常感谢。