0

我有这个问题。我有用于在控制台中绘制文本的 while 循环,我想让它具有交互性。我有两个 if 语句,其中包含实际键的条件。所以如果我按'W'它会做一些事情,但这不会起作用。我有两个项目,engine.dll 和 testApp 用于测试。继承人的代码:

 while (true)
            {
                game g = new game();
                g.Draw(cHP, mHP, name,posX,posY,blip);
                Thread.Sleep(50);
                Console.CursorVisible = false;
                ConsoleKeyInfo cki = new ConsoleKeyInfo();
                //if (Console.KeyAvailable) { Console.CursorVisible = true; break; }
                if (cki.KeyChar == 'w') MoveY(1); // Here it is
                if (cki.KeyChar == 's') MoveY(-1); // and here
            }
4

1 回答 1

0

不确定您在最终版本中想要什么,但对现有代码的修复将是这个

 Console.CursorVisible = false;
 while(true)
 {
       game g = new game();
       g.Draw(cHP, mHP, name,posX,posY,blip);
       Thread.Sleep(50); //might not be required depending
                         //on what you want to do

       var cki = Console.ReadKey(true);
       if (cki.KeyChar == 'w') MoveY(1);// Here it is
       if (cki.KeyChar == 's') MoveY(-1); // and here
 }
于 2013-06-30T17:08:41.987 回答