コード例 #1
0
ファイル: Main.cs プロジェクト: Rullazzz/TicTacToe
        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));
            }
        }
コード例 #2
0
ファイル: Main.cs プロジェクト: Rullazzz/TicTacToe
        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;
        }