private void race_Click(object sender, EventArgs e) { bool NoWinner = true; int winningHorse; race.Enabled = false; //disable start race button while (NoWinner) { // loop until we have a winner Application.DoEvents(); for (int i = 0; i < horses.Length; i++) { if (Horse.Run(horses[i])) { winningHorse = i + 1; NoWinner = false; MessageBox.Show("We have a winner - Horse #" + winningHorse); foreach (Punter punter in punters) { if (punter.bet != null) { punter.Collect(winningHorse); //give double amount to all who've won or deduce betted amount punter.bet = null; punter.UpdateLabels(); } } foreach (Horse horse in horses) { horse.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 { Close(); } } race.Enabled = true; //enable race button }
private void racebtn_Click(object sender, EventArgs e) { bool NoWinner = true; int winningHorse; racebtn.Enabled = false; while (NoWinner) { Application.DoEvents(); for (int i = 0; i < horses.Length; i++) { if (Horse.Run(horses[i])) { winningHorse = i + 1; NoWinner = false; MessageBox.Show("We have a winner - Horse " + winningHorse); foreach (Punter punter in punters) { if (punter.bet != null) { punter.Collect(winningHorse); punter.bet = null; punter.UpdateLabels(); } } foreach (Horse horse in horses) { horse.startPosition(); } 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 = "End Game!"; MessageBoxButtons buttons = MessageBoxButtons.YesNo; DialogResult result = MessageBox.Show(message, title, buttons); if (result == DialogResult.Yes) { SetupTrack(); //restart game } else { this.Close(); } } racebtn.Enabled = true; }