Esempio n. 1
0
        public void CreateMapConnection(Map startMap, Point startPosition, string startTileStem, Map endMap, Point endPosition, string endTileStem)
        {
            #region NullChecking
            if (startMap == null)
            {
                throw new ArgumentNullException(nameof(startMap));
            }
            if (string.IsNullOrEmpty(startTileStem))
            {
                throw new ArgumentNullException(nameof(startTileStem));
            }
            if (endMap == null)
            {
                throw new ArgumentNullException(nameof(endMap));
            }
            if (string.IsNullOrEmpty(endTileStem))
            {
                throw new ArgumentNullException(nameof(endTileStem));
            }
            #endregion NullChecking
            var startTile = Tile.GetRandomTile(startTileStem);
            var endTile = Tile.GetRandomTile(endTileStem);

            var tile1 = startMap.AddSubTile(startTile, startPosition);
            tile1.Position = startPosition;
            tile1.SteppedOn += OnTileStepOn;

            var tile2 = endMap.AddSubTile(endTile, endPosition, true);
            tile2.Position = endPosition;
            tile2.SteppedOn += OnTileStepOn;

            var mapConnectionStart = new MapConnection
            {
                End = endPosition,
                EndMap = endMap,
                Start = startPosition,
            };
            startMap.AddConnection(mapConnectionStart);
            var mapConnectionEnd = new MapConnection
            {
                End = startPosition,
                EndMap = startMap,
                Start = endPosition
            };
            endMap.AddConnection(mapConnectionEnd);
        }
Esempio n. 2
0
        /// <summary>
        /// creates random connection tiles at <see cref="mapBorder"/> in startMap, and on the opposite border of endMap 
        /// </summary>
        /// <param name="border"></param>
        /// <param name="thickness"></param>
        /// <param name="coverage"></param>
        /// <param name="startMap"></param>
        /// <param name="startPosition"></param>
        /// <param name="startTileStem"></param>
        /// <param name="endMap"></param>
        /// <param name="endTileStem"></param>
        /// TODO(philipp): no thickness needed for bordermapconnection tile thingies?
        public void CreateBorderMapConnection(MapBorder border, int coverage, Map startMap, string startTileStem, Map endMap, string endTileStem)
        {
            #region NullChecking
            if (startMap == null)
            {
                throw new ArgumentNullException(nameof(startMap));
            }
            if (string.IsNullOrEmpty(startTileStem))
            {
                throw new ArgumentNullException(nameof(startTileStem));
            }
            if (endMap == null)
            {
                throw new ArgumentNullException(nameof(endMap));
            }
            if (string.IsNullOrEmpty(endTileStem))
            {
                throw new ArgumentNullException(nameof(endTileStem));
            }
            #endregion NullChecking

            int startX = 0;
            int startY = 0;
            int endX = 0;
            int endY = 0;

            MapBorder oppositeMapBorder = MapBorder.None;

            switch (border)
            {
                case MapBorder.West:
                    startX = 0;
                    startY = 0;
                    endX = 1;
                    endY = startMap.Height;
                    oppositeMapBorder = MapBorder.East;
                    break;
                case MapBorder.North:
                    startX = 0;
                    startY = 0;
                    endX = startMap.Width;
                    endY = 1;
                    oppositeMapBorder = MapBorder.South;
                    break;
                case MapBorder.East:
                    startX = startMap.Width - 1;
                    startY = 0;
                    endX = startMap.Width;
                    endY = startMap.Height;
                    oppositeMapBorder = MapBorder.West;
                    break;
                case MapBorder.South:
                    startX = 0;
                    startY = startMap.Height - 1;
                    endX = startMap.Width;
                    endY = startMap.Height;
                    oppositeMapBorder = MapBorder.North;
                    break;
            }
            var rememberedTilePositions = new List<Point>();
            for (var y = startY; y < endY; ++y)
            {
                for (var x = startX; x < endX; ++x)
                {
                    if (_random.Next(0, 100) <= coverage)
                    {
                        var tileIndex = startMap.PointToIndex(x, y);
                        var tile = startMap.Tiles.ElementAt(tileIndex);
                        if (!tile.IsSolid)
                        {
                            //TODO(philipp): CLEAN UP THIS MESS!
                            var subTile = Tile.GetRandomTile(startTileStem);
                            subTile.Position = startMap.IndexToPoint(tileIndex);
                            rememberedTilePositions.Add(subTile.Position);
                            var connectionStartTile = startMap.AddSubTile(subTile, subTile.Position);
                            connectionStartTile.Position = subTile.Position;
                            connectionStartTile.SteppedOn += OnTileStepOn;
                        }
                    }
                }
            }
            var endTile = Tile.GetRandomTile(endTileStem);
            foreach (var rememberedTilePosition in rememberedTilePositions)
            {
                Point endPosition = Point.Zero;
                var startPosition = rememberedTilePosition;
                switch (oppositeMapBorder)
                {
                    case MapBorder.North:
                        endPosition = new Point(startPosition.X, 0);
                        break;
                    case MapBorder.West:
                        endPosition = new Point(0, startPosition.Y);
                        break;
                    case MapBorder.East:
                        endPosition = new Point(endMap.Width - 1, startPosition.Y);
                        break;
                    case MapBorder.South:
                        endPosition = new Point(startPosition.X, endMap.Height - 1);
                        break;
                }
                var connectionEndTile = endMap.AddSubTile(endTile, endPosition, true);
                connectionEndTile.Position = startPosition;
                connectionEndTile.SteppedOn += OnTileStepOn;

                var mapConnectionStart = new MapConnection
                {
                    End = endPosition,
                    EndMap = endMap,
                    Start = rememberedTilePosition,
                };
                startMap.AddConnection(mapConnectionStart);
                var mapConnectionEnd = new MapConnection
                {
                    End = rememberedTilePosition,
                    EndMap = startMap,
                    Start = endPosition
                };
                endMap.AddConnection(mapConnectionEnd);
            }
        }