Example #1
0
 // This method is invoked whenever the player clicks the "Start" button.
 private void ButtonStart_Click(object sender, EventArgs e)
 {
     BoolPgia.GenerateRandomPassword();
     this.Hide();
     PinResult.NumberOfGuesses = 0;
     new Board().ShowDialog();
     this.Show();
 }
Example #2
0
        // This method is invoked whenever the player clicks the arrow button of this user control class instance.
        private void m_ButtonArrow_Click(object sender, EventArgs e)
        {
            if (Enumerable <BoolPgia.eCharacter> .HasRepetitions(guess))
            {
                MessageBox.Show(BoolPgia.k_StringNoRepetitionsAllowed, "What's wrong with you?", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
            else if (BoolPgia.AlreadyTried(guess))
            {
                MessageBox.Show(BoolPgia.k_StringThisGuessHasAlreadyBeenTried, "What's wrong with you?", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
            else
            {
                this.Enabled = false;
                s_NumberOfGuesses++;
                if (s_NumberOfGuesses < s_PinsResults.Length)
                {
                    s_PinsResults[s_NumberOfGuesses].Enabled = true;
                }

                byte numberOfBoolim, numberOfPgiot;
                BoolPgia.CalculateResult(guess, out numberOfBoolim, out numberOfPgiot);

                long indexOfResultButton = 0;
                for (byte i = 0; i < numberOfBoolim; i++)
                {
                    resultButtons[indexOfResultButton].BackColor = Color.Black;
                    indexOfResultButton++;
                }

                for (byte i = 0; i < numberOfPgiot; i++)
                {
                    resultButtons[indexOfResultButton].BackColor = Color.Yellow;
                    indexOfResultButton++;
                }

                if (numberOfBoolim == BoolPgia.k_LengthOfPassword)
                {
                    showPassword();
                    MessageBox.Show(BoolPgia.GetStringPlayerSuccessfullyGuessedPassword(s_NumberOfGuesses), "Congratulations!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    gameOver();
                }
                else if (s_NumberOfGuesses == s_NumberOfChances)
                {
                    showPassword();
                    MessageBox.Show(BoolPgia.k_StringLoss, "Loser!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    gameOver();
                }
            }
        }