/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package dungeon; import java.util.LinkedList; import java.util.List; import main.Counter; import main.Dice; /** * * @author MrMcX */ public class Room { public int number; public Exit[] exits; public Dungeon.Type isNatural; public boolean isRoom, hasMonster, hasTrap, hasMagic, hasSpecial, hasTreasure = false; public Enemy monster; public Treasure treasure; public Trap trap; public String type, magicPhenomenon, specialPhenomenon = null; public Room(Exit predecessor, int numberOfExits, boolean room, String type, Counter c){ exits = new Exit[numberOfExits]; exits[0] = predecessor; this.isRoom = room; this.type = type; number = 0; } public List generate(Counter c, Dungeon.Type isNatural){ number = c.Next(); List list = new LinkedList(); for(int i = 0; i < exits.length; i++){ if(exits[i] == null){ Exit predecessor = new Exit(this); Room newRoom = RandomRoom(false, predecessor, c, isNatural); exits[i] = new Exit(newRoom, predecessor.type); list.add(newRoom); } } SetContents(isNatural); return list; } private void SetContents(Dungeon.Type isNatural){ if(isRoom){ switch(Dice.Roll(6, 2)){ case 2: case 3: return; case 4: hasMonster = true; monster = new Enemy(isNatural); return; case 5: hasTrap = true; trap = new Trap(); case 6: hasTreasure = true; treasure = new Treasure(); return; case 7: hasMagic = true; // TODO: generate magic here return; case 8: hasSpecial = true; // TODO: generate special here return; case 9: hasMonster = true; hasTrap = true; monster = new Enemy(isNatural); trap = new Trap(); return; case 10: hasMonster = true; hasTreasure = true; monster = new Enemy(isNatural); treasure = new Treasure(); return; case 11: hasMonster = true; hasMagic = true; monster = new Enemy(isNatural); // TODO: generate magic here return; case 12: hasTrap = true; hasTreasure = true; trap = new Trap(); treasure = new Treasure(); return; } } else { switch(Dice.Roll(6, 1)){ case 1: case 2: case 3: return; case 4: hasMonster = true; monster = new Enemy(isNatural); return; case 5: hasTrap = true; trap = new Trap(); return; case 6: hasTreasure = true; treasure = new Treasure(); return; } } this.isNatural = isNatural; } @Override public String toString(){ if(!isRoom){ return "Gang " + number; } else if(isNatural == Dungeon.Type.NATURAL){ return "Höhle " + number; } else { return "Raum " + number; } } public String toLongString(){ String out = ""; if(isRoom){ out += "Raum "; } else { out += "Gang "; } out += "Nummer " + number + ": " + type + "\n" + "Ausgänge:\n"; for(Exit x : exits){ out += x.toLongString(); } if(hasMonster){ out += "Gegner:\n- " + monster.toString() + "\n"; } if(hasTrap){ out += "Fallen:\n- " + trap + "\n"; } if(hasMagic){ out += "Magische Phänomene:\n- " + magicPhenomenon + "\n"; } if(hasSpecial){ out += "Besondere Phänomene:\n- " + specialPhenomenon + "\n"; } if(hasTreasure){ out += "Fundsache:\n- " + treasure + "\n"; } return out; } public String toShortString(){ if(isRoom){ return "Raum Nummer " + number; } else { return "Gang Nummer " + number; } } public static Room RoomBigExits(Exit predecessor, Counter c, Dungeon.Type isNatural){ int rand = Dice.Roll(3, 1); if(isNatural == Dungeon.Type.NATURAL){ return new Room(predecessor, rand + 1, true, "große Höhle mit " + rand + " Ausgängen", c); } else { return new Room(predecessor, rand + 1, true, "großer Raum mit " + rand + " Ausgängen", c); } } public static Room RoomSmallExits(Exit predecessor, Counter c, Dungeon.Type isNatural){ int rand = Dice.Roll(3, 1); if(isNatural == Dungeon.Type.NATURAL){ return new Room(predecessor, rand + 1, true, "kleine Höhle mit " + rand + " Ausgängen", c); } else { return new Room(predecessor, rand + 1, true, "kleiner Raum mit " + rand + " Ausgängen", c); } } public static Room RoomBigNoExits(Exit predecessor, Counter c, Dungeon.Type isNatural){ if(isNatural == Dungeon.Type.NATURAL){ return new Room(predecessor, 1, true, "große Höhle ohne Ausgang", c); } else { return new Room(predecessor, 1, true, "großer Raum ohne Ausgang", c); } } public static Room RoomBigExitsStair(Exit predecessor, Counter c, Dungeon.Type isNatural){ int rand = Dice.Roll(2, 1); if(isNatural == Dungeon.Type.NATURAL){ return new Room(predecessor, rand + 2, true, "große Höhle mit " + rand + " Ausgängen und einer Treppe", c); } else { return new Room(predecessor, rand + 2, true, "großer Raum mit " + rand + " Ausgängen und einer Treppe", c); } } public static Room RoomSmallNoExits(Exit predecessor, Counter c, Dungeon.Type isNatural){ if(isNatural == Dungeon.Type.NATURAL){ return new Room(predecessor, 1, true, "kleine Höhle ohne Ausgang", c); } else { return new Room(predecessor, 1, true, "kleiner Raum ohne Ausgang", c); } } public static Room RoomSmallExitsStair(Exit predecessor, Counter c, Dungeon.Type isNatural){ int rand = Dice.Roll(2, 1); if(isNatural == Dungeon.Type.NATURAL){ return new Room(predecessor, rand + 2, true, "kleine Höhle mit " + rand + " Ausgängen und einer Treppe", c); } else { return new Room(predecessor, rand + 2, true, "kleiner Raum mit " + rand + " Ausgängen und einer Treppe", c); } } public static Room RoomGiant(Exit predecessor, Counter c, Dungeon.Type isNatural){ int rand = Dice.Roll(2, 1); if(isNatural == Dungeon.Type.NATURAL){ return new Room(predecessor, rand + 1, true, "gigantische Höhle mit " + rand + " Ausgängen", c); } else { return new Room(predecessor, rand + 1, true, "gigantischer Raum mit " + rand + " Ausgängen", c); } } public static Room CorridorStraight(Exit predecessor, Counter c){ return new Room(predecessor, 2, false, "gerader Gang", c); } public static Room CorridorRight(Exit predecessor, Counter c){ return new Room(predecessor, 2, false, "rechts abbiegender Gang", c); } public static Room CorridorLeft(Exit predecessor, Counter c){ return new Room(predecessor, 2, false, "links abbiegender Gang", c); } public static Room CrossingT(Exit predecessor, Counter c){ return new Room(predecessor, 3, false, "T-Kreuzung mit Abzweigungen nach links und rechts", c); } public static Room Crossing(Exit predecessor, Counter c){ return new Room(predecessor, 4, false, "Kreuzung, die in alle Richtungen weitergeht", c); } public static Room DeadEnd(Exit predecessor, Counter c){ return new Room(predecessor, 1, false, "Sackgasse", c); } public static Room RandomRoom(boolean first, Exit predecessor, Counter c, Dungeon.Type isNatural){ int number; if(first){ number = Dice.Roll(6, 1); } else { number = Dice.Roll(20, 1); } switch(number){ case 1: case 2: case 3: return RoomBigExits(predecessor, c, isNatural); case 4: case 5: case 6: return RoomSmallExits(predecessor, c, isNatural); case 7: return RoomBigNoExits(predecessor, c, isNatural); case 8: case 9: return RoomBigExitsStair(predecessor, c, isNatural); case 10: return RoomSmallNoExits(predecessor, c, isNatural); case 11: case 12: return RoomSmallExitsStair(predecessor, c, isNatural); case 13: case 14: return RoomGiant(predecessor, c, isNatural); case 15: return CorridorStraight(predecessor, c); case 16: return CorridorRight(predecessor, c); case 17: return CorridorLeft(predecessor, c); case 18: return CrossingT(predecessor, c); case 19: return Crossing(predecessor, c); case 20: return DeadEnd(predecessor, c); } return null; } }