private void TimerOnElapsed(object sender, ElapsedEventArgs elapsedEventArgs) { _timerCount++; if (_gameRepeats == 0) { StopGame(); _state = EState.Stopped; } switch (_state) { case EState.Init: _combinationIndex = 0; SetAllOutput(true); if (_timerCount > 50) { SetAllOutput(false); _state = EState.ShowCombinationOn; _timerCount = 0; _combinationIndex = 0; } break; case EState.ShowCombinationOn: _hardware.SetOutput(_combinations[_combinationIndex], true); _state = EState.ShowCombinationOnPause; _timerCount = 0; break; case EState.ShowCombinationOnPause: if (_timerCount > SHOWCOMBINATIONONSHOWTIME) { _state = EState.ShowCombinationOff; _timerCount = 0; } break; case EState.ShowCombinationOff: SetAllOutput(false); _timerCount = 0; _state = EState.ShowCombinationOffPause; break; case EState.ShowCombinationOffPause: if (_timerCount > SHOWCOMBINATIONOFFTIME) { _state = EState.ShowCombinationOn; _timerCount = 0; _combinationIndex++; if (_combinationIndex >= _combinations.Count) { _state = EState.WaitToStart; _timerCount = 0; break; } } break; case EState.WaitToStart: if (_timerCount > 100) { SetAllOutput(true); _timerCount = 0; _state = EState.WaitToStartOff; } //int input = _hardware.ReadInput(); break; case EState.WaitToStartOff: if (_timerCount > 50) { SetAllOutput(false); _timerCount = 0; _state = EState.PrepareStart; } break; case EState.PrepareStart: if (_timerCount > 10) { _state = EState.AwaitingCombination; _combinationIndex = 0; _timerCount = 0; } break; case EState.AwaitingCombination: int input = _hardware.ReadInput(); if (input > 0) { IGameResult gameResult = new GameResult(); gameResult.ReactiontimeMillisseconds = 0; gameResult.Success = input == _combinations[_combinationIndex]; OnGameResult?.Invoke(gameResult); _state = EState.ShiftToNext; } if (_timerCount > 250) { IGameResult gameResult = new GameResult(); gameResult.ReactiontimeMillisseconds = 0; gameResult.Success = false; OnGameResult?.Invoke(gameResult); _state = EState.ShiftToNext; } break; case EState.ShiftToNext: if (_hardware.ReadInput() == 0) { _combinationIndex++; if (_combinationIndex >= _combinations.Count) { SetAllOutput(true); } else { _state = EState.AwaitingCombination; } } break; } }
private void TimerOnElapsed(object sender, ElapsedEventArgs elapsedEventArgs) { if (_gameRepeats == 0) { StopGame(); _state = EState.Stopped; } switch (_state) { case EState.Init: if (_timerCount == 0) { SetAllOutput(true); _timerCount++; break; } _timerCount++; if (_timerCount > 10) { _state = EState.InitBlink1; _timerCount = 0; } break; case EState.InitBlink1: if (_timerCount == 0) { SetAllOutput(false); _timerCount++; break; } _timerCount++; if (_timerCount > 5) { _state = EState.InitBlink2; _timerCount = 0; } break; case EState.InitBlink2: if (_timerCount == 0) { SetAllOutput(true); _timerCount++; break; } _timerCount++; if (_timerCount > 10) { _state = EState.InitBlink3; _timerCount = 0; } break; case EState.InitBlink3: SetAllOutput(false); _state = EState.GameReady; break; case EState.GameReady: break; case EState.LightButton: _buttonNumber = GetbuttonToLight(); _hardware.SetOutput(_buttonNumber, true); _timerCount = 0; _state = EState.AwiatingPress; _stopwatch.Restart(); break; case EState.AwiatingPress: _timerCount++; if (_timerCount > 250) { SetAllOutput(false); _state = EState.CoolDown; _stopwatch.Stop(); IGameResult gameResult = new GameResult(); gameResult.Success = false; gameResult.ReactiontimeMillisseconds = _stopwatch.ElapsedMilliseconds; OnGameResult?.Invoke(gameResult); } int input = _hardware.ReadInput(); if (input > 0) { _stopwatch.Stop(); SetAllOutput(false); _state = EState.CoolDown; IGameResult gameResult = new GameResult(); gameResult.ReactiontimeMillisseconds = _stopwatch.ElapsedMilliseconds; gameResult.Success = input == _buttonNumber; OnGameResult?.Invoke(gameResult); } break; case EState.CoolDown: _gameRepeats--; _timerCount = 0; _state = EState.CoolDownTimer; break; case EState.CoolDownTimer: _timerCount++; if (_timerCount > 10) { _state = EState.LightButton; } break; } }