public static void paint(Level level, Room room) {

    fill(level, room, Terrain.WALL);
    fill(level, room, 1, Terrain.EMPTY_SP);

    Room.Door entrance = room.entrance();

    Point pot = null;
    if (entrance.x == room.left) {
      pot = new Point(room.right - 1, Random.Int(2) == 0 ? room.top + 1 : room.bottom - 1);
    } else if (entrance.x == room.right) {
      pot = new Point(room.left + 1, Random.Int(2) == 0 ? room.top + 1 : room.bottom - 1);
    } else if (entrance.y == room.top) {
      pot = new Point(Random.Int(2) == 0 ? room.left + 1 : room.right - 1, room.bottom - 1);
    } else if (entrance.y == room.bottom) {
      pot = new Point(Random.Int(2) == 0 ? room.left + 1 : room.right - 1, room.top + 1);
    }
    set(level, pot, Terrain.ALCHEMY);

    Alchemy alchemy = new Alchemy();
    alchemy.seed(pot.x + level.getWidth() * pot.y, 1);
    level.blobs.put(Alchemy.class, alchemy);

    int n = Random.IntRange(2, 3);
    for (int i = 0; i < n; i++) {
      int pos;
      do {
        pos = room.random(level);
      } while (level.map[pos] != Terrain.EMPTY_SP || level.getHeap(pos) != null);
      level.drop(prize(level), pos);
    }

    entrance.set(Room.Door.Type.LOCKED);
    level.addItemToSpawn(new IronKey());
  }
Пример #2
0
  public static void paint(Level level, Room room) {

    Integer traps[] = {
      Terrain.TOXIC_TRAP,
      Terrain.TOXIC_TRAP,
      Terrain.TOXIC_TRAP,
      Terrain.PARALYTIC_TRAP,
      Terrain.PARALYTIC_TRAP,
      !Dungeon.bossLevel(Dungeon.depth + 1) ? Terrain.CHASM : Terrain.SUMMONING_TRAP
    };
    fill(level, room, Terrain.WALL);
    fill(level, room, 1, Random.element(traps));

    Room.Door door = room.entrance();
    door.set(Room.Door.Type.REGULAR);

    int lastRow =
        level.map[room.left + 1 + (room.top + 1) * Level.WIDTH] == Terrain.CHASM
            ? Terrain.CHASM
            : Terrain.EMPTY;

    int x = -1;
    int y = -1;
    if (door.x == room.left) {
      x = room.right - 1;
      y = room.top + room.height() / 2;
      fill(level, x, room.top + 1, 1, room.height() - 1, lastRow);
    } else if (door.x == room.right) {
      x = room.left + 1;
      y = room.top + room.height() / 2;
      fill(level, x, room.top + 1, 1, room.height() - 1, lastRow);
    } else if (door.y == room.top) {
      x = room.left + room.width() / 2;
      y = room.bottom - 1;
      fill(level, room.left + 1, y, room.width() - 1, 1, lastRow);
    } else if (door.y == room.bottom) {
      x = room.left + room.width() / 2;
      y = room.top + 1;
      fill(level, room.left + 1, y, room.width() - 1, 1, lastRow);
    }

    int pos = x + y * Level.WIDTH;
    if (Random.Int(3) == 0) {
      if (lastRow == Terrain.CHASM) {
        set(level, pos, Terrain.EMPTY);
      }
      level.drop(prize(level), pos).type = Heap.Type.CHEST;
    } else {
      set(level, pos, Terrain.PEDESTAL);
      level.drop(prize(level), pos);
    }

    level.addItemToSpawn(new PotionOfLevitation());
  }
Пример #3
0
  public static void saveGame(String fileName) throws IOException {
    try {
      Bundle bundle = new Bundle();

      bundle.put(VERSION, Game.version);
      bundle.put(CHALLENGES, challenges);
      bundle.put(HERO, hero);
      bundle.put(GOLD, gold);
      bundle.put(DEPTH, depth);

      bundle.put(POS, potionOfStrength);
      bundle.put(SOU, scrollsOfUpgrade);
      bundle.put(AS, arcaneStyli);
      bundle.put(DV, dewVial);
      bundle.put(WT, transmutation);

      int count = 0;
      int ids[] = new int[chapters.size()];
      for (Integer id : chapters) {
        ids[count++] = id;
      }
      bundle.put(CHAPTERS, ids);

      Bundle quests = new Bundle();
      Ghost.Quest.storeInBundle(quests);
      WandMaker.Quest.storeInBundle(quests);
      Blacksmith.Quest.storeInBundle(quests);
      Imp.Quest.storeInBundle(quests);
      bundle.put(QUESTS, quests);

      Room.storeRoomsInBundle(bundle);

      Statistics.storeInBundle(bundle);
      Journal.storeInBundle(bundle);

      if (quickslot instanceof Class) {
        bundle.put(QUICKSLOT, ((Class<?>) quickslot).getName());
      }

      Scroll.save(bundle);
      Potion.save(bundle);
      Wand.save(bundle);
      Ring.save(bundle);

      Bundle badges = new Bundle();
      Badges.saveLocal(badges);
      bundle.put(BADGES, badges);

      OutputStream output = Game.instance.openFileOutput(fileName, Game.MODE_PRIVATE);
      Bundle.write(bundle, output);
      output.close();

    } catch (Exception e) {

      GamesInProgress.setUnknown(hero.heroClass);
    }
  }
