Ejemplo n.º 1
0
        void timer_Tick(object sender, EventArgs e)
        {
            T.UpdatePosition();
            H.UpdatePosition();

            pictureBox1.Invalidate();

            if (T.DidYaBite(H) == true)
            {
                lboxCommentary.Items.Add("OUCH");
            }

            T.CheckOutofBounds();
            H.CheckOutofBounds();

            if (T.IsWinner() == true && H.IsWinner() == true)
            {
                timer.Stop();
                btnStartRace.Visible = true;
                lboxCommentary.Items.Add("It's a tie.");
                btnStartRace.Hide();
                btnPause.Hide();
            }
            else if (T.IsWinner() == true)
            {
                T.SetWinCount(T.GetWinCount() + 1);
                lblScoreT.Text = T.GetWinCount().ToString();
                timer.Stop();
                btnStartRace.Visible = true;
                lboxCommentary.Items.Add("TORTOISE WINS!!!!! YAY!!!!!");
                btnStartRace.Hide();
                btnPause.Hide();
            }
            else if (H.IsWinner() == true)
            {
                H.SetWinCount(H.GetWinCount() + 1);
                lblScoreH.Text = H.GetWinCount().ToString();
                timer.Stop();
                btnStartRace.Visible = true;
                lboxCommentary.Items.Add("Hare wins. Booooo");
                btnStartRace.Hide();
                btnPause.Hide();
            }
            else
            {
            }
        }
Ejemplo n.º 2
0
        // After each tick of the timer, the following occurs
        private void timer1_Tick(object sender, EventArgs e)
        {
            // Two bools are declared to store the values outputted from the IsWinner method
            bool Bob_Winner, Shelly_Winner;

            // The position of both animals/objects is updated (using the method in the class)
            Bob.UpdatePosition();
            Shelly.UpdatePosition();

            // The picture boxes are refreshed
            pbTortoiseTrack.Invalidate();
            pbHareTrack.Invalidate();

            // The IsWinner methods are run, to check and see if anyone has reached the end of the race
            Bob_Winner    = Bob.IsWinner();
            Shelly_Winner = Shelly.IsWinner();

            // If both animals have reached the end of the race, the following occurs
            if (Bob_Winner == true && Shelly_Winner == true)
            {
                // The timer stops, the declaration of the tie is reported to the user (using the list box)
                timer1.Stop();
                lb_output.Items.Add("It's a tie!");

                // The scores for each animal are updated
                Bob.iScore      = Bob.iScore + 1;
                Shelly.iScore   = Shelly.iScore + 1;
                btnPlay.Enabled = false;
            }
            // If bob the Hare wins, the following occurs
            else if (Bob_Winner == true)
            {
                // The timer stops, the win is outputted to the user, and the score is updated
                timer1.Stop();
                lb_output.Items.Add("The hare wins!");
                Bob.iScore      = Bob.iScore + 1;
                btnPlay.Enabled = false;
            }

            // If the tortiose Shelly wins, the following occurs
            else if (Shelly_Winner == true)
            {
                // The timer stops, the win is outputted to the user, and the score is updated
                timer1.Stop();
                lb_output.Items.Add("The tortoise wins!");
                Shelly.iScore   = Shelly.iScore + 1;
                btnPlay.Enabled = false;
            }

            // If Bob and Shelly are at the same position in the race, the following occurs
            if (Bob.get_position() == Shelly.get_position())
            {
                // The status us outputted to the user, and the sound player is used to play a sound
                lb_output.Items.Add("OUCH!");
                ouchSoundPlayer.Play();
            }

            // If either animals reaches the end of the race, the following occurs
            if (Bob.get_position() == 70 || Shelly.get_position() == 70)
            {
                // The buttons (Reset & Clear) are enabled, while the rest are disabled
                btnPause.Enabled = false;
                btnPlay.Enabled  = false;
                btnReset.Enabled = true;
                btnClear.Enabled = true;
            }

            // The scoreboard is updated
            lblHareScore.Text     = Bob.iScore.ToString();
            lblTortoiseScore.Text = Shelly.iScore.ToString();
        }