refactor: rename DefaultDeckGenerator to RandomDeckGenerator. DefaultDeckGenerator conveys no information about what the class does.

master
Lodici 2014-03-13 15:20:49 +00:00
parent 4d9213dcc3
commit 1326f340c1
15 changed files with 35 additions and 35 deletions

View File

@ -1,6 +1,6 @@
package magic.data; package magic.data;
import magic.generator.DefaultDeckGenerator; import magic.generator.RandomDeckGenerator;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
@ -18,10 +18,10 @@ public class DeckGenerators {
private static final String FILENAME = "deckgenerators.txt"; private static final String FILENAME = "deckgenerators.txt";
private final Map<String, DefaultDeckGenerator> generatorsMap; private final Map<String, RandomDeckGenerator> generatorsMap;
private DeckGenerators() { private DeckGenerators() {
generatorsMap = new TreeMap<String, DefaultDeckGenerator>(); generatorsMap = new TreeMap<String, RandomDeckGenerator>();
} }
public Set<String> getGeneratorNames() { public Set<String> getGeneratorNames() {
@ -39,7 +39,7 @@ public class DeckGenerators {
generatorsMap.put( generatorsMap.put(
name, name,
Class.forName("magic.generator." + cname + "_DeckGenerator") Class.forName("magic.generator." + cname + "_DeckGenerator")
.asSubclass(DefaultDeckGenerator.class) .asSubclass(RandomDeckGenerator.class)
.newInstance() .newInstance()
); );
System.err.println("added deck generator " + name); System.err.println("added deck generator " + name);
@ -55,7 +55,7 @@ public class DeckGenerators {
} }
} }
public DefaultDeckGenerator getDeckGenerator(final String name) { public RandomDeckGenerator getDeckGenerator(final String name) {
return generatorsMap.get(name); return generatorsMap.get(name);
} }

View File

@ -11,7 +11,7 @@ import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.Random; import java.util.Random;
public class Ability_Mono_DeckGenerator extends DefaultDeckGenerator { public class Ability_Mono_DeckGenerator extends RandomDeckGenerator {
private static final int MIN_NUM_CARDS_WITH_SUBTYPE = 30; private static final int MIN_NUM_CARDS_WITH_SUBTYPE = 30;

View File

@ -6,7 +6,7 @@ import magic.model.MagicCondensedDeck;
import magic.model.MagicDeckProfile; import magic.model.MagicDeckProfile;
import magic.model.MagicSubType; import magic.model.MagicSubType;
public class Elf_Horde_DeckGenerator extends DefaultDeckGenerator { public class Elf_Horde_DeckGenerator extends RandomDeckGenerator {
private static final String colorText = "g"; private static final String colorText = "g";
private static final String[] cards = { private static final String[] cards = {

View File

@ -6,7 +6,7 @@ import magic.model.MagicCondensedDeck;
import magic.model.MagicDeckProfile; import magic.model.MagicDeckProfile;
import magic.model.MagicSubType; import magic.model.MagicSubType;
public class Fairy_Horde_DeckGenerator extends DefaultDeckGenerator { public class Fairy_Horde_DeckGenerator extends RandomDeckGenerator {
private static final String colorText = "bu"; private static final String colorText = "bu";
private static final String[] spells = { private static final String[] spells = {

View File

@ -6,7 +6,7 @@ import magic.model.MagicCondensedDeck;
import magic.model.MagicDeckProfile; import magic.model.MagicDeckProfile;
import magic.model.MagicSubType; import magic.model.MagicSubType;
public class Human_Law_DeckGenerator extends DefaultDeckGenerator { public class Human_Law_DeckGenerator extends RandomDeckGenerator {
private static final String colorText = "w"; private static final String colorText = "w";
private static final String[] cards = { private static final String[] cards = {

View File

@ -11,14 +11,14 @@ import magic.model.MagicRandom;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
public class DefaultDeckGenerator { public class RandomDeckGenerator {
private final List<MagicCardDefinition> spellCards = new ArrayList<MagicCardDefinition>(); private final List<MagicCardDefinition> spellCards = new ArrayList<MagicCardDefinition>();
private final List<MagicCardDefinition> landCards = new ArrayList<MagicCardDefinition>(); private final List<MagicCardDefinition> landCards = new ArrayList<MagicCardDefinition>();
private MagicCubeDefinition cubeDefinition; private MagicCubeDefinition cubeDefinition;
public DefaultDeckGenerator(final MagicCubeDefinition cubeDefinition) { public RandomDeckGenerator(final MagicCubeDefinition cubeDefinition) {
this.cubeDefinition = cubeDefinition; this.cubeDefinition = cubeDefinition;
} }

View File

@ -4,7 +4,7 @@ import magic.data.CubeDefinitions;
import magic.model.MagicCondensedDeck; import magic.model.MagicCondensedDeck;
import magic.model.MagicDeckProfile; import magic.model.MagicDeckProfile;
public class Saint___Hero_DeckGenerator extends DefaultDeckGenerator { public class Saint___Hero_DeckGenerator extends RandomDeckGenerator {
private static final String colorText = "wu"; private static final String colorText = "wu";
private static final String[] spells = { private static final String[] spells = {

View File

@ -5,7 +5,7 @@ import magic.model.MagicCardDefinition;
import magic.model.MagicCondensedDeck; import magic.model.MagicCondensedDeck;
import magic.model.MagicDeckProfile; import magic.model.MagicDeckProfile;
public class Token_Madness_DeckGenerator extends DefaultDeckGenerator { public class Token_Madness_DeckGenerator extends RandomDeckGenerator {
private static final String colorText = "wg"; private static final String colorText = "wg";
private static final String[] spells = { private static final String[] spells = {

View File

@ -11,7 +11,7 @@ import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.Random; import java.util.Random;
public class Tribal_Mono_DeckGenerator extends DefaultDeckGenerator { public class Tribal_Mono_DeckGenerator extends RandomDeckGenerator {
private static final int MIN_NUM_CARDS_WITH_SUBTYPE = 30; private static final int MIN_NUM_CARDS_WITH_SUBTYPE = 30;

View File

@ -6,7 +6,7 @@ import magic.model.MagicCondensedDeck;
import magic.model.MagicDeckProfile; import magic.model.MagicDeckProfile;
import magic.model.MagicSubType; import magic.model.MagicSubType;
public class Vampire_Rage_DeckGenerator extends DefaultDeckGenerator { public class Vampire_Rage_DeckGenerator extends RandomDeckGenerator {
private static final String colorText = "br"; private static final String colorText = "br";
private static final String[] spells = { private static final String[] spells = {

View File

@ -6,7 +6,7 @@ import magic.model.MagicCondensedDeck;
import magic.model.MagicDeckProfile; import magic.model.MagicDeckProfile;
import magic.model.MagicSubType; import magic.model.MagicSubType;
public class White_Knights_DeckGenerator extends DefaultDeckGenerator { public class White_Knights_DeckGenerator extends RandomDeckGenerator {
private static final String colorText = "w"; private static final String colorText = "w";
private static final String[] cards = { private static final String[] cards = {

View File

@ -5,7 +5,7 @@ import magic.model.MagicCardDefinition;
import magic.model.MagicCondensedDeck; import magic.model.MagicCondensedDeck;
import magic.model.MagicDeckProfile; import magic.model.MagicDeckProfile;
public class White_Metal_DeckGenerator extends DefaultDeckGenerator { public class White_Metal_DeckGenerator extends RandomDeckGenerator {
private static final String colorText = "w"; private static final String colorText = "w";
private static final String[] spells = { private static final String[] spells = {

View File

@ -6,7 +6,7 @@ import magic.model.MagicCondensedDeck;
import magic.model.MagicDeckProfile; import magic.model.MagicDeckProfile;
import magic.model.MagicSubType; import magic.model.MagicSubType;
public class Zombie_Madness_DeckGenerator extends DefaultDeckGenerator { public class Zombie_Madness_DeckGenerator extends RandomDeckGenerator {
private static final String colorText = "b"; private static final String colorText = "b";
private static final String[] cards = { private static final String[] cards = {

View File

@ -6,7 +6,7 @@ import magic.ai.MagicAI;
import magic.data.CubeDefinitions; import magic.data.CubeDefinitions;
import magic.data.DeckUtils; import magic.data.DeckUtils;
import magic.data.DuelConfig; import magic.data.DuelConfig;
import magic.generator.DefaultDeckGenerator; import magic.generator.RandomDeckGenerator;
import magic.model.phase.MagicDefaultGameplay; import magic.model.phase.MagicDefaultGameplay;
import magic.model.player.PlayerProfile; import magic.model.player.PlayerProfile;
import magic.ui.viewer.DeckStrengthViewer; import magic.ui.viewer.DeckStrengthViewer;
@ -202,11 +202,21 @@ public class MagicDuel {
} }
public void buildDeck(final MagicPlayerDefinition player) { public void buildDeck(final MagicPlayerDefinition player) {
final MagicCubeDefinition cubeDefinition = CubeDefinitions.getCubeDefinition(duelConfig.getCube());
final DefaultDeckGenerator generator = new DefaultDeckGenerator(cubeDefinition);
if (player.getDeckProfile().isPreConstructed()) { if (player.getDeckProfile().isPreConstructed()) {
DeckUtils.loadRandomDeckFile(player); DeckUtils.loadRandomDeckFile(player);
} else { } else {
final MagicCubeDefinition cubeDefinition = CubeDefinitions.getCubeDefinition(duelConfig.getCube());
final RandomDeckGenerator generator = new RandomDeckGenerator(cubeDefinition);
player.generateDeck(generator);
}
}
private void createRandomDeck(final MagicPlayerDefinition player) {
if(player.getDeckGenerator() == null && player.getDeckProfile().getNrOfColors() == 0) {
DeckUtils.loadRandomDeckFile(player);
} else {
final MagicCubeDefinition cubeDefinition=CubeDefinitions.getCubeDefinition(duelConfig.getCube());
final RandomDeckGenerator generator = new RandomDeckGenerator(cubeDefinition);
player.generateDeck(generator); player.generateDeck(generator);
} }
} }
@ -235,16 +245,6 @@ public class MagicDuel {
} }
} }
private void createRandomDeck(final MagicPlayerDefinition player) {
if(player.getDeckGenerator() == null && player.getDeckProfile().getNrOfColors() == 0) {
DeckUtils.loadRandomDeckFile(player);
} else {
final MagicCubeDefinition cubeDefinition=CubeDefinitions.getCubeDefinition(duelConfig.getCube());
final DefaultDeckGenerator generator = new DefaultDeckGenerator(cubeDefinition);
player.generateDeck(generator);
}
}
public void initialize() { public void initialize() {
playerDefinitions=createPlayers(); playerDefinitions=createPlayers();
buildDecks(); buildDecks();

View File

@ -2,7 +2,7 @@ package magic.model;
import magic.data.CardDefinitions; import magic.data.CardDefinitions;
import magic.data.DeckGenerators; import magic.data.DeckGenerators;
import magic.generator.DefaultDeckGenerator; import magic.generator.RandomDeckGenerator;
import magic.model.player.AiPlayer; import magic.model.player.AiPlayer;
import magic.model.player.PlayerProfile; import magic.model.player.PlayerProfile;
import magic.ui.theme.PlayerAvatar; import magic.ui.theme.PlayerAvatar;
@ -115,7 +115,7 @@ public class MagicPlayerDefinition {
deck.setContent(aDeck); deck.setContent(aDeck);
} }
public DefaultDeckGenerator getDeckGenerator() { public RandomDeckGenerator getDeckGenerator() {
final String name = getDeckProfile().getDeckGeneratorName(); final String name = getDeckProfile().getDeckGeneratorName();
if (name == null) { if (name == null) {
@ -125,8 +125,8 @@ public class MagicPlayerDefinition {
return DeckGenerators.getInstance().getDeckGenerator(name); return DeckGenerators.getInstance().getDeckGenerator(name);
} }
void generateDeck(final DefaultDeckGenerator defaultGenerator) { void generateDeck(final RandomDeckGenerator defaultGenerator) {
final DefaultDeckGenerator customGenerator = getDeckGenerator(); final RandomDeckGenerator customGenerator = getDeckGenerator();
if(customGenerator == null) { if(customGenerator == null) {
defaultGenerator.generateDeck(DECK_SIZE, deckProfile, deck); defaultGenerator.generateDeck(DECK_SIZE, deckProfile, deck);