private void ElapsedTimerAction(object sender, System.Timers.ElapsedEventArgs e) { lock (lockObj) { if (TimeRemainingWhite == 0 && OutOfTime != null) { OutOfTime.Invoke(this, Base.Color.White); } if (TimeRemainingBlack == 0 && OutOfTime != null) { OutOfTime.Invoke(this, Base.Color.Black); } var elapsed = Elapsed; if (Math.Abs(lastElapseUpdate - elapsed) >= 100 || (elapsed == 0 && lastElapseUpdate != 0)) { lastElapseUpdate = elapsed; if (TimeRemainingChanged != null) { TimeRemainingChanged.Invoke(this); } } } }
IEnumerator GameTimer() { while (_timeRemaining > 0) { yield return(new WaitForSeconds(1)); _timeRemaining--; TimeRemainingChanged?.Invoke(_timeRemaining); } EndGame(); }
protected override void OnUpdate(GameTime gameTime) { TimeRemaining = Interval - CurrentTime; TimeRemainingChanged.Raise(this, EventArgs.Empty); if (CurrentTime >= Interval) { State = TimerState.Completed; CurrentTime = Interval; TimeRemaining = TimeSpan.Zero; Completed.Raise(this, EventArgs.Empty); } }