public static IslandEntity Random(GeoPoint center)
        {
            var random = new Random();

            var corners = new List<GeoPoint>();
            int currentAngle = 0;
            while (currentAngle < 360)
            {
                var actual = random.Next(30) + 30;
                var length = random.Next(10) + 5;

                currentAngle += actual;
                var x = (int) (Math.Cos(currentAngle * Math.PI / 360 * 2 ) * length);
                var y = (int) (Math.Sin(currentAngle * Math.PI / 360 * 2) * length);
                var point = new GeoPoint(x + center.X, y + center.Y);
                corners.Add(point);
            }

            return new IslandEntity { Corners = corners.ToArray() };
        }
Пример #2
0
 public void AddIsland(IslandEntity island)
 {
     foreach (var item in island.GeneratePoints())
     {
         var point = new GeoPoint(item.X, item.Y);
         points.Add(point, LocationType.Ground);
     }
 }
Пример #3
0
 public void AddCity(CityEntity entity)
 {
     var point = new GeoPoint(entity.X, entity.Y);
     points[point] = LocationType.City;
 }
Пример #4
0
 public PointContext(GeoPoint geopoint, TextureHolder texture)
 {
     GeoPoint = geopoint;
     Texture = texture;
 }
Пример #5
0
        /// <summary>
        /// Generates list of textures for given square, when left bottom corner is provided.
        /// </summary>
        /// <param name="lbx"></param>
        /// <param name="lby"></param>
        /// <param name="dx"></param>
        /// <param name="dy"></param>
        /// <returns>Sequence contains textures, starting from left bottom corner and returning rows first.</returns>
        public IEnumerable<PointContext> GetWindow(int lbx, int lby, int dx, int dy)
        {
            for (int y = 0; y < dy; y++)
                for (int x = 0; x < dx; x++)
                {
                    var geox = lbx + x;
                    var geoy = lby + y;

                    var area = new LocationType[9];
                    var centerOfArea = new GeoPoint(geox, geoy);

                    for (int i = 0; i < 9; i++) area[i] = LocationType.Water;

                    area[NeighborTopLeft] = points.ContainsKey(centerOfArea.TopLeft()) ? points[centerOfArea.TopLeft()] : LocationType.Water;
                    area[NeighborNorth] = points.ContainsKey(centerOfArea.Top()) ? points[centerOfArea.Top()] : LocationType.Water;
                    area[NeighborTopRight] = points.ContainsKey(centerOfArea.TopRight()) ? points[centerOfArea.TopRight()] : LocationType.Water;
                    area[NeighborWest] = points.ContainsKey(centerOfArea.Left()) ? points[centerOfArea.Left()] : LocationType.Water;
                    area[NeighborThis] = points.ContainsKey(centerOfArea) ? points[centerOfArea] : LocationType.Water;
                    area[NeighborEast] = points.ContainsKey(centerOfArea.Right()) ? points[centerOfArea.Right()] : LocationType.Water;
                    area[NeighborDownLeft] = points.ContainsKey(centerOfArea.DownLeft()) ? points[centerOfArea.DownLeft()] : LocationType.Water;
                    area[NeighborSouth] = points.ContainsKey(centerOfArea.Down()) ? points[centerOfArea.Down()] : LocationType.Water;
                    area[NeighborDownRight] = points.ContainsKey(centerOfArea.DownRight()) ? points[centerOfArea.DownRight()] : LocationType.Water;

                    var centerTexture = new TextureHolder();
                    foreach (var strategy in strategies)
                    {
                        var texture = strategy(area, centerTexture);
                        if (texture == centerTexture) continue;

                        centerTexture = texture;
                        break;
                    }

                    yield return new PointContext(centerOfArea, centerTexture);
                }
        }