只写了这么点,也不知道是不是该用keyEventArgs
using System;
using System.Windows.Forms;
namespace 会动的方块
{
class Program
{
static void Main(string[] args)
{
int[,] map = new int[10, 10];
KeyEventArgs keyEventArgs = new KeyEventArgs(Keys1);
Block block1 = new Block();
Console.Read();
}
}
class Block
{
public int Block_x { get; set; } = 1;
public int Block_y { get; set; } = 1;
public void Drawer()
{
Console.Clear();
Console.SetCursorPosition(this.Block_x, this.Block_y);
Console.Write("■");
}
}
}
keyEventArgs里面全都是方法,没有事件。。。
没有这样的事件,可以用 Console.ReadKey() 得到输入的按键,自己写一个事件触发
如此而已
Console.CursorVisible = false;
while (true)
{
var key = Console.ReadKey(true);
if (key.Key == ConsoleKey.LeftArrow) block1.Left();
if (key.Key == ConsoleKey.RightArrow) block1.Rigth();
if (key.Key == ConsoleKey.UpArrow) block1.Up();
if (key.Key == ConsoleKey.DownArrow) block1.Down();
if (key.Key == ConsoleKey.Escape) break;
}