所以我在 Visual Studio 中创建一个迷宫游戏,用 C# 编码。我走得很好,但我一直在弄清楚如何使迷宫的墙壁变得坚固。当前,当您到达迷宫中的墙壁时,位置标记会直接穿过它们并删除蓝色墙壁。我目前正试图弄清楚如何制作你无法穿过的墙壁。我尝试了各种陈述,还尝试弄乱 unicode,但似乎无处可去。如果有人有任何提示,那就太好了!谢谢。
这是我的代码:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Diagnostics;
namespace Project4
{
class Program
{
static void Main(string[] args)
{
Console.SetWindowSize(10, 10);
Console.BackgroundColor = ConsoleColor.White;
Console.ForegroundColor = ConsoleColor.DarkBlue;
//Make maze
Console.WriteLine("");
Console.WriteLine(" \u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588 ");
Console.WriteLine(" \u2588\u0020\u0020\u0020\u0020\u0020\u0020\u2588 ");
Console.WriteLine(" \u2588\u0020\u2588\u2588\u2588\u2588\u0020\u2588 ");
Console.WriteLine(" \u2588\u0020\u2588\u0020\u0020\u0020\u0020\u2588 ");
Console.WriteLine(" \u2588\u0020\u2588\u0020\u2588\u2588\u2588\u2588 ");
Console.WriteLine(" \u2588\u0020\u2588\u0020\u0020\u0020\u0020\u2588 ");
Console.WriteLine(" \u2588\u0020\u2588\u2588\u2588\u2588\u0020\u2588 ");
Console.WriteLine(" \u2588\u0020\u0020\u0020\u0020\u0020\u0020\u2588 ");
Console.WriteLine(" \u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588 ");
Console.Write("");
int col = 7;
int row = 6;
Console.SetCursorPosition(col, row);
Console.Write("*");
Console.SetCursorPosition(col, row);
while (true)
{
ConsoleKeyInfo info = Console.ReadKey(true);
if (info.Key == ConsoleKey.W)
{
Console.Write(" ");
Debug.Print("W");
row--;
}
if (info.Key == ConsoleKey.Z)
{
Console.Write(" ");
Debug.Print("Z");
row++;
}
if (info.Key == ConsoleKey.A)
{
Console.Write(" ");
Debug.Print("A");
col--;
}
if (info.Key == ConsoleKey.S)
{
Console.Write(" ");
Debug.Print("S");
col++;
}
Console.SetCursorPosition(col, row);
Console.Write("*");
Console.SetCursorPosition(col, row);
}
}
}
}