mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-19 04:08:01 +00:00
some Checkstyle in Gui_WinLose and GenerateThemeDeck
This commit is contained in:
@@ -46,7 +46,7 @@ import java.util.List;
|
|||||||
* @version $Id$
|
* @version $Id$
|
||||||
*/
|
*/
|
||||||
public class Gui_WinLose extends JFrame implements NewConstants {
|
public class Gui_WinLose extends JFrame implements NewConstants {
|
||||||
/** Constant <code>serialVersionUID=-5800412940994975483L</code> */
|
/** Constant <code>serialVersionUID=-5800412940994975483L</code>. */
|
||||||
private static final long serialVersionUID = -5800412940994975483L;
|
private static final long serialVersionUID = -5800412940994975483L;
|
||||||
|
|
||||||
private JLabel titleLabel = new JLabel();
|
private JLabel titleLabel = new JLabel();
|
||||||
@@ -72,6 +72,10 @@ public class Gui_WinLose extends JFrame implements NewConstants {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>Constructor for Gui_WinLose.</p>
|
* <p>Constructor for Gui_WinLose.</p>
|
||||||
|
*
|
||||||
|
* @param matchState a QuestMatchState
|
||||||
|
* @param quest a QuestData object
|
||||||
|
* @param qa a Quest_Assignment object
|
||||||
*/
|
*/
|
||||||
public Gui_WinLose(final QuestMatchState matchState, final QuestData quest, final Quest_Assignment qa) {
|
public Gui_WinLose(final QuestMatchState matchState, final QuestData quest, final Quest_Assignment qa) {
|
||||||
model = new WinLoseModel();
|
model = new WinLoseModel();
|
||||||
@@ -118,7 +122,7 @@ public class Gui_WinLose extends JFrame implements NewConstants {
|
|||||||
} else {
|
} else {
|
||||||
titleLabel.setText(ForgeProps.getLocalized(WINLOSE_TEXT.LOSE));
|
titleLabel.setText(ForgeProps.getLocalized(WINLOSE_TEXT.LOSE));
|
||||||
}
|
}
|
||||||
}//setup();
|
} //setup();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>jbInit.</p>
|
* <p>jbInit.</p>
|
||||||
@@ -134,15 +138,15 @@ public class Gui_WinLose extends JFrame implements NewConstants {
|
|||||||
this.getContentPane().setLayout(new MigLayout("fill"));
|
this.getContentPane().setLayout(new MigLayout("fill"));
|
||||||
continueButton.setText(ForgeProps.getLocalized(WINLOSE_TEXT.CONTINUE));
|
continueButton.setText(ForgeProps.getLocalized(WINLOSE_TEXT.CONTINUE));
|
||||||
continueButton.addActionListener(new java.awt.event.ActionListener() {
|
continueButton.addActionListener(new java.awt.event.ActionListener() {
|
||||||
public void actionPerformed(ActionEvent e) { continueButton_actionPerformed(e); }
|
public void actionPerformed(final ActionEvent e) { continueButton_actionPerformed(e); }
|
||||||
});
|
});
|
||||||
restartButton.setText(ForgeProps.getLocalized(WINLOSE_TEXT.RESTART));
|
restartButton.setText(ForgeProps.getLocalized(WINLOSE_TEXT.RESTART));
|
||||||
restartButton.addActionListener(new java.awt.event.ActionListener() {
|
restartButton.addActionListener(new java.awt.event.ActionListener() {
|
||||||
public void actionPerformed(ActionEvent e) { restartButton_actionPerformed(e); }
|
public void actionPerformed(final ActionEvent e) { restartButton_actionPerformed(e); }
|
||||||
});
|
});
|
||||||
quitButton.setText(ForgeProps.getLocalized(WINLOSE_TEXT.QUIT));
|
quitButton.setText(ForgeProps.getLocalized(WINLOSE_TEXT.QUIT));
|
||||||
quitButton.addActionListener(new java.awt.event.ActionListener() {
|
quitButton.addActionListener(new java.awt.event.ActionListener() {
|
||||||
public void actionPerformed(ActionEvent e) { quitButton_actionPerformed(e); }
|
public void actionPerformed(final ActionEvent e) { quitButton_actionPerformed(e); }
|
||||||
});
|
});
|
||||||
statsLabel.setFont(new java.awt.Font("Dialog", 0, 16));
|
statsLabel.setFont(new java.awt.Font("Dialog", 0, 16));
|
||||||
statsLabel.setHorizontalAlignment(SwingConstants.CENTER);
|
statsLabel.setHorizontalAlignment(SwingConstants.CENTER);
|
||||||
@@ -150,7 +154,7 @@ public class Gui_WinLose extends JFrame implements NewConstants {
|
|||||||
jPanel2.setLayout(new MigLayout("align center"));
|
jPanel2.setLayout(new MigLayout("align center"));
|
||||||
this.addWindowListener(new java.awt.event.WindowAdapter() {
|
this.addWindowListener(new java.awt.event.WindowAdapter() {
|
||||||
@Override
|
@Override
|
||||||
public void windowClosing(WindowEvent e) { this_windowClosing(e); }
|
public void windowClosing(final WindowEvent e) { this_windowClosing(e); }
|
||||||
});
|
});
|
||||||
this.getContentPane().add(titleLabel, "align center, grow, wrap");
|
this.getContentPane().add(titleLabel, "align center, grow, wrap");
|
||||||
this.getContentPane().add(statsLabel, "align center, grow, wrap");
|
this.getContentPane().add(statsLabel, "align center, grow, wrap");
|
||||||
@@ -166,38 +170,41 @@ public class Gui_WinLose extends JFrame implements NewConstants {
|
|||||||
*
|
*
|
||||||
* @param e a {@link java.awt.event.ActionEvent} object.
|
* @param e a {@link java.awt.event.ActionEvent} object.
|
||||||
*/
|
*/
|
||||||
void continueButton_actionPerformed(ActionEvent e) {
|
final void continueButton_actionPerformed(ActionEvent e) {
|
||||||
// issue 147 - keep battlefield up following win/loss
|
// issue 147 - keep battlefield up following win/loss
|
||||||
JFrame frame = (JFrame) AllZone.getDisplay();
|
JFrame frame = (JFrame) AllZone.getDisplay();
|
||||||
frame.dispose();
|
frame.dispose();
|
||||||
|
|
||||||
//open up "Game" screen
|
//open up "Game" screen
|
||||||
PrepareForNextRound();
|
prepareForNextRound();
|
||||||
AllZone.getDisplay().setVisible(true);
|
AllZone.getDisplay().setVisible(true);
|
||||||
frame.setEnabled(true);
|
frame.setEnabled(true);
|
||||||
dispose();
|
dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
void PrepareForNextRound()
|
void prepareForNextRound() {
|
||||||
{
|
|
||||||
if (Constant.Quest.fantasyQuest[0]) {
|
if (Constant.Quest.fantasyQuest[0]) {
|
||||||
int extraLife = 0;
|
int extraLife = 0;
|
||||||
if (model.qa != null) {
|
if (model.qa != null) {
|
||||||
forge.quest.data.QuestUtil.setupQuest(model.qa);
|
forge.quest.data.QuestUtil.setupQuest(model.qa);
|
||||||
if (model.quest.getInventory().hasItem("Zeppelin"))
|
if (model.quest.getInventory().hasItem("Zeppelin")) {
|
||||||
extraLife = 3;
|
extraLife = 3;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
//AllZone.getGameAction().newGame(Constant.Runtime.HumanDeck[0], Constant.Runtime.ComputerDeck[0], humanList, computerList, humanLife, computerLife);
|
//AllZone.getGameAction().newGame(Constant.Runtime.HumanDeck[0], Constant.Runtime.ComputerDeck[0],
|
||||||
|
//humanList, computerList, humanLife, computerLife);
|
||||||
CardList humanList = forge.quest.data.QuestUtil.getHumanPlantAndPet(model.quest, model.qa);
|
CardList humanList = forge.quest.data.QuestUtil.getHumanPlantAndPet(model.quest, model.qa);
|
||||||
CardList computerList = new CardList();
|
CardList computerList = new CardList();
|
||||||
|
|
||||||
|
|
||||||
int humanLife = model.quest.getLife() + extraLife;
|
int humanLife = model.quest.getLife() + extraLife;
|
||||||
int computerLife = 20;
|
int computerLife = 20;
|
||||||
if ( model.qa != null )
|
if (model.qa != null) {
|
||||||
computerLife = model.qa.getComputerLife();
|
computerLife = model.qa.getComputerLife();
|
||||||
|
}
|
||||||
|
|
||||||
AllZone.getGameAction().newGame(Constant.Runtime.HumanDeck[0], Constant.Runtime.ComputerDeck[0], humanList, computerList, humanLife, computerLife, model.qa);
|
AllZone.getGameAction().newGame(Constant.Runtime.HumanDeck[0], Constant.Runtime.ComputerDeck[0],
|
||||||
|
humanList, computerList, humanLife, computerLife, model.qa);
|
||||||
} else {
|
} else {
|
||||||
AllZone.getGameAction().newGame(Constant.Runtime.HumanDeck[0], Constant.Runtime.ComputerDeck[0]);
|
AllZone.getGameAction().newGame(Constant.Runtime.HumanDeck[0], Constant.Runtime.ComputerDeck[0]);
|
||||||
}
|
}
|
||||||
@@ -209,13 +216,13 @@ public class Gui_WinLose extends JFrame implements NewConstants {
|
|||||||
*
|
*
|
||||||
* @param e a {@link java.awt.event.ActionEvent} object.
|
* @param e a {@link java.awt.event.ActionEvent} object.
|
||||||
*/
|
*/
|
||||||
void restartButton_actionPerformed(ActionEvent e) {
|
final void restartButton_actionPerformed(ActionEvent e) {
|
||||||
// issue 147 - keep battlefield up following win/loss
|
// issue 147 - keep battlefield up following win/loss
|
||||||
JFrame frame = (JFrame) AllZone.getDisplay();
|
JFrame frame = (JFrame) AllZone.getDisplay();
|
||||||
frame.dispose();
|
frame.dispose();
|
||||||
|
|
||||||
model.match.reset();
|
model.match.reset();
|
||||||
PrepareForNextRound();
|
prepareForNextRound();
|
||||||
AllZone.getDisplay().setVisible(true);
|
AllZone.getDisplay().setVisible(true);
|
||||||
frame.setEnabled(true);
|
frame.setEnabled(true);
|
||||||
dispose();
|
dispose();
|
||||||
@@ -229,7 +236,9 @@ public class Gui_WinLose extends JFrame implements NewConstants {
|
|||||||
* @param q a {@link forge.quest.data.QuestData} object.
|
* @param q a {@link forge.quest.data.QuestData} object.
|
||||||
* @return a {@link java.lang.String} object.
|
* @return a {@link java.lang.String} object.
|
||||||
*/
|
*/
|
||||||
private String getCreditsAwardedText(final long creds, final QuestMatchState matchState, final forge.quest.data.QuestData q) {
|
private String getCreditsAwardedText(final long creds, final QuestMatchState matchState,
|
||||||
|
final forge.quest.data.QuestData q)
|
||||||
|
{
|
||||||
// TODO use q.qdPrefs to write bonus credits in prefs file
|
// TODO use q.qdPrefs to write bonus credits in prefs file
|
||||||
StringBuilder sb = new StringBuilder("<html>");
|
StringBuilder sb = new StringBuilder("<html>");
|
||||||
|
|
||||||
@@ -308,7 +317,7 @@ public class Gui_WinLose extends JFrame implements NewConstants {
|
|||||||
* @param fileName a {@link java.lang.String} object.
|
* @param fileName a {@link java.lang.String} object.
|
||||||
* @return a {@link javax.swing.ImageIcon} object.
|
* @return a {@link javax.swing.ImageIcon} object.
|
||||||
*/
|
*/
|
||||||
private ImageIcon getIcon(String fileName) {
|
private ImageIcon getIcon(final String fileName) {
|
||||||
File base = ForgeProps.getFile(IMAGE_ICON);
|
File base = ForgeProps.getFile(IMAGE_ICON);
|
||||||
File file = new File(base, fileName);
|
File file = new File(base, fileName);
|
||||||
ImageIcon icon = new ImageIcon(file.toString());
|
ImageIcon icon = new ImageIcon(file.toString());
|
||||||
@@ -320,7 +329,7 @@ public class Gui_WinLose extends JFrame implements NewConstants {
|
|||||||
*
|
*
|
||||||
* @param e a {@link java.awt.event.ActionEvent} object.
|
* @param e a {@link java.awt.event.ActionEvent} object.
|
||||||
*/
|
*/
|
||||||
void quitButton_actionPerformed(ActionEvent e) {
|
final void quitButton_actionPerformed(ActionEvent e) {
|
||||||
// issue 147 - keep battlefield up following win/loss
|
// issue 147 - keep battlefield up following win/loss
|
||||||
JFrame frame = (JFrame) AllZone.getDisplay();
|
JFrame frame = (JFrame) AllZone.getDisplay();
|
||||||
frame.dispose();
|
frame.dispose();
|
||||||
@@ -356,7 +365,7 @@ public class Gui_WinLose extends JFrame implements NewConstants {
|
|||||||
model.quest.saveData();
|
model.quest.saveData();
|
||||||
|
|
||||||
new QuestFrame();
|
new QuestFrame();
|
||||||
}//else - on quest
|
} //else - on quest
|
||||||
|
|
||||||
dispose();
|
dispose();
|
||||||
|
|
||||||
@@ -375,14 +384,17 @@ public class Gui_WinLose extends JFrame implements NewConstants {
|
|||||||
quitButton_actionPerformed(null);
|
quitButton_actionPerformed(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void giveBooster()
|
/**
|
||||||
{
|
*
|
||||||
|
* TODO Write javadoc for this method.
|
||||||
|
*/
|
||||||
|
protected final void giveBooster() {
|
||||||
String[] boosterTypes = {"Legacy", "Extended", "Standard"};
|
String[] boosterTypes = {"Legacy", "Extended", "Standard"};
|
||||||
String boosterType = GuiUtils.getChoice("Choose prize booster format", boosterTypes);
|
String boosterType = GuiUtils.getChoice("Choose prize booster format", boosterTypes);
|
||||||
List<String> setsToGive = null;
|
List<String> setsToGive = null;
|
||||||
if (boosterTypes[2].equals(boosterType)) { // T2
|
if (boosterTypes[2].equals(boosterType)) { // T2
|
||||||
setsToGive = new ArrayList<String>();
|
setsToGive = new ArrayList<String>();
|
||||||
setsToGive.addAll(Arrays.asList(new String[]{"M12","NPH","MBS","M11","ROE","WWK","ZEN"}));
|
setsToGive.addAll(Arrays.asList(new String[]{"M12", "NPH", "MBS", "M11", "ROE", "WWK", "ZEN"}));
|
||||||
}
|
}
|
||||||
if (boosterTypes[1].equals(boosterType)) { // Ext
|
if (boosterTypes[1].equals(boosterType)) { // Ext
|
||||||
setsToGive = new ArrayList<String>();
|
setsToGive = new ArrayList<String>();
|
||||||
@@ -396,6 +408,11 @@ public class Gui_WinLose extends JFrame implements NewConstants {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* TODO Write javadoc for this method.
|
||||||
|
* @param wonMatch
|
||||||
|
*/
|
||||||
protected void giveQuestRewards(final boolean wonMatch) {
|
protected void giveQuestRewards(final boolean wonMatch) {
|
||||||
// Award a random booster, as frequent as set in difficulty setup
|
// Award a random booster, as frequent as set in difficulty setup
|
||||||
if (model.quest.getRewards().willGiveBooster(wonMatch)) {
|
if (model.quest.getRewards().willGiveBooster(wonMatch)) {
|
||||||
@@ -464,7 +481,8 @@ public class Gui_WinLose extends JFrame implements NewConstants {
|
|||||||
fileName = CardUtil.buildFilename(c) +".jpg";
|
fileName = CardUtil.buildFilename(c) +".jpg";
|
||||||
icon = getCardIcon(fileName);
|
icon = getCardIcon(fileName);
|
||||||
|
|
||||||
JOptionPane.showMessageDialog(null, "", "You have won a random rare for winning against a very hard deck.", JOptionPane.INFORMATION_MESSAGE, icon);
|
JOptionPane.showMessageDialog(null, "", "You have won a random rare for winning against a very hard deck.",
|
||||||
|
JOptionPane.INFORMATION_MESSAGE, icon);
|
||||||
}*/
|
}*/
|
||||||
|
|
||||||
// Loss match penalty
|
// Loss match penalty
|
||||||
|
|||||||
@@ -36,23 +36,26 @@ public class GenerateThemeDeck {
|
|||||||
*
|
*
|
||||||
* @return a {@link java.util.ArrayList} object.
|
* @return a {@link java.util.ArrayList} object.
|
||||||
*/
|
*/
|
||||||
public ArrayList<String> getThemeNames() {
|
public final ArrayList<String> getThemeNames() {
|
||||||
ArrayList<String> ltNames = new ArrayList<String>();
|
ArrayList<String> ltNames = new ArrayList<String>();
|
||||||
|
|
||||||
File file = new File("res/quest/themes/");
|
File file = new File("res/quest/themes/");
|
||||||
|
|
||||||
if (!file.exists())
|
if (!file.exists()) {
|
||||||
throw new RuntimeException("GenerateThemeDeck : getThemeNames error -- file not found -- filename is "
|
throw new RuntimeException("GenerateThemeDeck : getThemeNames error -- file not found -- filename is "
|
||||||
+ file.getAbsolutePath());
|
+ file.getAbsolutePath());
|
||||||
|
}
|
||||||
|
|
||||||
if (!file.isDirectory())
|
if (!file.isDirectory()) {
|
||||||
throw new RuntimeException("GenerateThemeDeck : getThemeNames error -- not a directory -- "
|
throw new RuntimeException("GenerateThemeDeck : getThemeNames error -- not a directory -- "
|
||||||
+ file.getAbsolutePath());
|
+ file.getAbsolutePath());
|
||||||
|
}
|
||||||
|
|
||||||
String[] fileList = file.list();
|
String[] fileList = file.list();
|
||||||
for (int i = 0; i < fileList.length; i++) {
|
for (int i = 0; i < fileList.length; i++) {
|
||||||
if (fileList[i].endsWith(".thm"))
|
if (fileList[i].endsWith(".thm")) {
|
||||||
ltNames.add(fileList[i].substring(0, fileList[i].indexOf(".thm")));
|
ltNames.add(fileList[i].substring(0, fileList[i].indexOf(".thm")));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return ltNames;
|
return ltNames;
|
||||||
@@ -61,67 +64,72 @@ public class GenerateThemeDeck {
|
|||||||
/**
|
/**
|
||||||
* <p>getThemeDeck.</p>
|
* <p>getThemeDeck.</p>
|
||||||
*
|
*
|
||||||
* @param ThemeName a {@link java.lang.String} object.
|
* @param themeName a {@link java.lang.String} object.
|
||||||
* @param Size a int.
|
* @param size a int.
|
||||||
* @return a {@link forge.CardList} object.
|
* @return a {@link forge.CardList} object.
|
||||||
*/
|
*/
|
||||||
public CardList getThemeDeck(String ThemeName, int Size) {
|
public CardList getThemeDeck(final String themeName, final int size) {
|
||||||
CardList tDeck = new CardList();
|
CardList tDeck = new CardList();
|
||||||
|
|
||||||
ArrayList<Grp> Groups = new ArrayList<Grp>();
|
ArrayList<Grp> groups = new ArrayList<Grp>();
|
||||||
|
|
||||||
Map<String, Integer> CardCounts = new HashMap<String, Integer>();
|
Map<String, Integer> cardCounts = new HashMap<String, Integer>();
|
||||||
|
|
||||||
String s = "";
|
String s = "";
|
||||||
int BLandPercentage = 0;
|
int bLandPercentage = 0;
|
||||||
boolean Testing = false;
|
boolean testing = false;
|
||||||
|
|
||||||
// read theme file
|
// read theme file
|
||||||
String tFileName = "res/quest/themes/" + ThemeName + ".thm";
|
String tFileName = "res/quest/themes/" + themeName + ".thm";
|
||||||
File tFile = new File(tFileName);
|
File tFile = new File(tFileName);
|
||||||
if (!tFile.exists())
|
if (!tFile.exists()) {
|
||||||
throw new RuntimeException("GenerateThemeDeck : getThemeDeck -- file not found -- filename is " + tFile.getAbsolutePath());
|
throw new RuntimeException("GenerateThemeDeck : getThemeDeck -- file not found -- filename is "
|
||||||
|
+ tFile.getAbsolutePath());
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
in = new BufferedReader(new FileReader(tFile));
|
in = new BufferedReader(new FileReader(tFile));
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
ErrorViewer.showError(ex, "File \"%s\" exception", tFile.getAbsolutePath());
|
ErrorViewer.showError(ex, "File \"%s\" exception", tFile.getAbsolutePath());
|
||||||
throw new RuntimeException("GenerateThemeDeck : getThemeDeck -- file exception -- filename is " + tFile.getPath());
|
throw new RuntimeException("GenerateThemeDeck : getThemeDeck -- file exception -- filename is "
|
||||||
|
+ tFile.getPath());
|
||||||
}
|
}
|
||||||
|
|
||||||
s = readLine();
|
s = readLine();
|
||||||
while (!s.equals("End")) {
|
while (!s.equals("End")) {
|
||||||
if (s.startsWith("[Group")) {
|
if (s.startsWith("[Group")) {
|
||||||
Grp G = new Grp();
|
Grp g = new Grp();
|
||||||
|
|
||||||
String ss[] = s.replaceAll("[\\[\\]]", "").split(" ");
|
String[] ss = s.replaceAll("[\\[\\]]", "").split(" ");
|
||||||
for (int i = 0; i < ss.length; i++) {
|
for (int i = 0; i < ss.length; i++) {
|
||||||
if (ss[i].startsWith("Percentage")) {
|
if (ss[i].startsWith("Percentage")) {
|
||||||
String p = ss[i].substring("Percentage".length() + 1);
|
String p = ss[i].substring("Percentage".length() + 1);
|
||||||
G.Percentage = Integer.parseInt(p);
|
g.Percentage = Integer.parseInt(p);
|
||||||
}
|
}
|
||||||
if (ss[i].startsWith("MaxCnt")) {
|
if (ss[i].startsWith("MaxCnt")) {
|
||||||
String m = ss[i].substring("MaxCnt".length() + 1);
|
String m = ss[i].substring("MaxCnt".length() + 1);
|
||||||
G.MaxCnt = Integer.parseInt(m);
|
g.MaxCnt = Integer.parseInt(m);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
s = readLine();
|
s = readLine();
|
||||||
while (!s.equals("[/Group]")) {
|
while (!s.equals("[/Group]")) {
|
||||||
G.Cardnames.add(s);
|
g.Cardnames.add(s);
|
||||||
CardCounts.put(s, 0);
|
cardCounts.put(s, 0);
|
||||||
|
|
||||||
s = readLine();
|
s = readLine();
|
||||||
}
|
}
|
||||||
|
|
||||||
Groups.add(G);
|
groups.add(g);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (s.startsWith("BasicLandPercentage"))
|
if (s.startsWith("BasicLandPercentage")) {
|
||||||
BLandPercentage = Integer.parseInt(s.substring("BasicLandPercentage".length() + 1));
|
bLandPercentage = Integer.parseInt(s.substring("BasicLandPercentage".length() + 1));
|
||||||
|
}
|
||||||
|
|
||||||
if (s.equals("Testing"))
|
if (s.equals("Testing")) {
|
||||||
Testing = true;
|
testing = true;
|
||||||
|
}
|
||||||
|
|
||||||
s = readLine();
|
s = readLine();
|
||||||
}
|
}
|
||||||
@@ -130,7 +138,8 @@ public class GenerateThemeDeck {
|
|||||||
in.close();
|
in.close();
|
||||||
} catch (IOException ex) {
|
} catch (IOException ex) {
|
||||||
ErrorViewer.showError(ex, "File \"%s\" exception", tFile.getAbsolutePath());
|
ErrorViewer.showError(ex, "File \"%s\" exception", tFile.getAbsolutePath());
|
||||||
throw new RuntimeException("GenerateThemeDeck : getThemeDeck -- file exception -- filename is " + tFile.getPath());
|
throw new RuntimeException("GenerateThemeDeck : getThemeDeck -- file exception -- filename is "
|
||||||
|
+ tFile.getPath());
|
||||||
}
|
}
|
||||||
|
|
||||||
String tmpDeck = "";
|
String tmpDeck = "";
|
||||||
@@ -138,116 +147,122 @@ public class GenerateThemeDeck {
|
|||||||
// begin assigning cards to the deck
|
// begin assigning cards to the deck
|
||||||
Random r = MyRandom.random;
|
Random r = MyRandom.random;
|
||||||
|
|
||||||
for (int i = 0; i < Groups.size(); i++) {
|
for (int i = 0; i < groups.size(); i++) {
|
||||||
Grp G = Groups.get(i);
|
Grp g = groups.get(i);
|
||||||
float p = (float) ((float) G.Percentage * .01);
|
float p = (float) ((float) g.Percentage * .01);
|
||||||
int GrpCnt = (int) (p * (float) Size);
|
int grpCnt = (int) (p * (float) size);
|
||||||
int cnSize = G.Cardnames.size();
|
int cnSize = g.Cardnames.size();
|
||||||
tmpDeck += "Group" + i + ":" + GrpCnt + "\n";
|
tmpDeck += "Group" + i + ":" + grpCnt + "\n";
|
||||||
|
|
||||||
for (int j = 0; j < GrpCnt; j++) {
|
for (int j = 0; j < grpCnt; j++) {
|
||||||
s = G.Cardnames.get(r.nextInt(cnSize));
|
s = g.Cardnames.get(r.nextInt(cnSize));
|
||||||
|
|
||||||
int lc = 0;
|
int lc = 0;
|
||||||
while (CardCounts.get(s) >= G.MaxCnt || lc > Size) // don't keep looping forever
|
while (cardCounts.get(s) >= g.MaxCnt || lc > size) // don't keep looping forever
|
||||||
{
|
{
|
||||||
s = G.Cardnames.get(r.nextInt(cnSize));
|
s = g.Cardnames.get(r.nextInt(cnSize));
|
||||||
lc++;
|
lc++;
|
||||||
}
|
}
|
||||||
if (lc > Size)
|
if (lc > size) {
|
||||||
throw new RuntimeException("GenerateThemeDeck : getThemeDeck -- looped too much -- filename is " + tFile.getAbsolutePath());
|
throw new RuntimeException("GenerateThemeDeck : getThemeDeck -- looped too much -- filename is "
|
||||||
|
+ tFile.getAbsolutePath());
|
||||||
|
}
|
||||||
|
|
||||||
int n = CardCounts.get(s);
|
int n = cardCounts.get(s);
|
||||||
tDeck.add(AllZone.getCardFactory().getCard(s, AllZone.getComputerPlayer()));
|
tDeck.add(AllZone.getCardFactory().getCard(s, AllZone.getComputerPlayer()));
|
||||||
CardCounts.put(s, n + 1);
|
cardCounts.put(s, n + 1);
|
||||||
tmpDeck += s + "\n";
|
tmpDeck += s + "\n";
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int numBLands = 0;
|
int numBLands = 0;
|
||||||
if (BLandPercentage > 0) // if theme explicitly defines this
|
if (bLandPercentage > 0) { // if theme explicitly defines this
|
||||||
{
|
float p = (float) ((float) bLandPercentage * .01);
|
||||||
float p = (float) ((float) BLandPercentage * .01);
|
numBLands = (int) (p * (float) size);
|
||||||
numBLands = (int) (p * (float) Size);
|
} else { // otherwise, just fill in the rest of the deck with basic lands
|
||||||
} else // otherwise, just fill in the rest of the deck with basic lands
|
numBLands = size - tDeck.size();
|
||||||
numBLands = Size - tDeck.size();
|
}
|
||||||
|
|
||||||
tmpDeck += "numBLands:" + numBLands + "\n";
|
tmpDeck += "numBLands:" + numBLands + "\n";
|
||||||
|
|
||||||
if (numBLands > 0) // attempt to optimize basic land counts according to color representation
|
if (numBLands > 0) // attempt to optimize basic land counts according to color representation
|
||||||
{
|
{
|
||||||
CCnt ClrCnts[] = {new CCnt("Plains", 0),
|
CCnt[] clrCnts = {new CCnt("Plains", 0),
|
||||||
new CCnt("Island", 0),
|
new CCnt("Island", 0),
|
||||||
new CCnt("Swamp", 0),
|
new CCnt("Swamp", 0),
|
||||||
new CCnt("Mountain", 0),
|
new CCnt("Mountain", 0),
|
||||||
new CCnt("Forest", 0)};
|
new CCnt("Forest", 0)};
|
||||||
|
|
||||||
// count each instance of a color in mana costs
|
// count each instance of a color in mana costs
|
||||||
// TODO: count hybrid mana differently?
|
// TODO count hybrid mana differently?
|
||||||
for (int i = 0; i < tDeck.size(); i++) {
|
for (int i = 0; i < tDeck.size(); i++) {
|
||||||
String mc = tDeck.get(i).getManaCost();
|
String mc = tDeck.get(i).getManaCost();
|
||||||
|
|
||||||
for (int j = 0; j < mc.length(); j++) {
|
for (int j = 0; j < mc.length(); j++) {
|
||||||
char c = mc.charAt(j);
|
char c = mc.charAt(j);
|
||||||
|
|
||||||
if (c == 'W')
|
if (c == 'W') {
|
||||||
ClrCnts[0].Count++;
|
clrCnts[0].Count++;
|
||||||
else if (c == 'U')
|
} else if (c == 'U') {
|
||||||
ClrCnts[1].Count++;
|
clrCnts[1].Count++;
|
||||||
else if (c == 'B')
|
} else if (c == 'B') {
|
||||||
ClrCnts[2].Count++;
|
clrCnts[2].Count++;
|
||||||
else if (c == 'R')
|
} else if (c == 'R') {
|
||||||
ClrCnts[3].Count++;
|
clrCnts[3].Count++;
|
||||||
else if (c == 'G')
|
} else if (c == 'G') {
|
||||||
ClrCnts[4].Count++;
|
clrCnts[4].Count++;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int totalColor = 0;
|
int totalColor = 0;
|
||||||
for (int i = 0; i < 5; i++) {
|
for (int i = 0; i < 5; i++) {
|
||||||
totalColor += ClrCnts[i].Count;
|
totalColor += clrCnts[i].Count;
|
||||||
tmpDeck += ClrCnts[i].Color + ":" + ClrCnts[i].Count + "\n";
|
tmpDeck += clrCnts[i].Color + ":" + clrCnts[i].Count + "\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
tmpDeck += "totalColor:" + totalColor + "\n";
|
tmpDeck += "totalColor:" + totalColor + "\n";
|
||||||
|
|
||||||
for (int i = 0; i < 5; i++) {
|
for (int i = 0; i < 5; i++) {
|
||||||
if (ClrCnts[i].Count > 0) { // calculate number of lands for each color
|
if (clrCnts[i].Count > 0) { // calculate number of lands for each color
|
||||||
float p = (float) ClrCnts[i].Count / (float) totalColor;
|
float p = (float) clrCnts[i].Count / (float) totalColor;
|
||||||
int nLand = (int) ((float) numBLands * p);
|
int nLand = (int) ((float) numBLands * p);
|
||||||
tmpDeck += "numLand-" + ClrCnts[i].Color + ":" + nLand + "\n";
|
tmpDeck += "numLand-" + clrCnts[i].Color + ":" + nLand + "\n";
|
||||||
|
|
||||||
CardCounts.put(ClrCnts[i].Color, 2);
|
cardCounts.put(clrCnts[i].Color, 2);
|
||||||
for (int j = 0; j < nLand; j++)
|
for (int j = 0; j < nLand; j++) {
|
||||||
tDeck.add(AllZone.getCardFactory().getCard(ClrCnts[i].Color, AllZone.getComputerPlayer()));
|
tDeck.add(AllZone.getCardFactory().getCard(clrCnts[i].Color, AllZone.getComputerPlayer()));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
tmpDeck += "DeckSize:" + tDeck.size() + "\n";
|
tmpDeck += "DeckSize:" + tDeck.size() + "\n";
|
||||||
|
|
||||||
if (tDeck.size() < Size) {
|
if (tDeck.size() < size) {
|
||||||
int diff = Size - tDeck.size();
|
int diff = size - tDeck.size();
|
||||||
|
|
||||||
for (int i = 0; i < diff; i++) {
|
for (int i = 0; i < diff; i++) {
|
||||||
s = tDeck.get(r.nextInt(tDeck.size())).getName();
|
s = tDeck.get(r.nextInt(tDeck.size())).getName();
|
||||||
|
|
||||||
while (CardCounts.get(s) >= 4)
|
while (cardCounts.get(s) >= 4) {
|
||||||
s = tDeck.get(r.nextInt(tDeck.size())).getName();
|
s = tDeck.get(r.nextInt(tDeck.size())).getName();
|
||||||
|
}
|
||||||
|
|
||||||
int n = CardCounts.get(s);
|
int n = cardCounts.get(s);
|
||||||
tDeck.add(AllZone.getCardFactory().getCard(s, AllZone.getComputerPlayer()));
|
tDeck.add(AllZone.getCardFactory().getCard(s, AllZone.getComputerPlayer()));
|
||||||
CardCounts.put(s, n + 1);
|
cardCounts.put(s, n + 1);
|
||||||
tmpDeck += "Added:" + s + "\n";
|
tmpDeck += "Added:" + s + "\n";
|
||||||
}
|
}
|
||||||
} else if (tDeck.size() > Size) {
|
} else if (tDeck.size() > size) {
|
||||||
int diff = tDeck.size() - Size;
|
int diff = tDeck.size() - size;
|
||||||
|
|
||||||
for (int i = 0; i < diff; i++) {
|
for (int i = 0; i < diff; i++) {
|
||||||
Card c = tDeck.get(r.nextInt(tDeck.size()));
|
Card c = tDeck.get(r.nextInt(tDeck.size()));
|
||||||
|
|
||||||
while (c.isBasicLand())
|
while (c.isBasicLand()) {
|
||||||
c = tDeck.get(r.nextInt(tDeck.size()));
|
c = tDeck.get(r.nextInt(tDeck.size()));
|
||||||
|
}
|
||||||
|
|
||||||
tDeck.remove(c);
|
tDeck.remove(c);
|
||||||
tmpDeck += "Removed:" + s + "\n";
|
tmpDeck += "Removed:" + s + "\n";
|
||||||
@@ -255,8 +270,9 @@ public class GenerateThemeDeck {
|
|||||||
}
|
}
|
||||||
|
|
||||||
tmpDeck += "DeckSize:" + tDeck.size() + "\n";
|
tmpDeck += "DeckSize:" + tDeck.size() + "\n";
|
||||||
if (Testing)
|
if (testing) {
|
||||||
ErrorViewer.showError(tmpDeck);
|
ErrorViewer.showError(tmpDeck);
|
||||||
|
}
|
||||||
|
|
||||||
return tDeck;
|
return tDeck;
|
||||||
}
|
}
|
||||||
@@ -270,14 +286,21 @@ public class GenerateThemeDeck {
|
|||||||
//makes the checked exception, into an unchecked runtime exception
|
//makes the checked exception, into an unchecked runtime exception
|
||||||
try {
|
try {
|
||||||
String s = in.readLine();
|
String s = in.readLine();
|
||||||
if (s != null) s = s.trim();
|
if (s != null) {
|
||||||
|
s = s.trim();
|
||||||
|
}
|
||||||
return s;
|
return s;
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
ErrorViewer.showError(ex);
|
ErrorViewer.showError(ex);
|
||||||
throw new RuntimeException("GenerateThemeDeck : readLine error");
|
throw new RuntimeException("GenerateThemeDeck : readLine error");
|
||||||
}
|
}
|
||||||
}//readLine(Card)
|
} //readLine(Card)
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* TODO Write javadoc for this type.
|
||||||
|
*
|
||||||
|
*/
|
||||||
class CCnt {
|
class CCnt {
|
||||||
public String Color;
|
public String Color;
|
||||||
public int Count;
|
public int Count;
|
||||||
@@ -288,6 +311,11 @@ public class GenerateThemeDeck {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* TODO Write javadoc for this type.
|
||||||
|
*
|
||||||
|
*/
|
||||||
class Grp {
|
class Grp {
|
||||||
public ArrayList<String> Cardnames = new ArrayList<String>();
|
public ArrayList<String> Cardnames = new ArrayList<String>();
|
||||||
public int MaxCnt;
|
public int MaxCnt;
|
||||||
|
|||||||
Reference in New Issue
Block a user