【问题标题】:Is there a way to have a countdown timer while waiting for input?有没有办法在等待输入时设置倒数计时器?
【发布时间】:2013-06-23 07:25:38
【问题描述】:

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

基本上,页面会加载一段时间,并等待用户说出正确答案。如果时间用完,游戏就结束了,但如果用户做对了,他会继续下一个问题。

(我已经解决了演讲部分,我只需要弄清楚计时器)

有没有简单的方法可以做到这一点?

【问题讨论】:

  • 我看不出问题出在哪里。创建一个计时器和倒计时:D
  • 我以前从未做过任何 Windows Phone 应用程序,而且我对 c# 还是很陌生,所以我什至不知道要谷歌什么。
  • 请说明您的问题。你不知道如何显示倒计时或如何倒计时或什么:)?
  • 我不一定需要展示它,如果时间用完并且用户没有回答,我只需要让计时器停止正在发生的事情。
  • 谷歌如何使用“定时器”类并做必要的事情。另外我会推荐你​​ wpftutorial.net 来了解 XAML。

标签: c# xaml windows-phone-8


【解决方案1】:
//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()

这能解决你的问题吗?

【讨论】:

    猜你喜欢
    • 2020-03-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-07-11
    相关资源
    最近更新 更多