Java Code Examples for com.watabou.utils.Random#shuffle()
The following examples show how to use
com.watabou.utils.Random#shuffle() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RegularLevel.java From shattered-pixel-dungeon with GNU General Public License v3.0 | 6 votes |
@Override protected boolean build() { builder = builder(); ArrayList<Room> initRooms = initRooms(); Random.shuffle(initRooms); do { for (Room r : initRooms){ r.neigbours.clear(); r.connected.clear(); } rooms = builder.build((ArrayList<Room>)initRooms.clone()); } while (rooms == null); return painter().paint(this, rooms); }
Example 2
Source File: VaultRoom.java From shattered-pixel-dungeon with GNU General Public License v3.0 | 6 votes |
public void paint( Level level ) { Painter.fill( level, this, Terrain.WALL ); Painter.fill( level, this, 1, Terrain.EMPTY_SP ); Painter.fill( level, this, 2, Terrain.EMPTY ); int cx = (left + right) / 2; int cy = (top + bottom) / 2; int c = cx + cy * level.width(); Random.shuffle(prizeClasses); Item i1, i2; i1 = prize( level ); i2 = prize( level ); level.drop( i1, c ).type = Heap.Type.CRYSTAL_CHEST; if (Random.Int(10) == 0){ level.mobs.add(Mimic.spawnAt(c + PathFinder.NEIGHBOURS8[Random.Int(8)], i2, CrystalMimic.class)); } else { level.drop(i2, c + PathFinder.NEIGHBOURS8[Random.Int(8)]).type = Heap.Type.CRYSTAL_CHEST; } level.addItemToSpawn( new CrystalKey( Dungeon.depth ) ); entrance().set( Door.Type.LOCKED ); level.addItemToSpawn( new IronKey( Dungeon.depth ) ); }
Example 3
Source File: SecretRoom.java From shattered-pixel-dungeon with GNU General Public License v3.0 | 6 votes |
public static void initForRun(){ float[] regionChances = baseRegionSecrets.clone(); if (GamesInProgress.selectedClass == HeroClass.ROGUE){ for (int i = 0; i < regionChances.length; i++){ regionChances[i] += 0.6f; } } for (int i = 0; i < regionSecretsThisRun.length; i++){ regionSecretsThisRun[i] = (int)regionChances[i]; if (Random.Float() < regionChances[i] % 1f){ regionSecretsThisRun[i]++; } } runSecrets = new ArrayList<>(ALL_SECRETS); Random.shuffle(runSecrets); }
Example 4
Source File: RegularLevel.java From shattered-pixel-dungeon-gdx with GNU General Public License v3.0 | 6 votes |
@Override protected boolean build() { builder = builder(); ArrayList<Room> initRooms = initRooms(); Random.shuffle(initRooms); do { for (Room r : initRooms){ r.neigbours.clear(); r.connected.clear(); } rooms = builder.build((ArrayList<Room>)initRooms.clone()); } while (rooms == null); return painter().paint(this, rooms); }
Example 5
Source File: VaultRoom.java From shattered-pixel-dungeon-gdx with GNU General Public License v3.0 | 6 votes |
public void paint( Level level ) { Painter.fill( level, this, Terrain.WALL ); Painter.fill( level, this, 1, Terrain.EMPTY_SP ); Painter.fill( level, this, 2, Terrain.EMPTY ); int cx = (left + right) / 2; int cy = (top + bottom) / 2; int c = cx + cy * level.width(); Random.shuffle(prizeClasses); Item i1, i2; i1 = prize( level ); i2 = prize( level ); level.drop( i1, c ).type = Heap.Type.CRYSTAL_CHEST; level.drop( i2, c + PathFinder.NEIGHBOURS8[Random.Int( 8 )]).type = Heap.Type.CRYSTAL_CHEST; level.addItemToSpawn( new CrystalKey( Dungeon.depth ) ); entrance().set( Door.Type.LOCKED ); level.addItemToSpawn( new IronKey( Dungeon.depth ) ); }
Example 6
Source File: SecretRoom.java From shattered-pixel-dungeon-gdx with GNU General Public License v3.0 | 6 votes |
public static void initForRun(){ float[] regionChances = baseRegionSecrets.clone(); if (GamesInProgress.selectedClass == HeroClass.ROGUE){ for (int i = 0; i < regionChances.length; i++){ regionChances[i] += 0.6f; } } for (int i = 0; i < regionSecretsThisRun.length; i++){ regionSecretsThisRun[i] = (int)regionChances[i]; if (Random.Float() < regionChances[i] % 1f){ regionSecretsThisRun[i]++; } } runSecrets = new ArrayList<>(ALL_SECRETS); Random.shuffle(runSecrets); }
Example 7
Source File: Bestiary.java From shattered-pixel-dungeon with GNU General Public License v3.0 | 5 votes |
public static ArrayList<Class<? extends Mob>> getMobRotation( int depth ){ ArrayList<Class<? extends Mob>> mobs = standardMobRotation( depth ); addRareMobs(depth, mobs); swapMobAlts(mobs); Random.shuffle(mobs); return mobs; }
Example 8
Source File: RegularLevel.java From shattered-pixel-dungeon with GNU General Public License v3.0 | 5 votes |
protected Room randomRoom( Class<?extends Room> type ) { Random.shuffle( rooms ); for (Room r : rooms) { if (type.isInstance(r)) { return r; } } return null; }
Example 9
Source File: Bestiary.java From shattered-pixel-dungeon-gdx with GNU General Public License v3.0 | 5 votes |
public static ArrayList<Class<? extends Mob>> getMobRotation(int depth ){ ArrayList<Class<? extends Mob>> mobs = standardMobRotation( depth ); addRareMobs(depth, mobs); swapMobAlts(mobs); Random.shuffle(mobs); return mobs; }
Example 10
Source File: RegularLevel.java From shattered-pixel-dungeon-gdx with GNU General Public License v3.0 | 5 votes |
protected Room randomRoom( Class<?extends Room> type ) { Random.shuffle( rooms ); for (Room r : rooms) { if (type.isInstance(r)) { return r; } } return null; }
Example 11
Source File: RegularLevel.java From shattered-pixel-dungeon with GNU General Public License v3.0 | 4 votes |
@Override protected void createMobs() { //on floor 1, 8 pre-set mobs are created so the player can get level 2. int mobsToSpawn = Dungeon.depth == 1 ? 8 : nMobs(); ArrayList<Room> stdRooms = new ArrayList<>(); for (Room room : rooms) { if (room instanceof StandardRoom && room != roomEntrance) { for (int i = 0; i < ((StandardRoom) room).sizeCat.roomValue; i++) { stdRooms.add(room); } } } Random.shuffle(stdRooms); Iterator<Room> stdRoomIter = stdRooms.iterator(); while (mobsToSpawn > 0) { Mob mob = createMob(); Room roomToSpawn; if (!stdRoomIter.hasNext()) { stdRoomIter = stdRooms.iterator(); } roomToSpawn = stdRoomIter.next(); int tries = 30; do { mob.pos = pointToCell(roomToSpawn.random()); tries--; } while (tries >= 0 && (findMob(mob.pos) != null || !passable[mob.pos] || mob.pos == exit)); if (tries >= 0) { mobsToSpawn--; mobs.add(mob); //add a second mob to this room if (mobsToSpawn > 0 && Random.Int(4) == 0){ mob = createMob(); tries = 30; do { mob.pos = pointToCell(roomToSpawn.random()); tries--; } while (tries >= 0 && findMob(mob.pos) != null || !passable[mob.pos] || mob.pos == exit); if (tries >= 0) { mobsToSpawn--; mobs.add(mob); } } } } for (Mob m : mobs){ if (map[m.pos] == Terrain.HIGH_GRASS || map[m.pos] == Terrain.FURROWED_GRASS) { map[m.pos] = Terrain.GRASS; losBlocking[m.pos] = false; } } }
Example 12
Source File: SpecialRoom.java From shattered-pixel-dungeon with GNU General Public License v3.0 | 4 votes |
public static void initForRun() { runSpecials = (ArrayList<Class<?extends Room>>)ALL_SPEC.clone(); pitNeededDepth = -1; Random.shuffle(runSpecials); }
Example 13
Source File: RegularLevel.java From shattered-pixel-dungeon-gdx with GNU General Public License v3.0 | 4 votes |
@Override protected void createMobs() { //on floor 1, 8 pre-set mobs are created so the player can get level 2. int mobsToSpawn = Dungeon.depth == 1 ? 8 : nMobs(); ArrayList<Room> stdRooms = new ArrayList<>(); for (Room room : rooms) { if (room instanceof StandardRoom && room != roomEntrance) { for (int i = 0; i < ((StandardRoom) room).sizeCat.roomValue; i++) { stdRooms.add(room); } } } Random.shuffle(stdRooms); Iterator<Room> stdRoomIter = stdRooms.iterator(); while (mobsToSpawn > 0) { Mob mob = createMob(); Room roomToSpawn; if (!stdRoomIter.hasNext()) { stdRoomIter = stdRooms.iterator(); } roomToSpawn = stdRoomIter.next(); do { mob.pos = pointToCell(roomToSpawn.random()); } while (findMob(mob.pos) != null || !passable[mob.pos] || mob.pos == exit); mobsToSpawn--; mobs.add(mob); if (mobsToSpawn > 0 && Random.Int(4) == 0){ mob = createMob(); do { mob.pos = pointToCell(roomToSpawn.random()); } while (findMob(mob.pos) != null || !passable[mob.pos] || mob.pos == exit); mobsToSpawn--; mobs.add(mob); } } for (Mob m : mobs){ if (map[m.pos] == Terrain.HIGH_GRASS || map[m.pos] == Terrain.FURROWED_GRASS) { map[m.pos] = Terrain.GRASS; losBlocking[m.pos] = false; } } }
Example 14
Source File: SpecialRoom.java From shattered-pixel-dungeon-gdx with GNU General Public License v3.0 | 4 votes |
public static void initForRun() { runSpecials = (ArrayList<Class<?extends Room>>)ALL_SPEC.clone(); pitNeededDepth = -1; Random.shuffle(runSpecials); }