我正在创建一个计时器,有一个5秒的准备时间倒数第1,但后来我需要循环(工作时间和休息时间)8次,然后完成。在那一刻它只是倒计时每个计时器
if(prepTicks>0)
{
txtblPrepare.Visibility = System.Windows.Visibility.Visible;
txtblGo.Visibility = System.Windows.Visibility.Collapsed;
txtblTime.Text = prepTicks + " Seconds Remaining";
prepTicks--;
}
else if (workTick > 0)
{
txtblPrepare.Visibility = System.Windows.Visibility.Collapsed;
txtblGo.Visibility = System.Windows.Visibility.Visible;
txtblTime.Text = workTick + " Seconds Remaining";
workTick--;
}
else if (restTicks > 0)
{
txtblGo.Visibility = System.Windows.Visibility.Collapsed;
txtblRest.Visibility = System.Windows.Visibility.Visible;
txtblTime.Text = restTicks + " Seconds Remaining";
restTicks--;
}
else
{
txtblRest.Text = "Congratulations";
txtblTime.Text = "Times Up";
}
答案 0 :(得分:1)
以下是增量刻度的方法:
if(prepTicks <= 5) {}
else if (workTick <= 8) {}
else if (restTicks <= 8) {}
else {}
或者,如果工作和休息的组合受到限制:
if(prepTicks <= 5) {}
else if (workTick + restTicks <= 8 && restTicks > workTick) {} // altermating work and rest
else if (restTicks + workTick <= 8) {}
else {}
此外,不要忘记重新计算剩余的秒数,因为此示例需要增量滴答。