/// <summary>
        /// The click event for the submit button.
        /// </summary>
        /// <param name="sender">The Sender</param>
        /// <param name="e">The event arguments</param>
        private void buttonSubmit_Click(object sender, EventArgs e)
        {
            if (this.gameControl.ActivePlayer.SecretCode == string.Empty)
            {
                foreach (TextBox tb in this.codeEntryList)
                {
                    this.codeText = this.codeText + tb.Text;
                }

                var uniques = (new HashSet <char>(this.codeText)).Count;

                if (uniques != this.gameControl.CodeLength)
                {
                    MessageBox.Show("No repeating characters allowed.");
                    this.codeText = string.Empty;
                }
                else
                {
                    this.gameControl.ActivePlayer.SecretCode = this.codeText;
                }
            }

            if (this.gameControl.Versus == true)
            {
                // If P1's code is set, but P2's code is not, change turns, close screen, and reopen this screen again.
                if (this.gameControl.ActivePlayer.SecretCode != string.Empty && this.gameControl.Opponent.SecretCode == string.Empty)
                {
                    this.gameControl.ChangeTurns();
                    CodeEnterScreen player2CodeEnterScreen = new CodeEnterScreen(this.gameControl, this.gameControl.ActivePlayer);
                    player2CodeEnterScreen.Show();
                    this.Close();
                }

                // If both players have their codes entered, open a new GameBoard.
                if (this.gameControl.ActivePlayer.SecretCode != string.Empty && this.gameControl.Opponent.SecretCode != string.Empty)
                {
                    GameBoard gameBoard = new GameBoard(this.gameControl);
                    this.gameControl.ChangeTurns();
                    gameBoard.Show();
                    this.Close();
                }
            }
            else
            {
                // Game is in single player mode.
                if (this.gameControl.ActivePlayer.SecretCode != string.Empty)
                {
                    GameBoard gameBoard = new GameBoard(this.gameControl);
                    gameBoard.Show();
                    gameBoard.BringToFront();
                    gameBoard.Focus();
                    this.Close();
                }
            }
        }
예제 #2
0
        /// <summary>
        /// Initializes a new instance of the Picker class for use on the CodeEntry form.
        /// </summary>
        /// <param name="ces">A reference to the CodeEntry form.</param>
        /// <param name="gameControl">A reference to the GameControl form.</param>
        /// <param name="id">A passed-in value to be assigned as this Picker's ID.</param>
        public Picker(CodeEnterScreen ces, GameController gameControl, int id)
        {
            this.ces          = ces;
            this.gc           = gameControl;
            this.Id           = id;
            this.BorderStyle  = BorderStyle.FixedSingle;
            this.TextAlign    = ContentAlignment.MiddleCenter;
            this.Font         = new Font(this.Font.FontFamily, 50 * 3 / 8, FontStyle.Regular);
            this.InitialColor = this.BackColor;

            Label keylabel = new Label();

            keylabel.Location = new Point(this.Location.X, this.Location.Y);
            keylabel.Text     = id.ToString();
            keylabel.Font     = new Font(this.Font.FontFamily, 6, FontStyle.Regular);
            keylabel.Width    = 10;
            keylabel.Height   = 10;

            this.Controls.Add(keylabel);

            this.MouseHover += (s, z) =>
            {
                this.BackColor = Color.Aquamarine;
            };

            this.MouseLeave += (s, z) =>
            {
                if (gc.ActivePlayer.SelectedPicker != this)
                {
                    this.BackColor = InitialColor;
                }
            };

            this.Click += (s, z) =>
            {
                gameControl.ActivePlayer.SelectedPicker = this;
                this.BackColor = Color.Cyan;
                soundPick.Play();

                foreach (Picker p in ces.Pickers)
                {
                    if (p != this)
                    {
                        p.BackColor = this.InitialColor;
                    }
                }
            };
        }
        /// <summary>
        /// The Submit button click event.
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The event arguments.</param>
        private void buttonSubmit_Click(object sender, EventArgs e)
        {
            this.P1 = new Player(textBoxP1name.Text.ToString(), this.checkBoxP1isHuman.Checked);
            this.P2 = new Player(textBoxP2name.Text.ToString(), this.checkBoxP2isHuman.Checked);
            this.P1.AttemptsUsed = 0;
            this.P2.AttemptsUsed = 0;

            // Begin with P1's turn.
            this.ActivePlayer = this.P1;
            this.Opponent     = this.P2;

            this.CodeLength      = int.Parse(this.comboBoxCodeLength.SelectedItem.ToString());
            this.CodeDepth       = int.Parse(this.comboBoxCodeDepth.SelectedItem.ToString());
            this.AttemptsAllowed = int.Parse(this.comboBoxGuesses.SelectedItem.ToString());

            this.Versus = radioButtonVersus.Checked;

            CodeEnterScreen codeEnter = new CodeEnterScreen(this, this.ActivePlayer);

            codeEnter.ShowDialog();
        }