private void Button_Click(object sender, EventArgs e) { if (sender is Button button) { if (button.Text != "") { return; } if (IsFirstPlayer) { button.Text = "X"; IsFirstPlayer = false; PlayerTurnlabel.Text = SecondPlayer; } else { button.Text = "O"; IsFirstPlayer = true; PlayerTurnlabel.Text = FirstPlayer; } if (CheckGame(IsFirstPlayer ? SecondPlayer : FirstPlayer)) { var formContinue = new ContinueGame(); if (formContinue.ShowDialog() == DialogResult.Yes) { // TODO: Переделать. var formNewGame = new NewGame(); formNewGame.ShowDialog(); if (formNewGame.DialogResult == DialogResult.OK && formNewGame.IsNewNames) { formNewGame.SetNewNames(ref FirstPlayer, ref SecondPlayer); ResetButtons(); } } else { Application.Exit(); } } } else { throw new ArgumentNullException(nameof(sender)); } }
public Main() { InitializeComponent(); var formNewGame = new NewGame(); formNewGame.ShowDialog(); if (formNewGame.DialogResult == DialogResult.OK && formNewGame.IsNewNames) { formNewGame.SetNewNames(ref FirstPlayer, ref SecondPlayer); } this.Width = 400; this.Height = 500; CreateButtons(buttons); SetButtons(buttons); IsFirstPlayer = true; PlayerTurnlabel.Text = FirstPlayer; }