Ejemplo n.º 1
0
    /// <summary>
    ///
    /// </summary>
    /// <param name="currentRoom"></param>
    /// <param name="exitRoom"></param>
    /// <param name="routeLength"></param>
    /// <param name="visited"></param>
    /// <returns></returns>
    private int CalculateShortestRoute(BaseRoom currentRoom, BaseRoom exitRoom, int routeLength, HashSet <BaseRoom> visited)
    {
        var nextRooms = new Dictionary <BaseRoom, bool>();

        foreach (var direction in RoomConnection.Directions)
        {
            if (!currentRoom.HasConnection(direction))
            {
                continue;
            }

            var door = currentRoom.GetConnector(direction) as DoorConnector;
            if (door == null)
            {
                continue;
            }

            var nextRoom = GetAdjacentRoom(currentRoom, direction);
            if (nextRoom == null)
            {
                continue;
            }

            if (visited.Contains(nextRoom))
            {
                continue;
            }

            if (nextRoom == exitRoom)
            {
                return(routeLength + (door.IsLocked ? 1 : 0));
            }

            nextRooms.Add(nextRoom, door.IsLocked);
        }

        visited.Add(currentRoom);
        foreach (var roomEntry in nextRooms)
        {
            var room       = roomEntry.Key;
            var doorLocked = roomEntry.Value;

            var length = CalculateShortestRoute(room, exitRoom, routeLength + (doorLocked ? 1 : 0), visited);
            if (length < int.MaxValue)
            {
                return(length);
            }
        }

        return(int.MaxValue);
    }
Ejemplo n.º 2
0
    /// <summary>
    ///
    /// </summary>
    /// <param name="room"></param>
    /// <param name="direction"></param>
    public void OpenDoor(BaseRoom room, RoomConnection.DirectionType direction)
    {
        var door = room.GetConnector(direction) as DoorConnector;

        if (door == null)
        {
            return;
        }
        door.OpenDoor(true, m_playerController);

        var adjecentRoom = GetAdjacentRoom(room, direction);
        var adjacnetDoor = adjecentRoom?.GetConnector(direction.GetOpposite()) as DoorConnector;

        adjacnetDoor?.OpenDoor(true, m_playerController);
    }
Ejemplo n.º 3
0
    /// <summary>
    ///
    /// </summary>
    /// <param name="room"></param>
    /// <param name="direction"></param>
    public void UnlockDoor(BaseRoom room, RoomConnection.DirectionType direction)
    {
        var door = room.GetConnector(direction) as DoorConnector;

        if (door == null)
        {
            return;
        }
        door.UnlockDoor(true);

        var adjecentRoom = GetAdjacentRoom(room, direction);
        var adjacnetDoor = adjecentRoom?.GetConnector(direction.GetOpposite()) as DoorConnector;

        adjacnetDoor?.UnlockDoor(true);
    }