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

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

问题描述

我正在尝试创建一个简单的游戏,它需要用户在计时器用完之前进行输入.

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()

这能解决您的问题吗?

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

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