Package net.bytten.metazelda

Examples of net.bytten.metazelda.Room


    public void drawEdges(Graphics2D g, double scale, double roomSize,
            IDungeon dungeon, Room room) {
        g.setColor(Color.BLACK);
       
        for (Edge edge: room.getEdges()) {
            Room nextRoom = dungeon.get(edge.getTargetRoomId());
            Coords coords = room.getCenter(),
                   nextCoords = nextRoom.getCenter();
           
            if (nextRoom.getParent() == room) {
                drawParentEdge(g, scale, roomSize, room, nextRoom);
            }
               
            double x1 = coords.x*scale + roomSize*scale,
                   y1 = coords.y*scale + roomSize*scale,
                   x2 = nextCoords.x*scale + roomSize*scale,
                   y2 = nextCoords.y*scale + roomSize*scale;
            double sdy = Math.signum(y2-y1), sdx = Math.signum(x2-x1);
            y1 += sdy * scale*roomSize/2;
            y2 -= sdy * scale*roomSize/2;
            x1 += sdx * scale*roomSize/2;
            x2 -= sdx * scale*roomSize/2;

            if (nextRoom != null && Symbol.equals(edge.getSymbol(),
                    nextRoom.getEdge(room.id).getSymbol())) {
                // Bidirectional edge
                // avoid drawing twice:
                if (coords.compareTo(nextCoords) > 0) continue;
               
                g.drawLine((int)x1, (int)y1, (int)x2, (int)y2);
View Full Code Here


   
    protected double getRoomSize(Dimension dim, IDungeon dungeon) {
        double min = Double.MAX_VALUE;
        for (Room room: dungeon.getRooms()) {
            for (Edge edge: room.getEdges()) {
                Room neighbor = dungeon.get(edge.getTargetRoomId());
                double dist = neighbor.getCenter().distance(room.getCenter());
                if (dist < min) min = dist;
            }
        }
        return min/2;
    }
View Full Code Here

    protected Room chooseRoomWithFreeEdge(Collection<Room> roomCollection,
            int keyLevel) {
        List<Room> rooms = new ArrayList<Room>(roomCollection);
        Collections.shuffle(rooms, random);
        for (int i = 0; i < rooms.size(); ++i) {
            Room room = rooms.get(i);
            for (Pair<Double,Integer> next:
                    constraints.getAdjacentRooms(room.id, keyLevel)) {
                if (dungeon.get(next.second) == null) {
                    return room;
                }
View Full Code Here

        List<Integer> possibleEntries = new ArrayList<Integer>(
                constraints.initialRooms());
        assert possibleEntries.size() > 0;
        id = possibleEntries.get(random.nextInt(possibleEntries.size()));
       
        Room entry = new Room(id, constraints.getCoords(id), null,
                new Symbol(Symbol.START), new Condition());
        dungeon.add(entry);
       
        levels.addRoom(0, entry);
    }
View Full Code Here

                cond = cond.and(latestKey);
                doLock = true;
            }
           
            // Find an existing room with a free edge:
            Room parentRoom = null;
            if (!doLock && random.nextInt(10) > 0)
                parentRoom = chooseRoomWithFreeEdge(levels.getRooms(keyLevel),
                        keyLevel);
            if (parentRoom == null) {
                parentRoom = chooseRoomWithFreeEdge(dungeon.getRooms(),
                        keyLevel);
                doLock = true;
            }
           
            if (parentRoom == null)
                throw new OutOfRoomsException();
           
            // Decide which direction to put the new room in relative to the
            // parent
            int nextId = chooseFreeEdge(parentRoom, keyLevel);
            Set<Coords> coords = constraints.getCoords(nextId);
            Room room = new Room(nextId, coords, parentRoom, null, cond);
           
            // Add the room to the dungeon
            assert dungeon.get(room.id) == null;
            synchronized (dungeon) {
                dungeon.add(room);
View Full Code Here

               bossSym = new Symbol(Symbol.BOSS);
       
        for (Room room: dungeon.getRooms()) {
            if (room.getChildren().size() > 0 || room.getItem() != null)
                continue;
            Room parent = room.getParent();
            if (parent == null || parent.getChildren().size() != 1 ||
                    room.getItem() != null ||
                    !parent.getPrecond().implies(room.getPrecond()))
                continue;
            if (isGenerateGoal()) {
                if (!constraints.roomCanFitItem(room.id, goalSym) ||
                        !constraints.roomCanFitItem(parent.id, bossSym))
                    continue;
            } else {
                if (!constraints.roomCanFitItem(room.id, bossSym))
                    continue;
            }
            possibleGoalRooms.add(room);
        }
       
        if (possibleGoalRooms.size() == 0) throw new RetryException();
       
        Room goalRoom = possibleGoalRooms.get(random.nextInt(
                possibleGoalRooms.size())),
             bossRoom = goalRoom.getParent();
       
        if (!isGenerateGoal()) {
            bossRoom = goalRoom;
            goalRoom = null;
        }
       
        if (goalRoom != null) goalRoom.setItem(goalSym);
        bossRoom.setItem(bossSym);
       
        if (isBossRoomLocked()) {
            int oldKeyLevel = bossRoom.getPrecond().getKeyLevel(),
                newKeyLevel = Math.min(levels.keyCount(), constraints.getMaxKeys());
           
            List<Room> oklRooms = levels.getRooms(oldKeyLevel);
            if (goalRoom != null) oklRooms.remove(goalRoom);
            oklRooms.remove(bossRoom);
           
            if (goalRoom != null) levels.addRoom(newKeyLevel, goalRoom);
            levels.addRoom(newKeyLevel, bossRoom);
           
            Symbol bossKey = new Symbol(newKeyLevel-1);
            Condition precond = bossRoom.getPrecond().and(bossKey);
            bossRoom.setPrecond(precond);
            if (goalRoom != null) goalRoom.setPrecond(precond);
           
            if (newKeyLevel == 0) {
                dungeon.link(bossRoom.getParent(), bossRoom);
            } else {
                dungeon.link(bossRoom.getParent(), bossRoom, bossKey);
View Full Code Here

                    ? Condition.SwitchState.ON
                    : Condition.SwitchState.OFF);
       
        for (Edge edge: room.getEdges()) {
            int neighborId = edge.getTargetRoomId();
            Room nextRoom = dungeon.get(neighborId);
            if (room.getChildren().contains(nextRoom)) {
                if (room.getEdge(neighborId).getSymbol() == null &&
                        random.nextInt(4) != 0) {
                    dungeon.link(room, nextRoom, state.toSymbol());
                    addPrecond(nextRoom, new Condition(state.toSymbol()));
View Full Code Here

     * @return  a list of linked {@link Room}s starting with the goal room and
     *          ending with the start room.
     */
    protected List<Room> getSolutionPath() {
        List<Room> solution = new ArrayList<Room>();
        Room room = dungeon.findGoal();
        while (room != null) {
            solution.add(room);
            room = room.getParent();
        }
        return solution;
    }
View Full Code Here

            Collections.shuffle(rooms, random);
            Collections.shuffle(solution, random);
           
            // Pick a base room from the solution path so that the player
            // will have to encounter a switch-lock to solve the dungeon.
            Room baseRoom = null;
            for (Room room: solution) {
                if (room.getChildren().size() > 1 && room.getParent() != null) {
                    baseRoom = room;
                    break;
                }
            }
            if (baseRoom == null) throw new RetryException();
            Condition baseRoomCond = baseRoom.getPrecond();
           
            removeDescendantsFromList(rooms, baseRoom);
           
            Symbol switchSym = new Symbol(Symbol.SWITCH);
           
            Room switchRoom = null;
            for (Room room: rooms) {
                if (room.getItem() == null &&
                        baseRoomCond.implies(room.getPrecond()) &&
                        constraints.roomCanFitItem(room.id, switchSym)) {
                    switchRoom = room;
                    break;
                }
            }
            if (switchRoom == null) continue;
           
            if (switchLockChildRooms(baseRoom, Condition.SwitchState.EITHER)) {
                switchRoom.setItem(switchSym);
                return;
            }
        }
        throw new RetryException();
    }
View Full Code Here

                    // preconds ensure linkage doesn't trivialize the puzzle.
                    constraints.getAdjacentRooms(room.id, Integer.MAX_VALUE)) {
                int nextId = next.second;
                if (room.getEdge(nextId) != null) continue;
               
                Room nextRoom = dungeon.get(nextId);
                if (nextRoom == null || nextRoom.isGoal() || nextRoom.isBoss())
                    continue;
               
                boolean forwardImplies = room.getPrecond().implies(nextRoom.getPrecond()),
                        backwardImplies = nextRoom.getPrecond().implies(room.getPrecond());
                if (forwardImplies && backwardImplies) {
                    // both rooms are at the same keyLevel.
                    if (random.nextDouble() >=
                            constraints.edgeGraphifyProbability(room.id, nextRoom.id))
                        continue;
                   
                    dungeon.link(room, nextRoom);
                } else {
                    Symbol difference = room.getPrecond().singleSymbolDifference(
                            nextRoom.getPrecond());
                    if (difference == null || (!difference.isSwitchState() &&
                            random.nextDouble() >=
                                constraints.edgeGraphifyProbability(room.id, nextRoom.id)))
                        continue;
                    dungeon.link(room, nextRoom, difference);
View Full Code Here

TOP

Related Classes of net.bytten.metazelda.Room

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.