//初始位置
static int nowX = 1;
static int nowY = 1;
static void Main(string[] args)
{
Thread th = new Thread(XXX);//线程
th.Start();//开启线程
while (true)
{
Thread.Sleep(100);//休眠
Show();
}
}
public static void Show()
{
Console.Clear();//清空
int[,] arr = new int[10, 10];//地图
for (int i = 0; i < arr.GetLength(0); i++)
{
for (int j = 0; j < arr.GetLength(1); j++)
{
if (nowX == i && nowY == j)
{
Console.Write("■");
}
else
{
Console.Write("□");
}
}
Console.WriteLine();
}
Console.ReadKey();
}
private static void XXX()//移动
{
while (true)
{
var ss = Console.ReadKey();
switch (ss.Key)
{
case ConsoleKey.A:
nowY--;
break;
case ConsoleKey.D:
nowY++;
break;
case ConsoleKey.W:
nowX--;
break;
case ConsoleKey.S:
nowX++;
break;
}
}
}