private void SetupBikeRaceTrack() { Bikes.StartingPosition1 = Bike1.Right - BikeRacetrack.Left; Bikes.BikeRacetrackLength1 = BikeRacetrack.Size.Width - 70; //fixing length of BikeRace - till finish line Bikess[0] = new Bikes() { BikesPictureBox = Bike1 }; Bikess[1] = new Bikes() { BikesPictureBox = Bike2 }; Bikess[2] = new Bikes() { BikesPictureBox = Bike3 }; Bikess[3] = new Bikes() { BikesPictureBox = Bike4 }; BikeRacers[0] = pFactory.getBikeRacer("Kim", MaximumBet, KimBet); //getting Kim object from factory class BikeRacers[1] = pFactory.getBikeRacer("Barry", MaximumBet, BarryBet); //getting Barry object from factory class BikeRacers[2] = pFactory.getBikeRacer("Tom", MaximumBet, TomBet); //getting Tom object from factory class foreach (BikeRacer BikeRacer in BikeRacers) { BikeRacer.UpdateLabels(); } }
private void BikeRace_Click(object sender, EventArgs e) { bool NoWinner = true; int winningBikes; BikeRace.Enabled = false; //disable start BikeRace button while (NoWinner) // loop until we have a winner { Application.DoEvents(); for (int i = 0; i < Bikess.Length; i++) { if (Bikes.Run(Bikess[i])) { winningBikes = i + 1; NoWinner = false; MessageBox.Show("winner of the BikeRace is - Bikes #" + winningBikes); foreach (BikeRacer BikeRacer in BikeRacers) { if (BikeRacer.bet != null) { BikeRacer.Collect(winningBikes); //give double amount to all who've won or deduce betted amount BikeRacer.bet = null; BikeRacer.UpdateLabels(); } } foreach (Bikes Bikes in Bikess) { Bikes.TakeStartingPosition(); } break; } } } if (BikeRacers[0].busted && BikeRacers[1].busted && BikeRacers[2].busted) //stop BikeRacers 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) { SetupBikeRaceTrack(); //restart game } else { this.Close(); } } BikeRace.Enabled = true; //enable BikeRace button }
public Bet(int Amount, int bikeNum, BikeRacer Bettor) { this.Amount = Amount; this.bikeNum = bikeNum; this.Bettor = Bettor; }