Beispiel #1
0
        private void ApplyArrivals()
        {
            Dictionary <int, List <Fleet> > arrivalLocations = new Dictionary <int, List <Fleet> >();
            List <Fleet> toRemove = new List <Fleet>();

            foreach (Fleet f in Fleets)
            {
                if (f.RemainingTurns == 0)
                {
                    if (!arrivalLocations.ContainsKey(f.Destination))
                    {
                        arrivalLocations.Add(f.Destination, new List <Fleet>());
                    }

                    arrivalLocations[f.Destination].Add(f);
                    toRemove.Add(f);
                }
            }

            toRemove.ForEach(x => Fleets.Remove(x));

            foreach (var arrival in arrivalLocations)
            {
                Planet planet = Planets.First(x => x.Identifier == arrival.Key);
                if (planet == null)
                {
                    throw new Exception("Wha?  There's a fleet en route to a non-existant planet?");
                }

                ApplySpecificArrival(planet, arrival.Value);
            }
        }
Beispiel #2
0
        private void ApplyDepartures(List <Order> orders)
        {
            foreach (Order o in orders)
            {
                Planet sourcePlanet = Planets.First(x => x.Identifier == o.Source);
                if (sourcePlanet == null)
                {
                    throw new Exception("No source planet.  Order validation went wrong.");
                }

                Planet destinationPlanet = Planets.First(x => x.Identifier == o.Destination);
                if (destinationPlanet == null)
                {
                    throw new Exception("No destination planet.  Order validation went wrong.");
                }

                if (sourcePlanet.Ships < o.Ships)
                {
                    SetErrorMessage(o.Player, $"Tried to send too many ships from planet {o.Source}");
                }

                int totalTurns =
                    (int)Math.Ceiling(
                        Math.Sqrt(Math.Pow(destinationPlanet.X - sourcePlanet.X, 2) +
                                  Math.Pow(destinationPlanet.Y - sourcePlanet.Y, 2)));
                Fleets.Add(new Fleet(o.Player, o.Ships, o.Source, o.Destination, totalTurns, totalTurns));
                sourcePlanet.Ships -= o.Ships;
            }
        }