Beispiel #1
0
        private void btnSellAircraft_Click(object sender, RoutedEventArgs e)
        {
            TrainingAircraft aircraft = (TrainingAircraft)((Button)sender).Tag;

            var aircrafts = new List <TrainingAircraft>(this.FlightSchool.Aircrafts);

            aircrafts.Remove(aircraft);


            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).First(a => types.ContainsKey(a) && types[a] > 0);

                if (types.ContainsKey(firstAircraft))
                {
                    types[firstAircraft]--;
                }
            }

            Boolean canSellAircraft = aircrafts.Sum(a => a.Type.MaxNumberOfStudents) >= this.FlightSchool.Students.Count && types[aircraft.Type] > 1;

            if (canSellAircraft)
            {
                WPFMessageBoxResult result = WPFMessageBox.Show(Translator.GetInstance().GetString("MessageBox", "2809"), Translator.GetInstance().GetString("MessageBox", "2809", "message"), WPFMessageBoxButtons.YesNo);

                if (result == WPFMessageBoxResult.Yes)
                {
                    this.FlightSchool.removeTrainingAircraft(aircraft);

                    double price = aircraft.Type.Price * 0.75;
                    AirlineHelpers.AddAirlineInvoice(GameObject.GetInstance().HumanAirline, GameObject.GetInstance().GameTime, Invoice.InvoiceType.Airline_Expenses, price);
                }
            }
            else
            {
                WPFMessageBox.Show(Translator.GetInstance().GetString("MessageBox", "2810"), Translator.GetInstance().GetString("MessageBox", "2810", "message"), WPFMessageBoxButtons.Ok);
            }
        }
Beispiel #2
0
        private void btnSellAircraft_Click(object sender, RoutedEventArgs e)
        {
            TrainingAircraft aircraft = (TrainingAircraft)((Button)sender).Tag;

            var aircrafts = new List <TrainingAircraft>(this.FlightSchool.Aircrafts);

            aircrafts.Remove(aircraft);

            Boolean canSellAircraft = aircrafts.Sum(a => a.Type.MaxNumberOfStudents) >= this.FlightSchool.Students.Count;

            if (canSellAircraft)
            {
                WPFMessageBoxResult result = WPFMessageBox.Show(Translator.GetInstance().GetString("MessageBox", "2809"), Translator.GetInstance().GetString("MessageBox", "2809", "message"), WPFMessageBoxButtons.YesNo);

                if (result == WPFMessageBoxResult.Yes)
                {
                    this.FlightSchool.removeTrainingAircraft(aircraft);
                }
            }
            else
            {
                WPFMessageBox.Show(Translator.GetInstance().GetString("MessageBox", "2810"), Translator.GetInstance().GetString("MessageBox", "2810", "message"), WPFMessageBoxButtons.Ok);
            }
        }
Beispiel #3
0
 //remove an aircraft from the object
 public void removeTrainingAircraft(TrainingAircraft aircraft)
 {
     this.Aircrafts.Remove(aircraft);
     this.FlightSchool.removeTrainingAircraft(aircraft);
 }
Beispiel #4
0
 //adds an aircraft to the object
 public void addTrainingAircraft(TrainingAircraft aircraft)
 {
     this.Aircrafts.Add(aircraft);
     this.FlightSchool.addTrainingAircraft(aircraft);
 }
Beispiel #5
0
        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);
            }
        }