v0.6.0: moved important usages of collections.shuffle into Random
This commit is contained in:
parent
75f9cd454b
commit
048b5e5f7b
|
@ -22,7 +22,9 @@
|
||||||
package com.watabou.utils;
|
package com.watabou.utils;
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
public class Random {
|
public class Random {
|
||||||
|
|
||||||
|
@ -156,6 +158,10 @@ public class Random {
|
||||||
(T)collection.toArray()[Int( size )] :
|
(T)collection.toArray()[Int( size )] :
|
||||||
null;
|
null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static<T> void shuffle( List<?extends T> list){
|
||||||
|
Collections.shuffle(list, rand);
|
||||||
|
}
|
||||||
|
|
||||||
public static<T> void shuffle( T[] array ) {
|
public static<T> void shuffle( T[] array ) {
|
||||||
for (int i=0; i < array.length - 1; i++) {
|
for (int i=0; i < array.length - 1; i++) {
|
||||||
|
|
|
@ -74,7 +74,7 @@ public abstract class RegularLevel extends Level {
|
||||||
|
|
||||||
|
|
||||||
ArrayList<Room> initRooms = initRooms();
|
ArrayList<Room> initRooms = initRooms();
|
||||||
Collections.shuffle(initRooms);
|
Random.shuffle(initRooms);
|
||||||
|
|
||||||
do {
|
do {
|
||||||
for (Room r : initRooms){
|
for (Room r : initRooms){
|
||||||
|
@ -340,7 +340,7 @@ public abstract class RegularLevel extends Level {
|
||||||
}
|
}
|
||||||
|
|
||||||
protected Room randomRoom( Class<?extends Room> type ) {
|
protected Room randomRoom( Class<?extends Room> type ) {
|
||||||
Collections.shuffle( rooms );
|
Random.shuffle( rooms );
|
||||||
for (Room r : rooms) {
|
for (Room r : rooms) {
|
||||||
if (type.isInstance(r)
|
if (type.isInstance(r)
|
||||||
//compatibility with pre-0.6.0 saves
|
//compatibility with pre-0.6.0 saves
|
||||||
|
|
|
@ -274,7 +274,7 @@ public class ShopRoom extends SpecialRoom {
|
||||||
if (itemsToSpawn.size() > 63)
|
if (itemsToSpawn.size() > 63)
|
||||||
throw new RuntimeException("Shop attempted to carry more than 63 items!");
|
throw new RuntimeException("Shop attempted to carry more than 63 items!");
|
||||||
|
|
||||||
Collections.shuffle(itemsToSpawn);
|
Random.shuffle(itemsToSpawn);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void ChooseBag(Belongings pack){
|
private static void ChooseBag(Belongings pack){
|
||||||
|
|
|
@ -85,7 +85,7 @@ public class SpecialRoom extends Room {
|
||||||
}
|
}
|
||||||
|
|
||||||
guaranteedWellDepth = Random.IntRange( 6, 14 );
|
guaranteedWellDepth = Random.IntRange( 6, 14 );
|
||||||
Collections.shuffle(runSpecials);
|
Random.shuffle(runSpecials);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void initForFloor(){
|
public static void initForFloor(){
|
||||||
|
|
Loading…
Reference in New Issue
Block a user