private void Play(string playerX, string playerO, int rounds) { this.score = new Dictionary <GameRound, Game>(); this.game = Game.NewGame(playerX, playerO); this.round = new GameRound(rounds, 1); this.GameViewBeginState(); }
private void TurnButton_Clicked(object sender, EventArgs e) { if (sender is Button button) { var pos = Convert.ToInt32(button.Tag) - 1; if (!this.game.IsEmpty(pos)) { return; } button.Enabled = false; this.game.MarkSpace(pos, g => { button.Text = g.Turn.Marker(); g.Winner() .When( some: winner => { MessageBox.Show($"The winner of round {this.round.Current} is {winner}"); this.score.Add(this.round, g); if (this.round.RoundsLeft > 0) { this.round = this.round.Next(); this.game = g.RestartGame(); if (this.round.IsFinal) { MessageBox.Show($"Final round."); } this.GameViewBeginState(); } else { this.GameViewEndState(); } }, none: () => { var draw = !g.HasEmptySpaces(); if (draw) { MessageBox.Show("It's a draw"); } else { this.SwitchTurns(); } }); }); } }