コード例 #1
0
 public Range Intersection(Range range)
 {
     return new Range(Math.Max(Begin, range.Begin), Math.Min(End, range.End));
 }
コード例 #2
0
        private Link? PlaceRoomSourceFixed(FixedRoom src, Room target, int connPt, int sep)
        {
            var conn = src.ConnectionPoints[connPt];
            int x, y;
            Link? link = null;

            switch (conn.Item1)
            {
                case Direction.North:
                case Direction.South:
                    // North & South
                    int minX = src.Pos.X + conn.Item2 + template.CorridorWidth - target.Width;
                    int maxX = src.Pos.X + conn.Item2;
                    x = rand.Next(minX, maxX + 1);

                    if (conn.Item1 == Direction.South)
                        y = src.Pos.Y + src.Height + sep;
                    else
                        y = src.Pos.Y - sep - target.Height;

                    target.Pos = new Point(x, y);
                    if (collision.HitTest(target))
                        return null;

                    link = new Link(conn.Item1, src.Pos.X + conn.Item2);
                    break;

                case Direction.East:
                case Direction.West:
                    // East & West
                    int minY = src.Pos.Y + conn.Item2 + template.CorridorWidth - target.Height;
                    int maxY = src.Pos.Y + conn.Item2;
                    y = rand.Next(minY, maxY + 1);

                    if (conn.Item1 == Direction.East)
                        x = src.Pos.X + src.Width + sep;
                    else
                        x = src.Pos.X - sep - target.Width;

                    target.Pos = new Point(x, y);
                    if (collision.HitTest(target))
                        return null;

                    var linkY = new Range(src.Pos.Y, src.Pos.Y + src.Height).Intersection(
                        new Range(target.Pos.Y, target.Pos.Y + target.Height));
                    link = new Link(conn.Item1, src.Pos.Y + conn.Item2);
                    break;
            }

            collision.Add(target);
            return link;
        }
コード例 #3
0
        private void GenerateBranches()
        {
            int numRooms = new Range(minRoomNum, maxRoomNum).Random(rand);

            List<Room> copy;
            while (rooms.Count < numRooms)
            {
                copy = new List<Room>(rooms);
                rand.Shuffle(copy);

                bool worked = false;
                foreach (var room in copy)
                {
                    if (rooms.Count > numRooms)
                        break;
                    if (rand.Next() % 2 == 0)
                        continue;
                    worked |= GenerateBranchInternal(room, room.Depth + 1, template.MaxDepth, true);
                }
                if (!worked)
                    break;
            }
        }
コード例 #4
0
        private Link? PlaceRoomFree(Room src, Room target, Direction connPt, int sep)
        {
            int x, y;
            Link? link = null;

            switch (connPt)
            {
                case Direction.North:
                case Direction.South:
                    // North & South
                    int minX = src.Pos.X + template.CorridorWidth - target.Width;
                    int maxX = src.Pos.X + src.Width - template.CorridorWidth;
                    x = rand.Next(minX, maxX + 1);

                    if (connPt == Direction.South)
                        y = src.Pos.Y + src.Height + sep;
                    else
                        y = src.Pos.Y - sep - target.Height;

                    target.Pos = new Point(x, y);
                    if (collision.HitTest(target))
                        return null;

                    var linkX = new Range(src.Pos.X, src.Pos.X + src.Width).Intersection(
                        new Range(target.Pos.X, target.Pos.X + target.Width));
                    link = new Link(connPt, new Range(linkX.Begin, linkX.End - template.CorridorWidth).Random(rand));
                    break;

                case Direction.East:
                case Direction.West:
                    // East & West
                    int minY = src.Pos.Y + template.CorridorWidth - target.Height;
                    int maxY = src.Pos.Y + src.Height - template.CorridorWidth;
                    y = rand.Next(minY, maxY + 1);

                    if (connPt == Direction.East)
                        x = src.Pos.X + src.Width + sep;
                    else
                        x = src.Pos.X - sep - target.Width;

                    target.Pos = new Point(x, y);
                    if (collision.HitTest(target))
                        return null;

                    var linkY = new Range(src.Pos.Y, src.Pos.Y + src.Height).Intersection(
                        new Range(target.Pos.Y, target.Pos.Y + target.Height));
                    link = new Link(connPt, new Range(linkY.Begin, linkY.End - template.CorridorWidth).Random(rand));
                    break;
            }

            collision.Add(target);
            return link;
        }