Exemple #1
0
        private void UpdateTime()
        {
            // decrease the number of seconds by 1
            totalSeconds = totalSeconds - 1;
            timeLeft     = totalSeconds;

            // display the time left
            lblTimer.Text = "Time Left: " + timeLeft;

            // remove a life if total seconds is 0
            if (totalSeconds == 0)
            {
                // remove a life
                lives = lives - 1;

                // call lose life sound
                LoseLifeSound();

                if (lives == 2)
                {
                    // display lives
                    picHeart1.Show();
                    picHeart2.Show();
                    picHeart3.Hide();

                    // Call reset time
                    ResetTime();
                }
                else if (lives == 1)
                {
                    // display lives
                    picHeart1.Show();
                    picHeart2.Hide();
                    picHeart3.Hide();

                    // Call reset time
                    ResetTime();
                }
                else
                {
                    // stop time
                    tmrTimer.Stop();
                    tmrCountdown.Stop();

                    // Call Image to Front
                    ImageToFront();

                    // display lives
                    picHeart1.Hide();
                    picHeart2.Hide();
                    picHeart3.Hide();

                    // close this form and open lose form
                    this.Hide();
                    var LoseScreen = new frmLose();
                    LoseScreen.Closed += (s, args) => this.Close();
                    LoseScreen.Show();
                }
            }
        }
Exemple #2
0
        private void TmrTimer_Tick(object sender, EventArgs e)
        {
            // call wall
            Wall();

            // continously drop player towards the platform (the ground)
            picPlayer.Top += jumpSpeed;

            // if jumping and force is less than 0, create a gravity effect
            if (jumping && force < 0)
            {
                // make jumping false
                jumping = false;
            }

            if (goleft)
            {
                // push character towards left of screen
                picPlayer.Left -= 5;
            }

            if (goright)
            {
                // push character towards right of screen
                picPlayer.Left += 5;
            }

            if (jumping)
            {
                // set force to 1, jumpspeed to -12
                jumpSpeed = -12;
                force    -= 1;
            }
            // if it's not jumping set speed to 12
            else
            {
                jumpSpeed = 12;
            }

            // look through whole form to find picture boxes that player interacts with, in order to land on top of it.
            foreach (Control x in this.Controls)
            {
                // continue if x is a picturebox and the tag equals to the platform
                if (x is PictureBox && x.Tag == "platform")
                {
                    if (picPlayer.Bounds.IntersectsWith(x.Bounds) && !jumping)
                    {
                        // set force to 8, and player is going to be above the platform
                        force         = 8;
                        picPlayer.Top = x.Top - picPlayer.Height;
                    }
                }

                // if x is a picture box and tag is coin, continue
                if (x is PictureBox && x.Tag == "coin")
                {
                    if (picPlayer.Bounds.IntersectsWith(x.Bounds) && !jumping)
                    {
                        // assign url
                        wmpChime.URL = "Sounds/chime.wav";

                        // Play the sound
                        wmpChime.Ctlcontrols.play();

                        // increment the score
                        score++;

                        // display the score
                        lblScore.Text = "Score: " + score;

                        // remove the coin
                        this.Controls.Remove(x);
                    }
                }

                // if player touches the sad face, lose a life
                if (x is PictureBox && x.Tag == "sad")
                {
                    if (picPlayer.Bounds.IntersectsWith(x.Bounds) && !jumping)
                    {
                        // remove lives
                        lives = lives - 1;

                        // play lose sound
                        LoseLifeSound();

                        // decrease the score
                        score--;

                        // display the score
                        lblScore.Text = "Score: " + score;

                        // remove the coin
                        this.Controls.Remove(x);

                        if (lives == 3)
                        {
                            picHeart1.Show();
                            picHeart2.Show();
                            picHeart3.Show();
                        }
                        else if (lives == 2)
                        {
                            // display 2 lives
                            picHeart1.Show();
                            picHeart2.Show();
                            picHeart3.Hide();
                        }
                        else if (lives == 1)
                        {
                            // display 1 life
                            picHeart1.Show();
                            picHeart2.Hide();
                            picHeart3.Hide();
                        }
                        else
                        {
                            // display no lives
                            picHeart1.Hide();
                            picHeart2.Hide();
                            picHeart3.Hide();

                            // Stop timer
                            tmrTimer.Stop();
                            tmrCountdown.Stop();

                            // close this form and open lose form
                            this.Hide();
                            var LoseScreen = new frmLose();
                            LoseScreen.Closed += (s, args) => this.Close();
                            LoseScreen.Show();
                        }
                    }
                }

                // if player touches the door, stop timer and display you win
                if (picPlayer.Bounds.IntersectsWith(picDoor.Bounds))
                {
                    // stop timers
                    tmrTimer.Stop();
                    tmrCountdown.Stop();

                    // assign url
                    wmpDoor.URL = "Sounds/clink.mp3";

                    // Play the sound
                    wmpDoor.Ctlcontrols.play();

                    // Call Show Win
                    ShowWinLose();

                    // Call image to front
                    ImageToFront();
                }
            }
        }
Exemple #3
0
        private void UpdateLives()
        {
            // remove a life if total seconds is 0
            if (totalSeconds == 0)
            {
                if (lives == 3)
                {
                    // remove a life
                    lives = lives - 1;

                    // display lives
                    picHeart1.Show();
                    picHeart2.Show();
                    picHeart3.Hide();

                    // call lose life sound
                    LoseLifeSound();

                    // call reset time
                    ResetTime();
                }
                else if (lives == 2)
                {
                    // remove a life
                    lives = lives - 1;

                    // display lives
                    picHeart1.Show();
                    picHeart2.Hide();
                    picHeart3.Hide();

                    // call lose life sound
                    LoseLifeSound();

                    // call reset time
                    ResetTime();
                }
                else
                {
                    // remove a life
                    lives = lives - 1;

                    // call lose life sound
                    LoseLifeSound();

                    // stop time
                    tmrTimer.Stop();
                    tmrCountdown.Stop();

                    // display lives
                    picHeart1.Hide();
                    picHeart2.Hide();
                    picHeart3.Hide();

                    // Call Image to Front
                    ImageToFront();

                    // call reset time
                    ResetTime();

                    // new stuff
                    lives = 3;

                    // close this form and open instructions form
                    this.Hide();
                    var LoseScreen = new frmLose();
                    LoseScreen.Closed += (s, args) => this.Close();
                    LoseScreen.Show();
                }
            }
        }