public void NextGameStep() { switch(state) { case QuatroGameState.Idle: //KickStartNextPlayer KickStartNextPlayer(); state = QuatroGameState.Playing; //Fire State change event if (StateChanged != null) StateChanged(); break; case QuatroGameState.Playing: //Check the result of the playing and act accordingly if (field.State == QuatroField.GameState.Playing) if (options.automaticPlay != QuatroOptions.AutomaticPlay.StepAnalysis) KickStartNextPlayer(); else state = QuatroGameState.Idle; else { player1.EndGame(field.getCopy()); player2.EndGame(field.getCopy()); state = QuatroGameState.Finished; } //Fire State change event if (StateChanged != null) StateChanged(); break; case QuatroGameState.Finished: break; } }
public QuatroGame(QuatroPlayer player1, QuatroPlayer player2, QuatroOptions options) { this.options = options; turnTime = (int)(options.turnSeconds * 100); state = QuatroGameState.Idle; this.player1 = player1; this.player2 = player2; //time mechanics dispatcherTimer = new System.Windows.Threading.DispatcherTimer(); dispatcherTimer.Tick += UpdateTimer; dispatcherTimer.Interval = new TimeSpan(0, 0, 0, 0, 10); field = new QuatroField(); player1.StartGame(); player2.StartGame(); if (options.automaticPlay != QuatroOptions.AutomaticPlay.StepAnalysis) NextGameStep(); }