有没有办法有一个倒数计时器,同时等待输入? [英] Is there a way to have a countdown timer while waiting for input?

查看:278
本文介绍了有没有办法有一个倒数计时器,同时等待输入?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图创建一个简单的游戏,需要用户输入的计时器耗尽。



基本上,该网页将具有时间加载,并等待用户说了正确的答案。如果时间耗尽,比赛结束了,但如果用户得到它的权利,他移动到下一个问题。



(我已经得到了部分的讲话制定出来的,我只需要弄清楚定时器)



有一个简单的方法来做到这一点?


解决方案

  //添加使用使用System.Windows.Threading程序语句
;

//创建一个定时器
DispatcherTimer mytimer;

//设置定时
myTimer =新DispatcherTimer();
myTimer.Interval = System.TimeSpan.FromSeconds(10);
myTimer.Tick + = myTimer_Tick;

//当键入+ =,这个方法框架应该拿出
//自动。但是,如果没有在键入此。
无效myTimer_Tick(对象发件人,EventArgs五)
{
//这永远运行在定时器熄灭时(在这种情况下,每10秒)
}

//运行定时器
myTimer.Start()

//停止计时器
myTimer.Stop()

这是否解决你的问题?


I'm trying to create a simple game that requires the user's input before the timer runs out.

Basically, the page will load with a time, and wait for the user to say the correct answer. If the time runs out, the game is over, but if the user gets it right, he moves on to the next question.

(i've got the speech part worked out, I just need to figure out the timer)

Is there an easy way to accomplish this?

解决方案

//Add Using Statement
using System.Windows.Threading;

//Create Timer
DispatcherTimer mytimer;

//Setup Timer
myTimer = new DispatcherTimer();
myTimer.Interval = System.TimeSpan.FromSeconds(10);
myTimer.Tick += myTimer_Tick;

// When you type the +=, this method skeleton should come up
// automatically. But type this in if it doesn't.
void myTimer_Tick(object sender, EventArgs e)
{
    //This runs when ever the timer Goes Off (In this case every 10 sec)
}

//Run Timer
myTimer.Start()

//Stop Timer
myTimer.Stop()

Does this solve your question?

这篇关于有没有办法有一个倒数计时器,同时等待输入?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