//creates the pilot ranking for a pilot student public static Pilot.PilotRating GetPilotStudentRanking(PilotStudent student) { Pilot.PilotRating instructorRanking = student.Instructor.Rating; int aircraftCoeff = student.Instructor.FlightSchool.TrainingAircrafts.Exists(a => a.Type.MaxNumberOfStudents > 5) ? 10 : 0; int instructorRankingIndex = Array.IndexOf(Enum.GetValues(typeof(Pilot.PilotRating)), instructorRanking); Dictionary <Pilot.PilotRating, int> rankings = new Dictionary <Pilot.PilotRating, int>(); rankings.Add(instructorRanking, 50); if (instructorRankingIndex > 0) { Pilot.PilotRating prevRating = (Pilot.PilotRating)Enum.GetValues(typeof(Pilot.PilotRating)).GetValue(instructorRankingIndex - 1); rankings.Add(prevRating, 35 - aircraftCoeff); } if (instructorRankingIndex < Enum.GetValues(typeof(Pilot.PilotRating)).Length - 1) { Pilot.PilotRating nextRating = (Pilot.PilotRating)Enum.GetValues(typeof(Pilot.PilotRating)).GetValue(instructorRankingIndex + 1); rankings.Add(nextRating, 15 + aircraftCoeff); } Pilot.PilotRating rating = AIHelpers.GetRandomItem <Pilot.PilotRating>(rankings); return(rating); }
private void btnChangeInstructor_Click(object sender, RoutedEventArgs e) { PilotStudent student = (PilotStudent)((Hyperlink)sender).Tag; ComboBox cbInstructor = new ComboBox(); cbInstructor.SetResourceReference(ComboBox.StyleProperty, "ComboBoxTransparentStyle"); cbInstructor.Width = 200; cbInstructor.HorizontalAlignment = System.Windows.HorizontalAlignment.Left; cbInstructor.DisplayMemberPath = "Profile.Name"; cbInstructor.SelectedValuePath = "Profile.Name"; foreach (Instructor instructor in this.FlightSchool.Instructors.Where(i => i.Students.Count < Model.PilotModel.FlightSchool.MaxNumberOfStudentsPerInstructor && i != student.Instructor)) { cbInstructor.Items.Add(instructor); } cbInstructor.SelectedIndex = 0; if (PopUpSingleElement.ShowPopUp(Translator.GetInstance().GetString("PanelFlightSchool", "1005"), cbInstructor) == PopUpSingleElement.ButtonSelected.OK && cbInstructor.SelectedItem != null) { student.Instructor.removeStudent(student); student.Instructor = (Instructor)cbInstructor.SelectedItem; ICollectionView view = CollectionViewSource.GetDefaultView(lvStudents.ItemsSource); view.Refresh(); } }
private void btnDeleteStudent_Click(object sender, RoutedEventArgs e) { PilotStudent student = (PilotStudent)((Button)sender).Tag; WPFMessageBoxResult result = WPFMessageBox.Show(Translator.GetInstance().GetString("MessageBox", "2807"), string.Format(Translator.GetInstance().GetString("MessageBox", "2807", "message"), student.Profile.Name), WPFMessageBoxButtons.YesNo); if (result == WPFMessageBoxResult.Yes) { this.FlightSchool.removeStudent(student); student.Instructor.removeStudent(student); student.Instructor = null; setHireStudentsStatus(); } }
private void btnHire_Click(object sender, RoutedEventArgs e) { Random rnd = new Random(); ComboBox cbInstructor = new ComboBox(); cbInstructor.SetResourceReference(ComboBox.StyleProperty, "ComboBoxTransparentStyle"); cbInstructor.Width = 200; cbInstructor.HorizontalAlignment = System.Windows.HorizontalAlignment.Left; cbInstructor.DisplayMemberPath = "Profile.Name"; cbInstructor.SelectedValuePath = "Profile.Name"; foreach (Instructor instructor in this.FlightSchool.Instructors.Where(i => i.Students.Count < FlightSchool.MaxNumberOfStudentsPerInstructor)) { cbInstructor.Items.Add(instructor); } cbInstructor.SelectedIndex = 0; if (PopUpSingleElement.ShowPopUp(Translator.GetInstance().GetString("PanelFlightSchool", "1005"), cbInstructor) == PopUpSingleElement.ButtonSelected.OK && cbInstructor.SelectedItem != null) { List <Town> towns = Towns.GetTowns(this.FlightSchool.Airport.Profile.Country); Town town = towns[rnd.Next(towns.Count)]; DateTime birthdate = MathHelpers.GetRandomDate(GameObject.GetInstance().GameTime.AddYears(-55), GameObject.GetInstance().GameTime.AddYears(-23)); PilotProfile profile = new PilotProfile(Names.GetInstance().getRandomFirstName(), Names.GetInstance().getRandomLastName(), birthdate, town); PilotStudent student = new PilotStudent(profile, GameObject.GetInstance().GameTime, (Instructor)cbInstructor.SelectedItem); this.FlightSchool.addStudent(student); ((Instructor)cbInstructor.SelectedItem).addStudent(student); showStudents(); this.ParentPage.updatePage(); txtStudents.Text = this.FlightSchool.NumberOfStudents.ToString(); double studentPrice = GeneralHelpers.GetInflationPrice(PilotStudent.StudentCost); int studentsCapacity = Math.Min(this.FlightSchool.Instructors.Count * FlightSchool.MaxNumberOfStudentsPerInstructor, this.FlightSchool.TrainingAircrafts.Sum(f => f.Type.MaxNumberOfStudents)); btnHire.IsEnabled = studentsCapacity > this.FlightSchool.Students.Count && GameObject.GetInstance().HumanAirline.Money > studentPrice; AirlineHelpers.AddAirlineInvoice(GameObject.GetInstance().HumanAirline, GameObject.GetInstance().GameTime, Invoice.InvoiceType.Airline_Expenses, -studentPrice); } }
//returns the aircraft for a student private TrainingAircraft getStudentAircraft(PilotStudent student) { Dictionary <TrainingAircraftType, int> types = this.FlightSchool.Aircrafts.GroupBy(a => a.Type). Select(group => new { Type = group.Key, Count = group.Sum(g => g.Type.MaxNumberOfStudents) }).ToDictionary(g => g.Type, g => g.Count);; foreach (PilotStudent ps in this.FlightSchool.Students) { types[ps.Aircraft.Type]--; } var freeTypes = types.Where(t => t.Value > 0).Select(t => t.Key).OrderBy(t => t.TypeLevel); return(this.FlightSchool.Aircrafts.First(a => a.Type == freeTypes.First())); }
//creates the pilot rating for a pilot student public static PilotRating GetPilotStudentRating(PilotStudent student) { return(GetPilotStudentRating(student.Instructor)); }
//removes a student from the object public void removeStudent(PilotStudent student) { this.Students.Remove(student); this.FlightSchool.removeStudent(student); }
//adds a student to the object public void addStudent(PilotStudent student) { this.Students.Add(student); this.FlightSchool.addStudent(student); }
private void btnHire_Click(object sender, RoutedEventArgs e) { var aircraftsTypesFree = this.FlightSchool.Aircrafts.Select(a => a.Type); Dictionary <TrainingAircraftType, int> types = this.FlightSchool.Aircrafts.GroupBy(a => a.Type). Select(group => new { Type = group.Key, Count = group.Sum(g => g.Type.MaxNumberOfStudents) }).ToDictionary(g => g.Type, g => g.Count);; foreach (PilotStudent student in this.FlightSchool.Students) { var firstAircraft = student.Rating.Aircrafts.OrderBy(a => a.TypeLevel).FirstOrDefault(a => types.ContainsKey(a) && types[a] > 0); if (firstAircraft != null && types.ContainsKey(firstAircraft)) { types[firstAircraft]--; } } List <PilotRating> possibleRatings = new List <PilotRating>(); foreach (PilotRating rating in PilotRatings.GetRatings()) { if (rating.Aircrafts.Exists(a => types.ContainsKey(a) && types[a] > 0)) { possibleRatings.Add(rating); } } WPFMessageBoxResult result = WPFMessageBox.Show(Translator.GetInstance().GetString("MessageBox", "2811"), string.Format(Translator.GetInstance().GetString("MessageBox", "2811", "message")), WPFMessageBoxButtons.YesNo); if (result == WPFMessageBoxResult.Yes) { List <Town> towns = Towns.GetTowns(this.FlightSchool.FlightSchool.Airport.Profile.Country); Town town = towns[rnd.Next(towns.Count)]; DateTime birthdate = MathHelpers.GetRandomDate(GameObject.GetInstance().GameTime.AddYears(-35), GameObject.GetInstance().GameTime.AddYears(-23)); PilotProfile profile = new PilotProfile(Names.GetInstance().getRandomFirstName(town.Country), Names.GetInstance().getRandomLastName(town.Country), birthdate, town); Instructor instructor = (Instructor)cbInstructor.SelectedItem; string airlinerFamily = cbTrainAircraft.SelectedItem.ToString(); PilotStudent student = new PilotStudent(profile, GameObject.GetInstance().GameTime, instructor, GeneralHelpers.GetPilotStudentRating(instructor, possibleRatings), airlinerFamily); TrainingAircraft aircraft = getStudentAircraft(student); student.Aircraft = aircraft; this.FlightSchool.addStudent(student); instructor.addStudent(student); setHireStudentsStatus(); double studentPrice = GeneralHelpers.GetInflationPrice(PilotStudent.StudentCost); AirlineHelpers.AddAirlineInvoice(GameObject.GetInstance().HumanAirline, GameObject.GetInstance().GameTime, Invoice.InvoiceType.Airline_Expenses, -studentPrice); } }
//removes a student from the object public void removeStudent(PilotStudent student) { this.Students.Remove(student); this.FlightSchool.removeStudent(student); this.NumberOfStudents = this.Students.Count; }
//adds a student to the object public void addStudent(PilotStudent student) { this.Students.Add(student); this.FlightSchool.addStudent(student); this.NumberOfStudents = this.Students.Count; }