示例#1
0
 public void AddAdjacent(City adj)
 {
     Adjacent.Add(adj);
     if (Adjacent.Count > 6)
     {
         int a = 0;
     }
 }
示例#2
0
        public GameWorld(int Width, int Height, Point start, int seed = 0)
        {
            ////TODO: Make better world generation
            rng    = new Random(0);
            width  = Width;
            height = Height;

            map = new MapObject[width, height];
            int ID = 0;

            //Fill map with air
            for (int x = 0; x <= map.GetUpperBound(0); x++)
            {
                for (int y = 0; y <= map.GetUpperBound(1); y++)
                {
                    map[x, y] = new Space(ID++, new Point(x, y));
                }
            }

            if (Width % Room.RoomBaseSize != 0 || Height % Room.RoomBaseSize != 0)
            {
                throw new Exception("The large map can not be mapped onto the smaller!");
            }
            roomMap = new Room[Width / Room.RoomBaseSize, Height / Room.RoomBaseSize];

            //Define all possible rooms
            Point       _Position    = new Point(0, 0);
            List <Room> possibilites = new List <Room>
            {
                new IntersectionRoom(_Position),
                new TIntersectionBottom(_Position),
                new TIntersectionTop(_Position),
                new TIntersectionLeft(_Position),
                new TIntersectionRight(_Position),
                new SingleEntranceRoomTop(_Position),
                new SingleEntranceRoomRight(_Position),
                new SingleEntranceRoomLeft(_Position),
                new SingleEntranceRoomBottom(_Position),
                new FilledRoom(_Position)
            };

            //Add start room
            roomMap[0, 0] = new StartRoom(new Point(0, 0));
            roomMap[0, 0].Generate(ref map, ref ID);

            for (int x = 0; x <= roomMap.GetUpperBound(0); x++)
            {
                for (int y = 0; y <= roomMap.GetUpperBound(1); y++)
                {
                    if (roomMap[x, y] != null)
                    {
                        continue;
                    }

                    //Find possible rooms
                    //Find needed exits
                    List <int> top;
                    List <int> bottom;
                    List <int> left;
                    List <int> right;

                    if (y == 0)
                    {
                        top = new List <int>();
                    }
                    else
                    {
                        top = roomMap[x, y - 1].exits.bottom;
                    }

                    if (y == roomMap.GetUpperBound(1))
                    {
                        bottom = new List <int>();
                    }
                    else if (roomMap[x, y + 1] != null)
                    {
                        bottom = roomMap[x, y + 1].exits.top;
                    }
                    else
                    {
                        bottom = null;
                    }

                    if (x == 0)
                    {
                        left = new List <int>();
                    }
                    else
                    {
                        left = roomMap[x - 1, y].exits.right;
                    }

                    if (x == roomMap.GetUpperBound(0))
                    {
                        right = new List <int>();
                    }
                    else if (roomMap[x + 1, y] != null)
                    {
                        right = roomMap[x + 1, y].exits.left;
                    }
                    else
                    {
                        right = null;
                    }

                    Adjacent <List <int> > neededExits = new Adjacent <List <int> >(top, left, right, bottom);

                    //Find possible rooms
                    Room room = possibilites.First(p =>
                    {
                        bool _top    = p.exits.top.SequenceEqual(neededExits.top);
                        bool _left   = p.exits.left.SequenceEqual(neededExits.left);
                        bool _right  = null == neededExits.right || p.exits.right.SequenceEqual(neededExits.right);
                        bool _bottom = null == neededExits.bottom || p.exits.bottom.SequenceEqual(neededExits.bottom);
                        return(_top && _left && _right && _bottom);
                    });

                    //Add room
                    roomMap[x, y] = room.NewRoom(new Point(x * Room.RoomBaseSize, y * Room.RoomBaseSize));
                    roomMap[x, y].Generate(ref map, ref ID);
                }
            }
        }