Example #1
0
        private void race_Click(object sender, EventArgs e)
        {
            bool NoWinner = true;
            int  winningLion;

            race.Enabled = false; //disable start race button

            while (NoWinner)
            { // loop until we have a winner
                Application.DoEvents();
                for (int i = 0; i < Lions.Length; i++)
                {
                    if (Lion.Run(Lions[i]))
                    {
                        winningLion = i + 1;
                        NoWinner    = false;
                        MessageBox.Show("We have a winner - Lion #" + winningLion);
                        foreach (Punter punter in punters)
                        {
                            if (punter.bet != null)
                            {
                                punter.Collect(winningLion); //give double amount to all who've won or deduce betted amount
                                punter.bet = null;
                                punter.UpdateLabels();
                            }
                        }
                        foreach (Lion Lion in Lions)
                        {
                            Lion.TakeStartingPosition();
                        }
                        break;
                    }
                }
            }
            if (punters[0].busted && punters[1].busted && punters[2].busted)
            {  //stop punters from betting if they run out of cash
                String            message = "Do you want to Play Again?";
                String            title   = "GAME OVER!";
                MessageBoxButtons buttons = MessageBoxButtons.YesNo;
                DialogResult      result  = MessageBox.Show(message, title, buttons);
                if (result == DialogResult.Yes)
                {
                    SetupRaceTrack(); //restart game
                }
                else
                {
                    this.Close();
                }
            }
            race.Enabled = true; //enable race button
        }