private void Form2_Load(object sender, EventArgs e) { this.WindowState = FormWindowState.Maximized; List <Stable> stables = createStables(); List <Horse> horses = new List <Horse>(); foreach (Stable st in stables) { foreach (Horse h in findForsestHorsesFromStable(st, 3)) { horses.Add(h); } } foreach (Horse h in horses) { hippodrome.addMember(h); } horserInRace = hippodrome.runRace(); setHorsersNamesToForm(horserInRace); foreach (HorseInCompetition horse in horserInRace) { if (horse.getState() is Winner) { winner = horse; break; } } float currentSize = label8.Font.Size + 20.0F; label8.Font = new Font(label8.Font.Name, currentSize, label8.Font.Style, label8.Font.Unit); foreach (HorseInCompetition horse in horserInRace) { racingResultForEachHorse.Add(horse.boardsPassed * 10000 / 7); if (horse.raceResultTime >= maxTimeHorseInRace && horse.boardsPassed == 7) { maxTimeHorseInRace = horse.raceResultTime; } if (horse.timeTraining >= maxTimeHorseInTraining) { maxTimeHorseInTraining = horse.timeTraining; } if (horse.boardsPassed != 7) { horse.raceResultTime = horse.timeTraining; } } timer1.Enabled = true; timer1.Start(); timer1.Interval = 500; timer1.Tick += new EventHandler(start_Tick); }
public List <HorseInCompetition> runRace() { foreach (HorseInCompetition horse in horsers) { // перепрыгнула или нет? for (int j = 0; j < 6; j++) { if (!jumpOverBarricade()) { if (!jumpedAndNotSick()) { horse.setState(new Sick()); horse.boardsPassed = j + 1; break; } else { horse.raceResultTime += PENALTY_TIME; } } } } // Нахождение победителя HorseInCompetition fastestHorse = null; bool flag = false; foreach (HorseInCompetition horse in horsers) { if (horse.getState() is Sick) { continue; } if (!flag) { fastestHorse = horse; flag = true; } if (horse.raceResultTime < fastestHorse.raceResultTime) { fastestHorse = horse; } } if (fastestHorse != null) { fastestHorse.setState(new Winner()); } // Лечение лошадей Veterinarian veterinarian = Veterinarian.getVeterinarian(); foreach (HorseInCompetition horse in horsers) { if (horse.getState() is Sick) { veterinarian.treatment(horse); } } return(horsers); }