Exemplo n.º 1
0
        // ----- Form loading and closing functions -----

        // Function called when the form is loaded
        private void mainGame_Load(object sender, EventArgs e)
        {
            // Setting the Find label to empty
            lblFind.Text = "";
            // Making an object of the learnWindow form and passing colorString to the constructor
            learnWindow objLearnWindow = new learnWindow(colorString);

            // Opening the learnWindow form in modal mode to ensure user learns before continuing
            objLearnWindow.ShowDialog();
            // After the learnWindow form is closed, the objLearnWindow is detroyed to free memory
            objLearnWindow.Dispose();
            // fillColors is called to get the form ready for the game
            fillColors();
        }
Exemplo n.º 2
0
        // Function called when the color selected is correct
        private void correctAnswer()
        {
            // If statement checks if the file exists before it is imported
            // This makes sure the error "File Not Found" is avoided
            if (File.Exists("myResources\\picSmile.png"))
            {
                // The picResonse is set to the image picSmile with a happy smiley face
                picResponse.BackgroundImage = Image.FromFile("myResources\\picSmile.png");
            }
            // correctCount is increased by 1
            correctCount++;
            // progressBar is moved forward by 10
            progressBar.Increment(10);

            // If statement checks if the correctCount is 10, signifying completion of 1st level
            if (correctCount == 10)
            {
                // MessageBox is shown to the user, letting the user know that first level is complete
                MessageBox.Show("You made it to Level 2!\nYou get new colors to play with!", "Congratulations!!",
                                MessageBoxButtons.OK, MessageBoxIcon.Asterisk);

                // The new colors are stored into the colorString by using new String[]
                colorString = new String[] { "Orange", "Purple", "Pink", "Aqua" };

                // An object of the learnWindow is made and the new colorString is passed to the constructor
                learnWindow objLearnWindow = new learnWindow(colorString);
                // learnWindow form is displayed in modal mode
                objLearnWindow.ShowDialog();
                // Freeing the memory of the object objLearnWindow
                objLearnWindow.Dispose();
                // lblMsg is updated with a new message over the progressBar
                lblMsg.Text = "Fill this up to win the game!";
                // progressBar is reset to 0
                progressBar.Value = 0;
            }
            // else if statement checks if the correctCount is equal to 20
            else if (correctCount == 20)
            {
                // Message box is shown to tell user he/she won the game
                MessageBox.Show("You found my colors!", "You Win!!", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);

                // If statement displays a message box asking if user wants to play again
                if (MessageBox.Show("Do you want to play again?", "", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                {
                    // For user selection yes, the game is reset

                    // correctCount is reset to 0
                    correctCount = 0;
                    // colorString is reset to original values
                    colorString = new String[] { "Red", "Blue", "Green", "Yellow" };
                    // progressBar is reset to 0
                    progressBar.Value = 0;
                    // An object of the learnWindow is made and the new colorString is passed to the constructor
                    learnWindow objLearnWindow = new learnWindow(colorString);
                    // learnWindow form is displayed in modal mode
                    objLearnWindow.ShowDialog();
                    // Freeing the memory of the object objLearnWindow
                    objLearnWindow.Dispose();
                    // lblMsg is updated to be the same as round 1
                    lblMsg.Text = " Fill this up to get new Colors!";

                    // If statement checks if the file exists before it is imported
                    // This makes sure the error "File Not Found" is avoided
                    if (File.Exists("myResources\\empty.png"))
                    {
                        // The picResonse is set to the image "empty.gif"
                        picResponse.BackgroundImage = Image.FromFile("myResources\\empty.png");
                    }
                }
                else
                {
                    // For user selection no, the game exits

                    // MessageBox is shown notifying the closing of the game
                    MessageBox.Show("Game will now close...\n\nThank you for playing \"Find My Colors\"!!", "Thank you",
                                    MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                    // Form closing event is called after blnConfirm is set to true, ensuring no confirm exit
                    blnConfirm = true;
                    // Closes this form
                    this.Close();
                }
            }
        }