Пример #4
0
  public static void paint(Level level, Room room) {

    fill(level, room, Terrain.WALL);
    fill(level, room, 1, Terrain.EMPTY);

    Room.Door entrance = room.entrance();
    entrance.set(Room.Door.Type.LOCKED);

    Point well = null;
    if (entrance.x == room.left) {
      well = new Point(room.right - 1, Random.Int(2) == 0 ? room.top + 1 : room.bottom - 1);
    } else if (entrance.x == room.right) {
      well = new Point(room.left + 1, Random.Int(2) == 0 ? room.top + 1 : room.bottom - 1);
    } else if (entrance.y == room.top) {
      well = new Point(Random.Int(2) == 0 ? room.left + 1 : room.right - 1, room.bottom - 1);
    } else if (entrance.y == room.bottom) {
      well = new Point(Random.Int(2) == 0 ? room.left + 1 : room.right - 1, room.top + 1);
    }
    set(level, well, Terrain.EMPTY_WELL);

    int remains = room.random();
    while (level.map[remains] == Terrain.EMPTY_WELL) {
      remains = room.random();
    }

    level.drop(new IronKey(), remains).type = Type.SKELETON;

    if (Random.Int(5) == 0) {
      level.drop(Generator.random(Generator.Category.RING), remains);
    } else {
      level.drop(
          Generator.random(Random.oneOf(Generator.Category.WEAPON, Generator.Category.ARMOR)),
          remains);
    }

    int n = Random.IntRange(1, 2);
    for (int i = 0; i < n; i++) {
      level.drop(prize(level), remains);
    }
  }
Пример #5
0
  public static void init() {

    challenges = PixelDungeon.challenges();

    Actor.clear();

    PathFinder.setMapSize(Level.WIDTH, Level.HEIGHT);

    Scroll.initLabels();
    Potion.initColors();
    Wand.initWoods();
    Ring.initGems();

    Statistics.reset();
    Journal.reset();

    depth = 0;
    gold = 0;

    potionOfStrength = 0;
    scrollsOfUpgrade = 0;
    arcaneStyli = 0;
    dewVial = true;
    transmutation = Random.IntRange(6, 14);

    chapters = new HashSet<Integer>();

    Ghost.Quest.reset();
    WandMaker.Quest.reset();
    Blacksmith.Quest.reset();
    Imp.Quest.reset();

    Room.shuffleTypes();

    hero = new Hero();
    hero.live();

    Badges.reset();

    StartScene.curClass.initHero(hero);
  }
Пример #6
0
  public static void loadGame(String fileName, boolean fullLoad) throws IOException {

    Bundle bundle = gameBundle(fileName);

    Dungeon.challenges = bundle.getInt(CHALLENGES);

    Dungeon.level = null;
    Dungeon.depth = -1;

    if (fullLoad) {
      PathFinder.setMapSize(Level.WIDTH, Level.HEIGHT);
    }

    Scroll.restore(bundle);
    Potion.restore(bundle);
    Wand.restore(bundle);
    Ring.restore(bundle);

    potionOfStrength = bundle.getInt(POS);
    scrollsOfUpgrade = bundle.getInt(SOU);
    arcaneStyli = bundle.getInt(AS);
    dewVial = bundle.getBoolean(DV);
    transmutation = bundle.getInt(WT);

    if (fullLoad) {
      chapters = new HashSet<Integer>();
      int ids[] = bundle.getIntArray(CHAPTERS);
      if (ids != null) {
        for (int id : ids) {
          chapters.add(id);
        }
      }

      Bundle quests = bundle.getBundle(QUESTS);
      if (!quests.isNull()) {
        Ghost.Quest.restoreFromBundle(quests);
        WandMaker.Quest.restoreFromBundle(quests);
        Blacksmith.Quest.restoreFromBundle(quests);
        Imp.Quest.restoreFromBundle(quests);
      } else {
        Ghost.Quest.reset();
        WandMaker.Quest.reset();
        Blacksmith.Quest.reset();
        Imp.Quest.reset();
      }

      Room.restoreRoomsFromBundle(bundle);
    }

    Bundle badges = bundle.getBundle(BADGES);
    if (!badges.isNull()) {
      Badges.loadLocal(badges);
    } else {
      Badges.reset();
    }

    String qsClass = bundle.getString(QUICKSLOT);
    if (qsClass != null) {
      try {
        quickslot = Class.forName(qsClass);
      } catch (ClassNotFoundException e) {
      }
    } else {
      quickslot = null;
    }

    @SuppressWarnings("unused")
    String version = bundle.getString(VERSION);

    hero = null;
    hero = (Hero) bundle.get(HERO);

    gold = bundle.getInt(GOLD);
    depth = bundle.getInt(DEPTH);

    Statistics.restoreFromBundle(bundle);
    Journal.restoreFromBundle(bundle);
  }