Esempio n. 1
0
 //Метод для инициализации игры
 public void Initialize(decimal savings, DateTime startDate)
 {
     currentSavings = savings;
     ChangeFuelPrice();
     SavingsChanged?.Invoke(this, savings);
     currentGameDate = startDate;
     DateChanged?.Invoke(this, currentGameDate);
 }
Esempio n. 2
0
        public void BuyPlane(Plane.Models model, double price)
        {
            string planeID = (MaxID + 1).ToString();

            MaxID++;
            Plane plane = new Plane(planeID, model, Plane.Owns.Bought);

            planesAndCities.Add(planeID, CitiesInfo.cities["1"]);
            planes.Add(planeID, plane);
            observablePlanes.Add(plane);
            currentSavings -= (decimal)price;
            SavingsChanged?.Invoke(this, currentSavings);
        }
Esempio n. 3
0
        public void LeasePlane(Plane.Models model, double price, int days)
        {
            string planeID = (MaxID + 1).ToString();

            MaxID++;
            Lease lease = new Lease(planeID, days, price);
            Plane plane = new Plane(planeID, model, Plane.Owns.Leased, lease);

            planesAndCities.Add(planeID, CitiesInfo.cities["1"]);
            planes.Add(planeID, plane);
            observablePlanes.Add(plane);
            currentSavings -= (decimal)price;
            SavingsChanged?.Invoke(this, currentSavings);
        }
Esempio n. 4
0
        //Метод для отмены подписанного контракта
        public void CancelContract(uint flightNum)
        {
            if (!contracts.ContainsKey(flightNum))
            {
                return;
            }
            Contract cancelledContract = contracts[flightNum];

            if (cancelledContract.ConnectedFlights[0].Regularity == 0 ||
                cancelledContract.ConnectedFlights[0].Regularity > 0 &&
                cancelledContract.CountOfPerformedFlights == 0)
            {
                currentSavings -= cancelledContract.Forfeit;
                SavingsChanged?.Invoke(this, currentSavings);
            }
            observableContracts.Remove(contracts[flightNum]);
            contracts.Remove(flightNum);
        }
Esempio n. 5
0
        //Метод для перегонки самолёта из его текущего положения в другой город
        private decimal SendPlane(string planeID, string destinationID, uint?flightNum)
        {
            double  distance = CitiesInfo.GetRoute(planesAndCities[planeID].ID, destinationID).Distance;
            decimal minus    = (decimal)distance * fuelPrice;

            currentSavings -= minus;
            SavingsChanged?.Invoke(this, currentSavings);
            planesAndCities[planeID] = null;
            PlaneFlight ongoingFlight = new PlaneFlight
            {
                AssociatedFlightNum = flightNum,
                AssociatedPlaneID   = planeID,
                DestinationID       = destinationID,
                DistanceLeft        = distance
            };

            planesProgress.Add(ongoingFlight);
            return(minus);
        }
Esempio n. 6
0
        private bool ContractIsPrepared(Contract contract, int flightIdx)
        {
            if (contract.ConnectedFlights[flightIdx].DateFrom.Date != currentGameDate.Date ||
                contract.Time != null &&
                (contract.Time.Hours != currentGameDate.TimeOfDay.Hours ||
                 contract.Time.Minutes != currentGameDate.TimeOfDay.Minutes))
            {
                return(false);
            }

            if (contract.AssignedPlane == null || contract.Time == null || planesAndCities[contract.AssignedPlane.ID] == null)
            {
                currentSavings -= contract.Forfeit;
                SavingsChanged?.Invoke(this, currentSavings);
                return(false);
            }

            return(true);
        }
Esempio n. 7
0
        //Метод для загрузки игры
        public void LoadGame(Stream savedGame)
        {
            BinaryFormatter serializer = new BinaryFormatter();
            Game            loadedGame = (Game)serializer.Deserialize(savedGame);

            Initialize(loadedGame.currentSavings, loadedGame.currentGameDate);

            SavingsChanged?.Invoke(this, currentSavings);

            fuelPrice = loadedGame.fuelPrice;
            FuelPriceChanged?.Invoke(this, fuelPrice);

            planesProgress   = loadedGame.planesProgress;
            observablePlanes = loadedGame.observablePlanes;
            planes           = loadedGame.planes;

            planesAndCities = loadedGame.planesAndCities;

            bulletinBoard       = loadedGame.bulletinBoard;
            contracts           = loadedGame.contracts;
            observableContracts = loadedGame.observableContracts;
        }
Esempio n. 8
0
 public void PayFine(double fine)
 {
     currentSavings -= (decimal)fine;
     SavingsChanged?.Invoke(this, currentSavings);
 }
Esempio n. 9
0
 public void SellPlane(double Price)
 {
     currentSavings += (decimal)Price;
     SavingsChanged?.Invoke(this, currentSavings);
 }