【发布时间】:2017-02-09 11:54:10
【问题描述】:
我正在尝试使用 Visual Studio 在 c# 中为控制台创建一个简单的 clickclickclick 游戏。唯一还没有工作的是控制台如何计算键盘上 any 按钮的按下次数。现有代码的问题是即使释放按钮后该语句仍保持为真。
using System;
using System.Diagnostics;
public class clickclickclickgame
{
public static void Main()
{
Stopwatch timer = new Stopwatch();
int amountofpresses = 0;
timer.Start();
while (timer.ElapsedMilliseconds < 2000)
{
if (Console.KeyAvailable == true) // this is where my question is about.
{
timer.Restart();
amountofpresses++;
}
timer.Stop();
Console.WriteLine(amountofpresses);
}
}
【问题讨论】:
-
你必须
Read密钥... -
@Damion Gans 阅读我的回答,我会解释一些事情并为您提供解决方案。