Example #1
0
        /// <summary>
        /// This is the ckick event handler for the "Check" button when clicked it checks if there are any empty guesses. If guesses are filled it creates a
        /// new guess list full of strings equal to guess buttons back color. then passes the "guesses" list to guess class. It then calls the draw pins class
        /// which works out the physical reprsentation of the pins and finally enables the next row of guess buttons
        /// </summary>
        private void btn_Check_Click(object sender, EventArgs e)
        {
            List <string> guesses = new List <string>();

            for (int i = guessCount; i < 4 * difficulty; i += difficulty)//checks for empty guesses
            {
                string buttonName = "btn_Guess" + i;
                if (tlp_Guesses.Controls[buttonName].BackColor == defaultColor)
                {
                    MessageBox.Show("Please make sure that every guess has been used.");
                    return;
                }
            }

            for (int i = guessCount; i < 4 * difficulty; i += difficulty) //add each guess ball into the "guesses" List
            {
                string buttonName = "btn_Guess" + i;
                guesses.Add(tlp_Guesses.Controls[buttonName].BackColor.ToString());
                tlp_Guesses.Controls[buttonName].Enabled = false;
            }

            GuessClass guess = new GuessClass(guesses);

            drawPins(guess);

            guessCount++;

            for (int i = guessCount; i < 4 * difficulty; i += difficulty)
            {
                string buttonName = "btn_Guess" + i;
                tlp_Guesses.Controls[buttonName].Enabled = true;
            }
        }
Example #2
0
        /// <summary>
        /// This method is used to interpret the count of black and white pins from solution to the visual version that the user will see. It also
        /// checks for winner as well, if a winner is found it opens a new form if the user wants to play again and the new form calls a new instance
        /// of the game.
        /// </summary>
        /// <param name="guess"> this is the current user guess </param>
        private void drawPins(GuessClass guess)
        {
            if (solution.isMatch(guess.intGuessList) == true)
            {
                string buttonName = "btn_Pin" + index;
                tlp_Pins.Controls[buttonName].BackColor = System.Drawing.Color.Black;
                buttonName = "btn_Pin" + (index + 1);
                tlp_Pins.Controls[buttonName].BackColor = System.Drawing.Color.Black;
                buttonName = "btn_Pin" + (index + difficulty * 2);
                tlp_Pins.Controls[buttonName].BackColor = System.Drawing.Color.Black;
                buttonName = "btn_Pin" + (index + difficulty * 2 + 1);
                tlp_Pins.Controls[buttonName].BackColor = System.Drawing.Color.Black;
                tlp_Solution.Visible = true;
                tmr_GameTimer.Stop();
                Player player = new Player(txt_Name.Text, difficultyToString(), guessCount, secondsPlayed.ToString());
                leaderboard.addPlayer(player);
                DialogResult dialogResult = MessageBox.Show("You have Won the Game, Would you like to play again?", "Game Over", MessageBoxButtons.YesNo);
                if (dialogResult == DialogResult.Yes)
                {
                    leaderboard.writeLeaderboard();
                    this.Hide();
                    frm_NewGame newGame = new frm_NewGame();
                }
                else if (dialogResult == DialogResult.No)
                {
                    leaderboard.writeLeaderboard();
                    Application.Exit();
                }
            }
            else
            {
                if (guessCount + 1 != difficulty)
                {
                    MessageBox.Show("No Good Try again.");
                }
                else
                {
                    tlp_Solution.Visible = true;
                    DialogResult dialogResult = MessageBox.Show("You have lost the Game, Would you like to play again?", "Game Over", MessageBoxButtons.YesNo);
                    if (dialogResult == DialogResult.Yes)
                    {
                        this.Hide();
                        frm_NewGame newGame = new frm_NewGame();
                    }
                    else if (dialogResult == DialogResult.No)
                    {
                        Application.Exit();
                    }
                }
            }

            int count = 0;

            if (solution.hint.getBlackPegCount() != 0)
            {
                for (int i = 0; i < solution.hint.getBlackPegCount(); i++)
                {
                    if (i == 0)
                    {
                        string buttonName = "btn_Pin" + index;
                        tlp_Pins.Controls[buttonName].BackColor = System.Drawing.Color.Black;
                    }
                    else if (i == 1)
                    {
                        string buttonName = "btn_Pin" + (index + 1);
                        tlp_Pins.Controls[buttonName].BackColor = System.Drawing.Color.Black;
                    }
                    else if (i == 2)
                    {
                        string buttonName = "btn_Pin" + (index + difficulty * 2);
                        tlp_Pins.Controls[buttonName].BackColor = System.Drawing.Color.Black;
                    }
                    else if (i == 3)
                    {
                        string buttonName = "btn_Pin" + (index + difficulty * 2 + 1);
                        tlp_Pins.Controls[buttonName].BackColor = System.Drawing.Color.Black;
                    }
                    count = solution.hint.getBlackPegCount();
                }
            }

            if (solution.hint.getWhitePegCount() != 0)
            {
                for (int j = count; j < count + solution.hint.getWhitePegCount(); j++)
                {
                    if (j == 0)
                    {
                        string buttonName = "btn_Pin" + index;
                        tlp_Pins.Controls[buttonName].BackColor = System.Drawing.Color.White;
                    }
                    else if (j == 1)
                    {
                        string buttonName = "btn_Pin" + (index + 1);
                        tlp_Pins.Controls[buttonName].BackColor = System.Drawing.Color.White;
                    }
                    else if (j == 2)
                    {
                        string buttonName = "btn_Pin" + (index + difficulty * 2);
                        tlp_Pins.Controls[buttonName].BackColor = System.Drawing.Color.White;
                    }
                    else if (j == 3)
                    {
                        string buttonName = "btn_Pin" + (index + difficulty * 2 + 1);
                        tlp_Pins.Controls[buttonName].BackColor = System.Drawing.Color.White;
                    }
                }
            }

            index += 2;
        }