Exemple #1
0
        private void btnFinish_Click(object sender, EventArgs e)
        {
            bool ready = false;
            do
            {
                if (txtPlayer1.Text == "")
                {
                    MessageBox.Show("Player 1 must enter a name!");
                    txtPlayer1.Focus();
                }
                else
                    p1.Name = txtPlayer1.Text;
                if (txtPlayer2.Text == "")
                {
                    MessageBox.Show("Player 2 must enter a name!");
                    txtPlayer2.Focus();
                }
                p2.Name = txtPlayer2.Text;

                if (radAqua1.Checked)
                    p1.Color = radAqua1.BackColor;
                else if (radBlack1.Checked)
                    p1.Color = radBlack1.BackColor;
                else if (radBlue1.Checked)
                    p1.Color = radBlue1.BackColor;
                else if (radGray1.Checked)
                    p1.Color = radGray1.BackColor;
                else if (radGreen1.Checked)
                    p1.Color = radGreen1.BackColor;
                else if (radOrange1.Checked)
                    p1.Color = radOrange1.BackColor;
                else if (radPink1.Checked)
                    p1.Color = radPink1.BackColor;
                else if (radPurple1.Checked)
                    p1.Color = radPurple1.BackColor;
                else if (radRed1.Checked)
                    p1.Color = radRed1.BackColor;
                else if (radYellow1.Checked)
                    p1.Color = radYellow1.BackColor;

                if (radAqua2.Checked)
                    p2.Color = radAqua2.BackColor;
                else if (radBlack2.Checked)
                    p2.Color = radBlack2.BackColor;
                else if (radBlue2.Checked)
                    p2.Color = radBlue2.BackColor;
                else if (radGray2.Checked)
                    p2.Color = radGray2.BackColor;
                else if (radGreen2.Checked)
                    p2.Color = radGreen2.BackColor;
                else if (radOrange2.Checked)
                    p2.Color = radOrange2.BackColor;
                else if (radPink2.Checked)
                    p2.Color = radPink2.BackColor;
                else if (radPurple2.Checked)
                    p2.Color = radPurple2.BackColor;
                else if (radRed2.Checked)
                    p2.Color = radRed2.BackColor;
                else if (radYellow2.Checked)
                    p2.Color = radYellow2.BackColor;

                if (p2.Color == p1.Color)
                {
                    MessageBox.Show("Players must choose a different color than eachother, sorry.");
                    break;
                }
                else if (p1.Name == p2.Name)
                {
                    MessageBox.Show("Players must each enter a different name");
                    break;
                }
                else
                    ready = true;

                p1.GamesWon = Convert.ToInt32(lblWins1.Text);

                p2.GamesWon = Convert.ToInt32(lblWins2.Text);

            } while (ready == false);

            if (ready)
            {
                ConnectFour game = new ConnectFour(p1, p2, pList);
                this.Visible = false;
                game.ShowDialog();
                this.Close();

            }
        }