private void raceClock_Tick(object sender, EventArgs e) { foreach (GreyHound greyhound in greyhouds) { if (greyhound.Run()) { raceClock.Stop(); MessageBox.Show("Wygrał " + GreyHound.WinnerDog()); if (raceClock.Enabled == false) { // Zakończ wyścig - podsumuj foreach (Player player in players) { player.Collect(GreyHound.WinnerDog()); } // Przygotuj nową grę PrepareNewGame(); ButtonsOnOff(); UpdateAllLabels(players); } return; } } }
// Przygotuj nową grę private void PrepareNewGame() { GreyHound.ResetWinnerDog(); int a = GreyHound.WinnerDog(); foreach (GreyHound greyhound in greyhouds) { greyhound.TakeStartingPosition(); } }
// inicjalizacja gry public void InitializeRaceGame() { // Inicjalizuj psy wyścigowe PictureBox[] pictureBoxes = new PictureBox[4]; pictureBoxes[0] = pictureBox_hound0; pictureBoxes[1] = pictureBox_hound1; pictureBoxes[2] = pictureBox_hound2; pictureBoxes[3] = pictureBox_hound3; for (int i = 0; i < greyhouds.Length; i++) { greyhouds[i] = new GreyHound(pictureBoxes[i], i); } Random random = new Random(); int totalRaceTrackLength = pictureBox_raceTrack.Width + pictureBox_raceTrack.Location.X - pictureBox_hound0.Location.X - pictureBox_hound0.Width; foreach (GreyHound greyhound in greyhouds) { greyhound.SetRandom(random); greyhound.SetStartingPosition(); greyhound.SetRacetrackLength(totalRaceTrackLength); } // Inicjalizuj graczy players[0] = new Player("Janek", radioB_janek, label_janek, 0); players[1] = new Player("Bartek", radioB_bartek, label_bartek, 1); players[2] = new Player("Arek", radioB_arek, label_arek, 2); UpdateAllLabels(players); }