2014-12-26 24 views
-1

我創建了一個定時器,它有一個準備時間爲5秒的倒數第一次,但之後我需要循環(工作時間和休息時間)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

您沒有5秒8次的條件。 – MikeG

+0

我想循環(工作計時器+休息計時器)8次,這就是所有'for(rounds = 0; rounds <9; rounds ++){工作計時器,比其他計時器}' –

回答

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 {} 

此外,不要忘記重新計算你的秒數,因爲這個例子需要增量滴答。