private void TmrCountdown_Tick(object sender, EventArgs e)
        {                                            // On tick of the TmrCountdown
            TimerCount--;                            // Decrease one from the timer
            LblToStart.Text = TimerCount.ToString(); // Display the timer value on the panel

            if (TimerCount == 3)
            {                                // If the timer value is equal to 3
                LblGameStart.Visible = true; // Display the time till game start text
            }

            if (TimerCount == 0)
            {                                 // If the timer value is equal to 0
                LblToStart.Visible   = false; // Hide the second countdown
                LblGameStart.Visible = false; // Hide the time till game start text

                ButtonClicked = 1;            // Set the button as clicked

                // Enable the games timers
                TmrShark.Enabled       = true;
                TmrSurfer.Enabled      = true;
                BottleTimer.Enabled    = true;
                BottleTimeWait.Enabled = true;

                TmrCountdown.Stop(); // Stop the TmrCountdown

                TmrPopUp.Start();
                LblPopUp.Visible = true; // Display the popup text
                LblPopUp.Text    = "Game started";
            }
        }
        private void BtnHard_Click(object sender, EventArgs e)
        {     // If the user clicks on the hard difficulty button
            if (UsernameValid == 0)
            { // If the user name is valid
                // Show the countdown to the game starts
                LblToStart.Visible   = true;
                LblGameStart.Visible = true;

                // Display the sidebar elements such as lives textbox, lives label, etc
                LvlCount.Visible      = true;
                LvlTxt.Visible        = true;
                ScoreCount.Visible    = true;
                ScoreTxt.Visible      = true;
                label1.Visible        = true;
                LvsCount.Visible      = true;
                LvsTxt.Visible        = true;
                LevelProgress.Visible = true;
                LblName.Visible       = true;

                // Hide the welcome to game message, username, instructions
                LblInstructions.Visible = false;
                TbUsername.Visible      = false;
                LblWelcome.Visible      = false;
                LblUsername.Visible     = false;

                // Hide the difficulty buttons
                BtnHard.Visible   = false;
                BtnMedium.Visible = false;
                BtnEasy.Visible   = false;

                // Disable the difficulty buttons to allow the surfer to move
                BtnHard.Enabled   = false;
                BtnMedium.Enabled = false;
                BtnEasy.Enabled   = false;

                // Disable the timers
                TmrShark.Enabled       = false;
                TmrSurfer.Enabled      = false;
                BottleTimer.Enabled    = false;
                BottleTimeWait.Enabled = false;

                lives       = 1;                             // Set the lives count to 1
                LvsTxt.Text = lives.ToString();              // Display the lives count in the LvsText textbox

                TmrCountdown.Start();                        // Start the countdown timer

                LblName.Text = "Welcome " + TbUsername.Text; // Edit the text to say Welcome then their name

                TmrPopUp.Start();
                LblPopUp.Visible = true; // Display the popup text
                LblPopUp.Text    = "Hard difficulty selected";
            }
        }
        private void CheckScore()
        {                                         // Initiate the CheckScore method/ function
            if (score % 20 == 0)
            {                                     // If the score is divisible by 25
                level      += 1;                  // Add one to level count
                LvlTxt.Text = level.ToString();   // Convert the level to a string, then display it on the LvlTxt textbox

                LevelProgress.Value = 0;          // Set the levelprogress bar to a value of 0
                LevelProgress.Step  = 0;          // Set the levelprogress bar to a step of 0

                score         = 0;                // Set the score count to 0
                ScoreTxt.Text = score.ToString(); // Convert the score to a string, then display it on the ScoreTxt textbox

                TmrPopUp.Start();
                LblPopUp.Visible = true; // Display the popup text
                LblPopUp.Text    = "You reached level " + level;
            }
        }
        private void CheckLives()
        {     // Initiate the CheckLives method/ function
            if (lives == 0)
            { // If the user has no lives left
                // Disable the timers
                TmrShark.Enabled       = false;
                TmrSurfer.Enabled      = false;
                BottleTimer.Enabled    = false;
                BottleTimeWait.Enabled = false;

                TmrPopUp.Start();
                LblPopUp.Visible = true; // Display the popup text
                LblPopUp.Text    = "Game over!";

                MessageBox.Show("Game Over!! You lost all your lives and reached level " + level + ", score " + score + "!"); // Display the game over message, telling the user their level and score count
                this.Close();                                                                                                 // Close the game
            }
        }
        private void TmrPopUp_Tick(object sender, EventArgs e)
        {                    // On tick of the TmrPopUp
            TmrPopUpCount--; // Decrease one from the timer

            if (TmrPopUpCount == 3)
            {                            // If the timer value is equal to 3
                LblPopUp.Visible = true; // Display the popup text
            }

            if (TmrPopUpCount == 0)
            {                             // If the timer value is equal to 0
                LblPopUp.Visible = false; // Hide the popup text

                TmrPopUpCount = 3;

                TmrPopUp.Stop(); // Stop the TmrPopUp
            }
        }
        private void TbUsername_TextChanged(object sender, EventArgs e)
        {                                           // On change up of the textbox
            string UsernameValue = TbUsername.Text; // Create a string with the value of the TbUsername value

            if (UsernameValue == "")
            {                      // If the username textbox is empty
                UsernameValid = 1; // Set the usernamevalid to 1, which disables the user from selecting a difficulty

                TmrPopUp.Start();
                LblPopUp.Visible = true; // Display the popup text
                LblPopUp.Text    = "Please enter a username. Remember no numbers allowed!";
            }

            else
            {                      // The username is not empty
                UsernameValid = 0; // Set the usernamevalid to 0, which enables the user to select a difficulty
            }

            for (int i = 0; i < UsernameValue.Length; i++)
            {
                if (!char.IsLetter(UsernameValue[i]))
                {                       // If the current character is not a letter
                    TbUsername.Clear(); // Remove all characters in the username textbox
                    TbUsername.Focus(); // Focuse the user onto the username textbox to set the user to editing the username
                    UsernameValid = 1;  // Set the usernamevalid to 1, which disables the user from selecting a difficulty

                    TmrPopUp.Start();
                    LblPopUp.Visible = true; // Display the popup text
                    LblPopUp.Text    = "Remember no numbers allowed!";
                }

                else
                {
                    UsernameValid = 0; // Set the usernamevalid to 0, which enables the user to select a difficulty
                }
            }
        }
        private void BottleTimer_Tick(object sender, EventArgs e)
        {
            if (ButtonClicked == 1)
            {                                     // Only run the code if a difficulty button has been pressed
                bottleRectangle.X += bottleSpeed; // Set the speed of the bottle on timer tick

                // If the bottle rectangle touches the surfer
                if (bottleRectangle.IntersectsWith(surferRectangle))
                {
                    Random RandYValue = new Random();                  // Generate a random y value
                    int    yValueInt  = 0;                             // Generate a intager
                    yValueInt         = RandYValue.Next(20, 500);      // Make the y value between 20 and 500 in the panel
                    bottleRectangle.X = -30;                           // Move the bottle back to the start of the panel, but of the screen so the user cannot see it
                    bottleRectangle.Y = yValueInt;                     // Set the y value of the botttle to the yValueInt varible

                    BottleTimer.Enabled = false;                       // Disable the bottle timer for another 15 seconds

                    Random BottlePrize       = new Random();           // Genrate a random number
                    int    BottlePrizeNumber = BottlePrize.Next(1, 5); // Make the random number between 1 and 4

                    if (BottlePrizeNumber == 1)
                    {                                   // If the random number generated is equal to 1
                        lives++;                        // Add one to lives count
                        LvsTxt.Text = lives.ToString(); // Convert it to a string then dispaly it on the LvsTxt textbox

                        TmrPopUp.Start();
                        LblPopUp.Visible = true; // Display the popup text
                        LblPopUp.Text    = "You gained a life. You now have " + lives + " lives remaining";
                    }

                    if (BottlePrizeNumber == 2)
                    {
                        lives++;                        // Add one to lives count
                        LvsTxt.Text = lives.ToString(); // Convert it to a string then dispaly it on the LvsTxt textbox

                        TmrPopUp.Start();
                        LblPopUp.Visible = true; // Display the popup text
                        LblPopUp.Text    = "You gained a life. You now have " + lives + " lives remaining";
                    }

                    if (BottlePrizeNumber == 3)
                    {
                        lives++;                        // Add one to lives count
                        LvsTxt.Text = lives.ToString(); // Convert it to a string then dispaly it on the LvsTxt textbox

                        TmrPopUp.Start();
                        LblPopUp.Visible = true; // Display the popup text
                        LblPopUp.Text    = "You gained a life. You now have " + lives + " lives remaining";
                    }

                    if (BottlePrizeNumber == 4)
                    {
                        lives--;                        // Remove one from the lives count
                        LvsTxt.Text = lives.ToString(); // Convert it to a string then dispaly it on the LvsTxt textbox

                        TmrPopUp.Start();
                        LblPopUp.Visible = true; // Display the popup text
                        LblPopUp.Text    = "You lost a life. You now have " + lives + " lives remaining";
                    }
                }

                if (bottleRectangle.X > PnlGame.Width)
                {                                                 // If the bottle reaches the end of the panel
                    Random RandYValue = new Random();             // Generate a random y value
                    int    yValueInt  = 0;                        // Generate a intager
                    yValueInt         = RandYValue.Next(20, 500); // Make the y value between 20 and 500 in the panel
                    bottleRectangle.X = -30;                      // Move the bottle back to the start of the panel, but of the screen so the user cannot see it
                    bottleRectangle.Y = yValueInt;                // Set the y value of the botttle to the yValueInt varible

                    BottleTimer.Enabled = false;                  // Disable the bottle timer for another 15 seconds
                }
            }
        }
        private void TmrShark_Tick(object sender, EventArgs e)
        {
            if (ButtonClicked == 1)
            {     // Only run the code if a difficulty button has been pressed
                for (int i = 0; i <= 4; i++)
                { // Run the code for each of the 5 sharks
                    if (level == 1)
                    {
                        sharkSpeed[i] = speed.Next(4, 15); // If the level is 1, then each shark has a random speed between 4 and 15
                    }

                    if (level == 2)
                    {
                        sharkSpeed[i] = speed.Next(10, 20); // If the level is 2, then each shark has a random speed between 10 and 20
                    }

                    if (level == 3)
                    {
                        sharkSpeed[i] = speed.Next(15, 20); // If the level is 3, then each shark has a random speed between 15 and 20
                    }

                    if (level == 4)
                    {
                        sharkSpeed[i] = speed.Next(20, 22); // If the level is 4, then each shark has a random speed between 20 and 22
                    }

                    if (level == 5)
                    {
                        sharkSpeed[i] = speed.Next(20, 22); // If the level is 5, then each shark has a random speed between 20 and 22
                    }

                    if (level == 6)
                    {
                        sharkSpeed[i] = speed.Next(21, 24); // If the level is 6, then each shark has a random speed between 21 and 24
                    }

                    if (level == 7)
                    {
                        sharkSpeed[i] = speed.Next(21, 24); // If the level is 7, then each shark has a random speed between 21 and 24
                    }

                    if (level == 8)
                    {
                        sharkSpeed[i] = speed.Next(21, 24); // If the level is 8, then each shark has a random speed between 21 and 24
                    }

                    if (level == 9)
                    {
                        sharkSpeed[i] = speed.Next(25, 30); // If the level is 9, then each shark has a random speed between 25 and 30
                    }

                    if (level > 9)
                    {
                        sharkSpeed[i] = speed.Next(25, 30); // If the level is greater than 9, then each shark has a random speed between 25 and 30
                    }

                    sharksRectangle[i].X += sharkSpeed[i]; // Set each shark to the correct speed

                    if (sharksRectangle[i].IntersectsWith(surferRectangle))
                    {                                   // If the surfer collides with any shark
                        sharksRectangle[i].X = 20;      // Move the shark back to the begining of the panel
                        lives      -= 1;                // Reduce lives count by one
                        LvsTxt.Text = lives.ToString(); // Display the number of lives remaining on the LvsTxt textbox
                        CheckLives();                   // Initiate the function that checks how many lives the user has

                        TmrPopUp.Start();
                        LblPopUp.Visible = true; // Display the popup text
                        LblPopUp.Text    = "You lost a life. You now have " + lives + " lives remaining";
                    }

                    if (sharksRectangle[i].X > PnlGame.Width)
                    {                                            // If the shark reaches the end of the panel
                        score += 1;                              // Add one point to score count
                        sharksRectangle[i].X = 25;               // Move the shark back to the begining of the panel
                        ScoreTxt.Text        = score.ToString(); // Display the score count on the ScoreTxt textbox

                        // Increase the value/ step the level progressbar by one
                        LevelProgress.Value += 1;
                        LevelProgress.Step  += 1;

                        CheckScore(); // Initiate the function that checks the score the user is on and if the level needs increasing
                    }

                    PnlGame.Invalidate();
                }
            }
        }