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);
        }
Esempio n. 2
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);
        }
Esempio n. 3
0
        // 玩家移动
        public bool Move(Direction direction)
        {
            Room     currentRoom = _maze.GetRoom(_man.GetLocation());
            IMapSite dstSite     = currentRoom.GetSite(direction);

            if (dstSite != null && dstSite.EnterAble)
            {
                Room dstRoom     = dstSite.Enter(currentRoom);
                var  dstLocation = dstRoom.GetLocation();
                if (dstLocation - _man.GetLocation() == 1)
                {
                    // neighbor
                    _man.Move(direction);
                }
                else
                {
                    _man.SetLocation(dstLocation);
                }
                return(true);
            }

            return(false);
        }