// 使用工厂来初始化room和外墙
        public void InitialRooms(MazeFactory factory)
        {
            for (int x = 0; x < _gameSizeH; x++)
            {
                for (int y = 0; y < _gameSizeW; y++)
                {
                    Room newRoom = factory.MakeRoom(new Location(x, y));

                    if (x == 0)
                    {
                        new Wall(newRoom, Direction.North);
                    }
                    else
                    {
                        Room northRoom = GetRoom(x - 1, y);
                        northRoom.SetSite(Direction.South, newRoom);
                        newRoom.SetSite(Direction.North, northRoom);
                        if (x == _gameSizeH - 1)
                        {
                            new Wall(newRoom, Direction.South);
                        }
                    }

                    if (y == 0)
                    {
                        new Wall(newRoom, Direction.West);
                    }
                    else
                    {
                        Room westRoom = GetRoom(x, y - 1);
                        westRoom.SetSite(Direction.East, newRoom);
                        newRoom.SetSite(Direction.West, westRoom);
                        if (y == _gameSizeW - 1)
                        {
                            new Wall(newRoom, Direction.East);
                        }
                    }

                    _rooms[x * _gameSizeW + y] = newRoom;
                }
            }
        }
        public MapMidWare(Room room1, Room room2)
        {
            _room1 = room1;
            _room2 = room2;
            if (_room1 == null || _room2 == null)
            {
                return;
            }
            Location l1 = room1.GetLocation();
            Location l2 = room2.GetLocation();

            if (l1 - l2 != 1)
            {
                return;
            }
            Direction direction1, direction2;

            if (l1.X - l2.X > 0)
            {
                direction1 = Direction.North;
                direction2 = Direction.South;
            }
            else if (l1.X - l2.X < 0)
            {
                direction1 = Direction.South;
                direction2 = Direction.North;
            }
            else if (l1.Y - l2.Y > 0)
            {
                direction1 = Direction.West;
                direction2 = Direction.East;
            }
            else
            {
                direction1 = Direction.East;
                direction2 = Direction.West;
            }
            room1.SetSite(direction1, this);
            room2.SetSite(direction2, this);
        }
Exemple #3
0
        /// <summary>
        /// join r1 with r2
        /// </summary>
        public static void Join(Room room1, Room room2)
        {
            if (room1 == null || room2 == null)
            {
                return;
            }
            Location l1 = room1.GetLocation();
            Location l2 = room2.GetLocation();

            if (l1 - l2 != 1)
            {
                return;
            }
            Direction direction1, direction2;

            if (l1.X - l2.X > 0)
            {
                direction1 = Direction.North;
                direction2 = Direction.South;
            }
            else if (l1.X - l2.X < 0)
            {
                direction1 = Direction.South;
                direction2 = Direction.North;
            }
            else if (l1.Y - l2.Y > 0)
            {
                direction1 = Direction.West;
                direction2 = Direction.East;
            }
            else
            {
                direction1 = Direction.East;
                direction2 = Direction.West;
            }
            room1.SetSite(direction1, room2);
            room2.SetSite(direction2, room1);
        }
Exemple #4
0
 // 单侧墙(外墙)
 public Wall(Room room, Direction direction) : base(room, null)
 {
     room.SetSite(direction, this);
 }