Basically what @Egor Skriptunoff said. This should scale easily. You could use a collection of Class<Monster>
if you didn't want to use an enum
.
enum Monster {
GOLD(1),
SILVER(3),
BRONZE(6) // pseudo probabilities
private int weight;
// constructor etc..
}
public Monster getMonsterSpecial() {
List<Monster> monsters = new ArrayList<>();
for(Monster monsterType : Monster.values()) {
monsters.addAll(Collections.nCopies(monsterType.getWeight(), monsterType));
}
int winIndex = random.nextInt(monsters.length);
return monsters.get(winIndex);
}
You could perhaps make the enum Monsters
plural, and have it point to a Class<? extends Monster>
if you still want to instantiate monster classes. I just tried to make the example clearer.