c#控制台应用程序游戏中的两个光标



我正试图在c#控制台应用程序中制作一个蛇游戏。

using System.Reflection;
namespace First_console_game
{
class Program
{
static void Main(string[] args)
{
Random rnd = new Random();
int redo = 0;
Byte Foods = 0;
Byte Flops = 0;
int x = 10, y = 20;
int Foodx = rnd.Next(1, 200);
int Foody = rnd.Next(1, 175);
ConsoleKeyInfo keyInfo;
do
{
keyInfo = Console.ReadKey(true);
//Console.SetCursorPosition(Foodx, Foody); This is the position of the food cell, and this is the part where it doesn't work. 
Flops += 1;
if (Flops == 5)
{
Console.Clear();
Flops = 0;
}

switch (keyInfo.Key)
{
case ConsoleKey.RightArrow:
x += 1;
Console.SetCursorPosition(x, y);
Console.Write("x");
break;
case ConsoleKey.LeftArrow:
x--;
Console.SetCursorPosition(x, y);
Console.Write("x");
break;
case ConsoleKey.UpArrow:
y -= 1;
Console.SetCursorPosition(x, y);
Console.Write("^");
break;
case ConsoleKey.DownArrow:
y += 1;
Console.SetCursorPosition(x, y);
Console.Write("x");
break;

}
} while (redo == 0);
Console.ReadLine();
}
}
}

在游戏中,我想要两个光标。一个给食物,一个给球员。

但很明显,我不能使用Console.SetCursorPosition(Foodx, Foody),因为这会让玩家在屏幕上到处乱跑,从而扰乱游戏。

那么我该如何添加一个单独的光标呢?谢谢

Re:"但很明显"-这一点都不明显!您可以将光标设置在那里;食物;字符,如*F

光标在你的游戏中没有任何作用,所以你可以用隐藏它

Console.CursorVisible = false;

最新更新