Example #1
0
        public void Draw()
        {
            Triangle.Draw(_engine.Surface.Canvas);
            Planets.ForEach(p => p.Draw(_engine.Surface.Canvas));

            _engine.Surface.Canvas.DrawLine(0, Planets.Last().Transform.Y - 150, _engine.Surface.Width, Planets.Last().Transform.Y - 150, PaintFinishedLine);
        }
Example #2
0
        public void DoInitialCalculations()
        {
            PlanetsById = Planets.ToImmutableSortedDictionary(p => p.Id, p => p);

            // TODO dit is dubbelop .. allebei order by distanceturns
            Planets.ForEach(p => p.NeighboringPlanets = Planets.Where(n => p.Neighbors.Contains(n.Id)).OrderBy(n => n.DistanceTo(p)).ToList());
            Planets.ForEach(p => p.NeighbouringPlanetsDistanceTurns = CalculateNeighbouringPlanetsDistanceTurns(p));

            Planets.ForEach(p => p.ShortestPaths = CalculateShortestPaths(p));
        }
Example #3
0
        public void Update()
        {
            Triangle.Step();

            Planets.ForEach(planet =>
            {
                Triangle.Intersect(planet);
                planet.Step();
            });

            CheckEndGame();
        }
Example #4
0
        public void TurnInit()
        {
            Planets.ForEach(p => p.Friendlyness = DetermineFriendlyness(p.Owner));

            for (var i = 0; i < Ships.Count; i++)
            {
                Ships[i].Friendlyness = DetermineFriendlyness(Ships[i].Owner);
                Ships[i].Target       = Planets.FirstOrDefault(p => p.Id == Ships[i].TargetId);
//                Ships.ForEach(s => s.Friendlyness = DetermineFriendlyness(s.Owner));
//                Ships.ForEach(s => s.Target = Planets.Single(p => p.Id == s.TargetId));
            }

            var shipsByTarget = Ships.GroupBy(s => s.TargetId).ToDictionary(s => s.Key, s => s.AsEnumerable());

            Planets.ForEach(p => p.SetInboundShips(shipsByTarget.GetValueOrDefault(p.Id, new Ship[0])));
        }
Example #5
0
        private Weather GetWeather(int day, ref double maxPerimeter, ref int maxRainDay, int nFractionalDigits)
        {
            List <CoordinatesHelper> coordinates = new List <CoordinatesHelper>();

            //Get coordinates list
            Planets.ForEach(planet => coordinates.Add(planet.CurrentCoordinates(day, nFractionalDigits)));

            if (IsDrought(coordinates, nFractionalDigits))
            {
                return new Weather {
                           DayNumber = day, WeatherType = WeatherEnum.sequia
                }
            }
            ;
            if (IsOptimum(coordinates, nFractionalDigits))
            {
                return new Weather {
                           DayNumber = day, WeatherType = WeatherEnum.optimo
                }
            }
            ;
            if (IsRain(coordinates))
            {
                double perimeter = Math.Perimeter(coordinates[0], coordinates[1], coordinates[2]);

                if (perimeter > maxPerimeter)
                {
                    maxPerimeter = perimeter;
                    maxRainDay   = day;
                }

                return(new Weather {
                    DayNumber = day, WeatherType = WeatherEnum.lluvia
                });
            }

            return(new Weather {
                DayNumber = day, WeatherType = WeatherEnum.normal
            });
        }