Search in sources :

Example 1 with RandomLevel

use of com.nyrds.pixeldungeon.levels.RandomLevel in project pixel-dungeon-remix by NYRDS.

the class DungeonGenerator method createLevel.

public static Level createLevel(Position pos) {
    Class<? extends Level> levelClass = mLevelKindList.get(getLevelKind(pos.levelId));
    if (levelClass == null) {
        GLog.w("Unknown level type: %s", getLevelKind(pos.levelId));
        return createLevel(pos);
    }
    try {
        Level ret;
        String levelId = pos.levelId;
        if (levelClass == PredesignedLevel.class) {
            String levelFile = mLevels.getJSONObject(levelId).getString("file");
            ret = new PredesignedLevel(levelFile);
        } else if (levelClass == RandomLevel.class) {
            String levelFile = mLevels.getJSONObject(levelId).getString("file");
            ret = new RandomLevel(levelFile);
        } else {
            ret = levelClass.newInstance();
        }
        ret.levelId = levelId;
        JSONObject levelDesc = mLevels.getJSONObject(pos.levelId);
        int xs = 32;
        int ys = 32;
        if (levelDesc.has("size")) {
            JSONArray levelSize = levelDesc.getJSONArray("size");
            xs = levelSize.optInt(0, 32);
            ys = levelSize.optInt(1, 32);
        }
        ret.create(xs, ys);
        return ret;
    } catch (InstantiationException | IllegalAccessException | JSONException e) {
        throw new TrackedRuntimeException(e);
    }
}
Also used : TrackedRuntimeException(com.nyrds.android.util.TrackedRuntimeException) RandomLevel(com.nyrds.pixeldungeon.levels.RandomLevel) JSONArray(org.json.JSONArray) JSONException(org.json.JSONException) PredesignedLevel(com.nyrds.pixeldungeon.levels.PredesignedLevel) JSONObject(org.json.JSONObject) GutsLevel(com.nyrds.pixeldungeon.levels.GutsLevel) PrisonLevel(com.watabou.pixeldungeon.levels.PrisonLevel) IceCavesLevel(com.nyrds.pixeldungeon.levels.IceCavesLevel) CavesLevel(com.watabou.pixeldungeon.levels.CavesLevel) TownShopLevel(com.nyrds.pixeldungeon.levels.TownShopLevel) HallsBossLevel(com.watabou.pixeldungeon.levels.HallsBossLevel) CavesBossLevel(com.watabou.pixeldungeon.levels.CavesBossLevel) NecroLevel(com.nyrds.pixeldungeon.levels.NecroLevel) ShadowLordLevel(com.nyrds.pixeldungeon.levels.ShadowLordLevel) DeadEndLevel(com.watabou.pixeldungeon.levels.DeadEndLevel) SewerBossLevel(com.watabou.pixeldungeon.levels.SewerBossLevel) LastLevel(com.watabou.pixeldungeon.levels.LastLevel) PrisonBossLevel(com.watabou.pixeldungeon.levels.PrisonBossLevel) CityLevel(com.watabou.pixeldungeon.levels.CityLevel) LastShopLevel(com.watabou.pixeldungeon.levels.LastShopLevel) Level(com.watabou.pixeldungeon.levels.Level) PredesignedLevel(com.nyrds.pixeldungeon.levels.PredesignedLevel) RandomLevel(com.nyrds.pixeldungeon.levels.RandomLevel) SewerLevel(com.watabou.pixeldungeon.levels.SewerLevel) SpiderLevel(com.nyrds.pixeldungeon.spiders.levels.SpiderLevel) CityBossLevel(com.watabou.pixeldungeon.levels.CityBossLevel) HallsLevel(com.watabou.pixeldungeon.levels.HallsLevel) FakeLastLevel(com.nyrds.pixeldungeon.levels.FakeLastLevel) IceCavesBossLevel(com.nyrds.pixeldungeon.levels.IceCavesBossLevel) NecroBossLevel(com.nyrds.pixeldungeon.levels.NecroBossLevel)

Aggregations

TrackedRuntimeException (com.nyrds.android.util.TrackedRuntimeException)1 FakeLastLevel (com.nyrds.pixeldungeon.levels.FakeLastLevel)1 GutsLevel (com.nyrds.pixeldungeon.levels.GutsLevel)1 IceCavesBossLevel (com.nyrds.pixeldungeon.levels.IceCavesBossLevel)1 IceCavesLevel (com.nyrds.pixeldungeon.levels.IceCavesLevel)1 NecroBossLevel (com.nyrds.pixeldungeon.levels.NecroBossLevel)1 NecroLevel (com.nyrds.pixeldungeon.levels.NecroLevel)1 PredesignedLevel (com.nyrds.pixeldungeon.levels.PredesignedLevel)1 RandomLevel (com.nyrds.pixeldungeon.levels.RandomLevel)1 ShadowLordLevel (com.nyrds.pixeldungeon.levels.ShadowLordLevel)1 TownShopLevel (com.nyrds.pixeldungeon.levels.TownShopLevel)1 SpiderLevel (com.nyrds.pixeldungeon.spiders.levels.SpiderLevel)1 CavesBossLevel (com.watabou.pixeldungeon.levels.CavesBossLevel)1 CavesLevel (com.watabou.pixeldungeon.levels.CavesLevel)1 CityBossLevel (com.watabou.pixeldungeon.levels.CityBossLevel)1 CityLevel (com.watabou.pixeldungeon.levels.CityLevel)1 DeadEndLevel (com.watabou.pixeldungeon.levels.DeadEndLevel)1 HallsBossLevel (com.watabou.pixeldungeon.levels.HallsBossLevel)1 HallsLevel (com.watabou.pixeldungeon.levels.HallsLevel)1 LastLevel (com.watabou.pixeldungeon.levels.LastLevel)1