我没有成功地在互联网上搜索我想要完成的事情(可能是因为我不知道我需要什么!)到目前为止,我已经开发了一个小游戏,有几个不同的模式和一个60秒定时器为每个问题。我剩下的唯一问题是,我不知道如何在屏幕上延迟的问题之间引入2-3秒的延迟。现在,是用户得到正确或错误的问题,下一个问题立即出现在屏幕上。我想要发生的是,屏幕变成了空白(我将用xyx.Text =“”来清除文本块;除了显示“右”的文本块!或者“错了!”持续大约3秒。
在2-3秒后,程序将继续正常,随机选择一个问题显示在屏幕上。为了清晰起见,下面是我正在使用的当前代码
public sealed partial class QuickPage : Page
{
DispatcherTimer timeLeft = new Dispatcher();
int timesTicked = 60;
public void CountDown()
{
timeLeft.Tick += timeLeft_Tick;
timeLeft.Interval = new TimeSpan(0,0,0,1);
timeLeft.Start();
}
public void timeLeft_Tick(object sender, object e)
{
lblTime.Text = timesTicked.ToString();
if (timesTicked > 0)
{
timesTicked--;
}
else
{
timeLeft.Stop();
lblTime.Text = "Times Up";
}
}这里有一个线程,在这里我得到了用于倒计时器的DispatcherTimer的帮助:Help with DispatcherTimer
发布于 2015-03-06 18:55:29
示例延迟5秒:
DispatcherTimer timer = new DispatcherTimer();
// Call this method after the 60 seconds countdown.
public void Start_timer()
{
timer.Tick += timer_Tick;
timer.Interval = new TimeSpan(0, 0, 5);
bool enabled = timer.IsEnabled;
// Check and show answer is correct or wrong
timer.Start();
}
void timer_Tick(object sender, object e)
{
this.Visibility = System.Windows.Visibility.Visible;
(sender as DispatcherTimer).Stop(); // Or you can just call timer.Stop() if the timer is a global variable.
// Clear screen, go to the next question
}https://stackoverflow.com/questions/28905187
复制相似问题