114 lines
3.2 KiB
C#
114 lines
3.2 KiB
C#
|
using System;
|
|||
|
using System.Collections.Generic;
|
|||
|
using System.Diagnostics;
|
|||
|
using System.Linq;
|
|||
|
using System.Text;
|
|||
|
using System.Threading.Tasks;
|
|||
|
using static Debug.MinLong.Main;
|
|||
|
|
|||
|
namespace Debug.Tanchishe;
|
|||
|
|
|||
|
public class Main
|
|||
|
{
|
|||
|
public Main()
|
|||
|
{
|
|||
|
Console.Clear();
|
|||
|
Program.ResetChars();
|
|||
|
she.x = b / 2;
|
|||
|
she.y = a / 2;
|
|||
|
Program.chars[she.y, she.x].Char = she.Char;
|
|||
|
//sx();
|
|||
|
new Thread(PrintCharArray).Start();//打印
|
|||
|
KeyThread();//键盘
|
|||
|
new Zhixing(this).Run();
|
|||
|
|
|||
|
|
|||
|
}
|
|||
|
|
|||
|
public class She
|
|||
|
{
|
|||
|
public int x, y;
|
|||
|
public int direction = 0;//方向 0不动 1上 2右 -1下 -2左
|
|||
|
public char Char = 'o';
|
|||
|
}
|
|||
|
public She she = new();
|
|||
|
int i; int j;
|
|||
|
int a = Program.chars.GetLength(0);
|
|||
|
int b = Program.chars.GetLength(1);
|
|||
|
private void PrintCharArray()
|
|||
|
{
|
|||
|
while (Program.IsWhile)
|
|||
|
{
|
|||
|
sx();
|
|||
|
Thread.Sleep(50);
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
public void sx()
|
|||
|
{
|
|||
|
Console.SetCursorPosition(0, 0);// 设定光标位置
|
|||
|
Console.Clear();
|
|||
|
for (i = 0; i < a; i++)
|
|||
|
{
|
|||
|
for (j = 0; j < b; j++)
|
|||
|
{
|
|||
|
// Console.ForegroundColor = chars[i, j].Color;
|
|||
|
Console.Write(Program.chars[i, j].Char);
|
|||
|
}
|
|||
|
Console.WriteLine();
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// 全局键盘监听
|
|||
|
/// </summary>
|
|||
|
public void KeyThread()
|
|||
|
{
|
|||
|
new Thread(() =>
|
|||
|
{
|
|||
|
while (Program.IsWhile)
|
|||
|
{
|
|||
|
ConsoleKeyInfo consoleKeyInfo = Console.ReadKey(true);
|
|||
|
if (consoleKeyInfo.Key == ConsoleKey.Escape)
|
|||
|
{
|
|||
|
Program.IsWhile = false;
|
|||
|
Thread.Sleep(500);
|
|||
|
Console.Clear();
|
|||
|
Environment.Exit(0);
|
|||
|
return;
|
|||
|
}
|
|||
|
// Console.WriteLine(consoleKeyInfo.Key);
|
|||
|
|
|||
|
switch (consoleKeyInfo.Key)
|
|||
|
{
|
|||
|
//空格
|
|||
|
case ConsoleKey.W:
|
|||
|
case ConsoleKey.UpArrow:
|
|||
|
she.direction = 1;
|
|||
|
//Program.chars[she.y--, she.x].Char = Program.ShowChar;
|
|||
|
//Program.chars[she.y, she.x].Char = she.Char;
|
|||
|
break;
|
|||
|
case ConsoleKey.S:
|
|||
|
case ConsoleKey.DownArrow:
|
|||
|
Program.chars[she.y++, she.x].Char = Program.ShowChar;
|
|||
|
Program.chars[she.y, she.x].Char = she.Char;
|
|||
|
break;
|
|||
|
|
|||
|
case ConsoleKey.A:
|
|||
|
case ConsoleKey.LeftArrow:
|
|||
|
Program.chars[she.y, she.x--].Char = Program.ShowChar;
|
|||
|
Program.chars[she.y, she.x].Char = she.Char;
|
|||
|
break;
|
|||
|
case ConsoleKey.D:
|
|||
|
case ConsoleKey.RightArrow:
|
|||
|
Program.chars[she.y, she.x++].Char = Program.ShowChar;
|
|||
|
Program.chars[she.y, she.x].Char = she.Char;
|
|||
|
break;
|
|||
|
}
|
|||
|
//sx();
|
|||
|
}
|
|||
|
// 等待用户按下任意键后退出
|
|||
|
}).Start();
|
|||
|
}
|
|||
|
}
|