I have tried asking this question two or three times before but have not been able to phase it properly so I want to try one more time. I am making a training stopwatch app. The function of the app is to count 10 seconds, to allow the trainee 10 seconds to prepare. Once that time has elapsed, it counts to 20 seconds in which the trainee does a hard workout for the 20 seconds. After that, there is a 10 second rest time. Then it loops back to the 20 second workout and continues this loop for 8 rounds.
My problem is that it will begin the 10 second preparation but then it loops back into the 10 second timer. For some reason my if else statement keeps looping back into the preparation time. I'm using a stopwatch and timespan for the the if statement.
private void timer_Tick(object sender, EventArgs e)
{
//throw new NotImplementedException();
//timer timespan is more than zero, start stopwatch(get the prepare counter going)
if (timerWatch.Elapsed < new TimeSpan(0, 0, 11))// if its 5sec
{
milllisecond = timerWatch.ElapsedMilliseconds;
second = milllisecond / 1000;
milllisecond = milllisecond % 1000;
minute = second / 60;
second = second % 60;
hour = minute / 60;
minute = minute % 60;
txtblTime.Text = minute.ToString("00") + ":" + second.ToString("00");
}
else if (timerWatch.Elapsed >= new TimeSpan(0, 0, 10) && timerWatch.Elapsed < new TimeSpan(0, 0, 21))//more than 4sec
{
timerWatch.Restart();
milllisecond = timerWatch.ElapsedMilliseconds;
second = milllisecond / 1000;
milllisecond = milllisecond % 1000;
minute = second / 60;
second = second % 60;
hour = minute / 60;
minute = minute % 60;
txtblTime.Text = minute.ToString("00") + ":" + second.ToString("00");
txtblPrepare.Visibility = System.Windows.Visibility.Collapsed;
txtblGo.Visibility = System.Windows.Visibility.Visible;
}
else if (timerWatch.Elapsed < new TimeSpan(0, 0, 21))
{
timerWatch.Restart();
milllisecond = timerWatch.ElapsedMilliseconds;
second = milllisecond / 1000;
milllisecond = milllisecond % 1000;
minute = second / 60;
second = second % 60;
hour = minute / 60;
minute = minute % 60;
txtblTime.Text = minute.ToString("00") + ":" + second.ToString("00");
txtblGo.Visibility = System.Windows.Visibility.Collapsed;
}
else
txtblTime.Text = "Times Up!";
}
Aucun commentaire:
Enregistrer un commentaire