- Added CardShop.

This commit is contained in:
jendave
2011-08-06 03:44:30 +00:00
parent 78521f3849
commit 2cac78c2a1
16 changed files with 4001 additions and 25 deletions

4
.gitattributes vendored
View File

@@ -58,6 +58,7 @@ res/quest/common.txt -text svneol=native#text/plain
res/quest/easy.txt -text svneol=native#text/plain res/quest/easy.txt -text svneol=native#text/plain
res/quest/hard.txt -text svneol=native#text/plain res/quest/hard.txt -text svneol=native#text/plain
res/quest/medium.txt -text svneol=native#text/plain res/quest/medium.txt -text svneol=native#text/plain
res/quest/price.txt -text svneol=native#text/plain
res/quest/quest.properties svneol=native#text/plain res/quest/quest.properties svneol=native#text/plain
res/quest/questData -text svneol=unset#unset res/quest/questData -text svneol=unset#unset
res/quest/rare.txt -text svneol=native#text/plain res/quest/rare.txt -text svneol=native#text/plain
@@ -99,6 +100,7 @@ src/forge/CardFilter.java -text svneol=native#text/plain
src/forge/CardList.java svneol=native#text/plain src/forge/CardList.java svneol=native#text/plain
src/forge/CardListFilter.java svneol=native#text/plain src/forge/CardListFilter.java svneol=native#text/plain
src/forge/CardListUtil.java svneol=native#text/plain src/forge/CardListUtil.java svneol=native#text/plain
src/forge/CardShopTableModel.java -text svneol=native#text/plain
src/forge/CardUtil.java svneol=native#text/plain src/forge/CardUtil.java svneol=native#text/plain
src/forge/Combat.java svneol=native#text/plain src/forge/Combat.java svneol=native#text/plain
src/forge/CombatPlaneswalker.java svneol=native#text/plain src/forge/CombatPlaneswalker.java svneol=native#text/plain
@@ -153,6 +155,7 @@ src/forge/GuiDisplay3.java -text svneol=native#text/plain
src/forge/GuiDisplayUtil.java svneol=native#text/plain src/forge/GuiDisplayUtil.java svneol=native#text/plain
src/forge/GuiInput.java svneol=native#text/plain src/forge/GuiInput.java svneol=native#text/plain
src/forge/Gui_BoosterDraft.java svneol=native#text/plain src/forge/Gui_BoosterDraft.java svneol=native#text/plain
src/forge/Gui_CardShop.java -text svneol=native#text/plain
src/forge/Gui_DeckEditor.java -text svneol=native#text/plain src/forge/Gui_DeckEditor.java -text svneol=native#text/plain
src/forge/Gui_DeckEditorNew.java -text svneol=native#text/plain src/forge/Gui_DeckEditorNew.java -text svneol=native#text/plain
src/forge/Gui_DeckEditor_Menu.java svneol=native#text/plain src/forge/Gui_DeckEditor_Menu.java svneol=native#text/plain
@@ -233,6 +236,7 @@ src/forge/QuestData_BoosterPack.java svneol=native#text/plain
src/forge/QuestData_State.java svneol=native#text/plain src/forge/QuestData_State.java svneol=native#text/plain
src/forge/ReadBoosterPack.java svneol=native#text/plain src/forge/ReadBoosterPack.java svneol=native#text/plain
src/forge/ReadCard.java svneol=native#text/plain src/forge/ReadCard.java svneol=native#text/plain
src/forge/ReadPriceList.java -text svneol=native#text/plain
src/forge/Run.java svneol=native#text/plain src/forge/Run.java svneol=native#text/plain
src/forge/RunTest.java svneol=native#text/plain src/forge/RunTest.java svneol=native#text/plain
src/forge/SimpleCombat.java svneol=native#text/plain src/forge/SimpleCombat.java svneol=native#text/plain

2851
res/quest/price.txt Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -2,6 +2,8 @@ common--file=common.txt
uncommon--file=uncommon.txt uncommon--file=uncommon.txt
rare--file=rare.txt rare--file=rare.txt
price--file=price.txt
easy--file=easy.txt easy--file=easy.txt
medium--file=medium.txt medium--file=medium.txt
hard--file=hard.txt hard--file=hard.txt

Binary file not shown.

View File

@@ -23,9 +23,10 @@ public class QuestData_State implements Serializable {
private static final long serialVersionUID = 7007940230351051937L; private static final long serialVersionUID = 7007940230351051937L;
int rankIndex, win, lost; int rankIndex, win, lost;
long credits;
String difficulty; String difficulty;
ArrayList<String> cardPool; ArrayList<String> cardPool, shopList;
HashMap<String, Deck> myDecks, aiDecks; HashMap<String, Deck> myDecks, aiDecks;
private Object readResolve() throws ObjectStreamException { private Object readResolve() throws ObjectStreamException {
@@ -39,6 +40,6 @@ public class QuestData_State implements Serializable {
for(Entry<String, Deck> deck:this.aiDecks.entrySet()) { for(Entry<String, Deck> deck:this.aiDecks.entrySet()) {
aiDecks.put(deck.getKey(), deck.getValue().migrate()); aiDecks.put(deck.getKey(), deck.getValue().migrate());
} }
return new forge.QuestData_State(rankIndex, win, lost, difficulty, cardPool, myDecks, aiDecks); return new forge.QuestData_State(rankIndex, win, lost, credits, difficulty, cardPool, shopList, myDecks, aiDecks);
} }
} }

View File

@@ -14,6 +14,8 @@ public class Card extends MyObservable {
private static int nextUniqueNumber; private static int nextUniqueNumber;
private int uniqueNumber = nextUniqueNumber++; private int uniqueNumber = nextUniqueNumber++;
private long value;
//private Collection keyword = new TreeSet(); //private Collection keyword = new TreeSet();
//private ArrayList<String> keyword = new ArrayList<String>(); //private ArrayList<String> keyword = new ArrayList<String>();
@@ -1466,6 +1468,15 @@ public class Card extends MyObservable {
return uniqueNumber; return uniqueNumber;
} }
public void setValue(long n)
{
value = n;
}
public long getValue()
{
return value;
}
@Override @Override
public boolean equals(Object o) { public boolean equals(Object o) {
if(o instanceof Card) { if(o instanceof Card) {

View File

@@ -0,0 +1,305 @@
package forge;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.util.Arrays;
import javax.swing.JTable;
import javax.swing.table.AbstractTableModel;
import javax.swing.table.TableColumn;
import javax.swing.table.TableColumnModel;
class CardShopTableModel extends AbstractTableModel {
private static final long serialVersionUID = 1L;
//holds 1 copy of each card, DOES NOT HOLD multiple cards with the same name
private CardList dataNoCopies = new CardList();
//holds multiple card
//example: if there are 4 Elvish Pipers, dataNoCopies has 1 copy, and dataCopies has 3
private CardList dataCopies = new CardList();
//used by sort(), holds old data to compare with sorted data, to see if any change was made
//private CardList oldList = new CardList();
private CardContainer cardDetail;
private String column[] = {"Qty", "Name", "Cost", "Color", "Type", "Stats", "R", "Value"};
//used to resort(), used when addCard(Card) is called
private int recentSortedColumn;
private boolean recentAscending;
public CardShopTableModel(CardContainer cd) {
this(new CardList(), cd);
}
public CardShopTableModel(CardList inData, CardContainer in_cardDetail) {
cardDetail = in_cardDetail;
//intialize dataNoCopies and dataCopies
addCard(inData);
}
public void resizeCols(final JTable table) {
TableColumn column = null;
for(int i = 0; i < table.getColumnCount(); i++) {
column = table.getColumnModel().getColumn(i);
if(i == 0) {
column.setPreferredWidth(25); //make first column small
column.setMaxWidth(25);
} else if(i == 1) {
column.setPreferredWidth(190);
column.setMinWidth(190);
column.setMaxWidth(190);
} else if(i == 2) {
column.setPreferredWidth(85);
column.setMinWidth(85);
column.setMaxWidth(126);
} else if(i == 3) {
column.setPreferredWidth(58);
column.setMaxWidth(58);
} else if(i == 4) column.setPreferredWidth(130);
else if(i == 5) {
column.setPreferredWidth(32);
column.setMaxWidth(42);
} else if(i == 6) {
column.setPreferredWidth(20);
column.setMaxWidth(20);
} else if(i == 7) {
column.setPreferredWidth(40);
column.setMaxWidth(40);
}
}//for
for(int j = 0; j < table.getColumnCount(); j++) {
column = table.getColumnModel().getColumn(j);
//System.out.println("col Width:" + column.getPreferredWidth());
}
}
public void clear() {
dataNoCopies.clear();
dataCopies.clear();
//fireTableDataChanged();
}
public CardList getCards() {
CardList all = new CardList();
all.addAll(dataCopies.toArray());
all.addAll(dataNoCopies.toArray());
return all;
}
public void removeCard(Card c) {
//remove card from "dataCopies",
//if not found there, remove card from "dataNoCopies"
int index = findCardName(c.getName(), dataCopies);
if(index != -1) //found card name
dataCopies.remove(index);
else {
index = findCardName(c.getName(), dataNoCopies);
dataNoCopies.remove(index);
}
fireTableDataChanged();
}
private int findCardName(String name, CardList list) {
for(int i = 0; i < list.size(); i++)
if(list.get(i).getName().equals(name)) return i;
return -1;
}
public void addCard(Card c) {
if(0 == countQuantity(c, dataNoCopies)) dataNoCopies.add(c);
else dataCopies.add(c);
}
public void addCard(CardList c) {
for(int i = 0; i < c.size(); i++)
addCard(c.get(i));
fireTableDataChanged();
}
public Card rowToCard(int row) {
return dataNoCopies.get(row);
}
private int countQuantity(Card c) {
return countQuantity(c, dataNoCopies) + countQuantity(c, dataCopies);
}
//CardList data is either class members "dataNoCopies" or "dataCopies"
private int countQuantity(Card c, CardList data) {
int count = 0;
for(int i = 0; i < data.size(); i++)
//are the card names the same?
if(data.get(i).getName().equals(c.getName())) count++;
return count;
}
public int getRowCount() {
return dataNoCopies.size();
}
public int getColumnCount() {
return column.length;
}
@Override
public String getColumnName(int n) {
return column[n];
}
public Object getValueAt(int row, int column) {
return getColumn(dataNoCopies.get(row), column);
}
private Object getColumn(Card c, int column) {
switch(column) {
case 0:
return Integer.valueOf(countQuantity(c));
case 1:
return c.getName();
case 2:
return c.getManaCost();
case 3:
return TableSorter.getColor(c);
case 4:
return GuiDisplayUtil.formatCardType(c);
case 5:
return c.isCreature()? c.getBaseAttack() + "/" + c.getBaseDefense():"";
case 6:
String rarity = c.getRarity();
if(rarity.length() > 0) rarity = rarity.substring(0, 1);
return rarity;
case 7:
long value = c.getValue();
return value;
default:
return "error";
}
}
public void addListeners(final JTable table) {
//updates card detail, listens to any key strokes
table.addKeyListener(new KeyListener() {
public void keyPressed(KeyEvent ev) {}
public void keyTyped(KeyEvent ev) {}
public void keyReleased(KeyEvent ev) {
int row = table.getSelectedRow();
if(row != -1) {
cardDetail.setCard(dataNoCopies.get(row));
}
}
});
//updates card detail, listens to any mouse clicks
table.addMouseListener(new MouseAdapter() {
@Override
public void mousePressed(MouseEvent e) {
int row = table.getSelectedRow();
if(row != -1) {
cardDetail.setCard(dataNoCopies.get(row));
}
}
});
//sorts
MouseListener mouse = new MouseAdapter() {
@Override
public void mousePressed(MouseEvent e) {
TableColumnModel columnModel = table.getColumnModel();
int viewColumn = columnModel.getColumnIndexAtX(e.getX());
int column = table.convertColumnIndexToModel(viewColumn);
if(column != -1) {
//sort ascending
@SuppressWarnings("unused")
boolean change = sort(column, true);
//if(! change)
// sort(column, false);//sort descending
//fireTableDataChanged();
}
}//mousePressed()
};//MouseListener
table.getTableHeader().addMouseListener(mouse);
}//addCardListener()
//called by the GUI when a card is added to re-sort
public void resort() {
sort(recentSortedColumn, recentAscending);
//this.fireTableDataChanged();
}
//returns true if any data changed positions
// @SuppressWarnings("unchecked")
// Arrays.sort
public boolean sort(int column, boolean ascending) {
//used by addCard() to resort the cards
recentSortedColumn = column;
recentAscending = ascending;
CardList all = new CardList();
all.addAll(dataNoCopies.toArray());
all.addAll(dataCopies.toArray());
TableSorter sorter = new TableSorter(all, column, ascending);
Card[] array = all.toArray();
Arrays.sort(array, sorter);
/*
//determine if any data changed position
boolean hasChanged = false;
CardList check = removeDuplicateNames(array);
for(int i = 0; i < check.size(); i++)
//do the card names match?
if(! check.get(i).getName().equals(dataNoCopies.get(i).getName()))
hasChanged = true;
*/
//clear everything, and add sorted data back into the model
dataNoCopies.clear();
dataCopies.clear();
addCard(new CardList(array));
//this value doesn't seem to matter:
//return hasChanged;
return true;
}//sort()
/*
private CardList removeDuplicateNames(Card[] c)
{
TreeSet check = new TreeSet();
CardList list = new CardList();
for(int i = 0; i < c.length; i++)
{
if(! check.contains(c[i].getName()))
{
check.add(c[i].getName());
list.add(c[i]);
}
}
return list;
}
*/
}//CardTableModel

558
src/forge/Gui_CardShop.java Normal file
View File

@@ -0,0 +1,558 @@
package forge;
import java.awt.Color;
import java.awt.Component;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.GridLayout;
import java.awt.Image;
import java.awt.Point;
import java.awt.Rectangle;
import java.awt.event.ActionEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.text.DecimalFormat;
import java.text.NumberFormat;
import java.util.ArrayList;
import java.util.Map;
import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.SwingUtilities;
import javax.swing.border.Border;
import javax.swing.border.EtchedBorder;
import javax.swing.border.TitledBorder;
import javax.swing.event.MouseInputListener;
import forge.error.ErrorViewer;
import forge.gui.game.CardDetailPanel;
import forge.gui.game.CardPicturePanel;
import forge.properties.NewConstants;
public class Gui_CardShop extends JFrame implements CardContainer, DeckDisplay, NewConstants {
private static final long serialVersionUID = 3988857075791576483L;
Gui_DeckEditor_Menu customMenu;
//private ImageIcon upIcon = Constant.IO.upIcon;
//private ImageIcon downIcon = Constant.IO.downIcon;
private CardShopTableModel topModel;
private CardShopTableModel bottomModel;
private JScrollPane jScrollPane1 = new JScrollPane();
private JScrollPane jScrollPane2 = new JScrollPane();
private JButton sellButton = new JButton();
@SuppressWarnings("unused")
// border1
private Border border1;
private TitledBorder titledBorder1;
private Border border2;
private TitledBorder titledBorder2;
private JButton buyButton = new JButton();
private JTable topTable = new JTable();
private JTable bottomTable = new JTable();
private JScrollPane jScrollPane3 = new JScrollPane();
private JPanel jPanel3 = new JPanel();
private GridLayout gridLayout1 = new GridLayout();
private JLabel creditsLabel = new JLabel();
private JLabel jLabel1 = new JLabel();
private JLabel sellPercentageLabel = new JLabel();
private double multi;
private CardList top;
private CardList bottom;
public Card cCardHQ;
private CardDetailPanel detail = new CardDetailPanel(null);
private CardPicturePanel picture = new CardPicturePanel(null);
private JPanel glassPane;
private QuestData questData;
@Override
public void setTitle(String message) {
super.setTitle(message);
}
public void updateDisplay(CardList top, CardList bottom) {
this.top = top;
this.bottom = bottom;
topModel.clear();
bottomModel.clear();
if(AllZone.NameChanger.shouldChangeCardName()) {
top = new CardList(AllZone.NameChanger.changeCard(top.toArray()));
bottom = new CardList(AllZone.NameChanger.changeCard(bottom.toArray()));
}
Card c;
String cardName;
ReadBoosterPack pack = new ReadBoosterPack();
// update top
for(int i = 0; i < top.size(); i++) {
c = top.get(i);
// add rarity to card if this is a sealed card pool
cardName = AllZone.NameChanger.getOriginalName(c.getName());
if(!pack.getRarity(cardName).equals("error")) {
c.setRarity(pack.getRarity(cardName));
}
topModel.addCard(c);
}// for
// update bottom
for(int i = 0; i < bottom.size(); i++) {
c = bottom.get(i);
// add rarity to card if this is a sealed card pool
if(!customMenu.getGameType().equals(Constant.GameType.Constructed)) c.setRarity(pack.getRarity(c.getName()));
bottomModel.addCard(c);
}// for
topModel.resort();
bottomModel.resort();
}// updateDisplay
public void updateDisplay() {
//updateDisplay(this.top, this.bottom);
topModel.clear();
if(AllZone.NameChanger.shouldChangeCardName()) {
top = new CardList(AllZone.NameChanger.changeCard(top.toArray()));
bottom = new CardList(AllZone.NameChanger.changeCard(bottom.toArray()));
}
Card c;
String cardName;
ReadBoosterPack pack = new ReadBoosterPack();
// update top
for(int i = 0; i < top.size(); i++) {
c = top.get(i);
// add rarity to card if this is a sealed card pool
cardName = AllZone.NameChanger.getOriginalName(c.getName());
if(!pack.getRarity(cardName).equals("error")) {
c.setRarity(pack.getRarity(cardName));
}
topModel.addCard(c);
}// for
topModel.resort();
}
public CardShopTableModel getTopTableModel() {
return topModel;
}
public CardList getTop() {
return topModel.getCards();
}
//bottom shows cards that the user has chosen for his library
public CardList getBottom() {
return bottomModel.getCards();
}
public void show(final Command exitCommand) {
final Command exit = new Command() {
private static final long serialVersionUID = 5210924838133689758L;
public void execute() {
Gui_CardShop.this.dispose();
exitCommand.execute();
}
};
customMenu = new Gui_DeckEditor_Menu(this, exit);
customMenu.setTitle("Card Shop");
//this.setJMenuBar(customMenu);
//do not change this!!!!
this.addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent ev) {
customMenu.close();
}
});
setup();
//show cards, makes this user friendly
//customMenu.newConstructed();
//get pricelist:
ReadPriceList r = new ReadPriceList();
Map<String,Long> map = r.getPriceList();
ReadBoosterPack pack = new ReadBoosterPack();
CardList shop;
if (questData.getShopList().size() == 0)
{
shop = pack.getShopCards(questData.getWin());
ArrayList<String> shopListToBeSaved = new ArrayList<String>();
for (int i = 0; i <shop.size();i++)
{
Card crd = shop.get(i);
crd.setValue(map.get(crd.getName()));
shopListToBeSaved.add(crd.getName());
}
questData.setShopList(shopListToBeSaved);
}
else //grab existing shopList
{
ArrayList<String> shopList = questData.getShopList();
shop = new CardList();
for(int i = 0; i < shopList.size(); i++) {
Card c = AllZone.CardFactory.getCard(shopList.get(i).toString(), "");
c.setValue(map.get(c.getName()));
c.setRarity(pack.getRarity(c.getName()));
shop.add(c);
}
}
ArrayList<String> list = questData.getCardpool();
CardList owned = new CardList();
for(int i = 0; i < list.size(); i++) {
Card c = AllZone.CardFactory.getCard(list.get(i).toString(), "");
c.setValue(map.get(c.getName()));
c.setRarity(pack.getRarity(c.getName()));
owned.add(c);
}
customMenu.populateShop(shop, owned);
double multiPercent = multi*100;
NumberFormat formatter = new DecimalFormat("#0.00");
sellPercentageLabel.setText("(Sell percentage: " + formatter.format(multiPercent) +"% of value)" );
topModel.sort(1, true);
bottomModel.sort(1, true);
}//show(Command)
private void addListeners() {
MouseInputListener l = new MouseInputListener() {
public void mouseReleased(MouseEvent e) {
redispatchMouseEvent(e);
}
public void mousePressed(MouseEvent e) {
redispatchMouseEvent(e);
}
public void mouseExited(MouseEvent e) {
redispatchMouseEvent(e);
}
public void mouseEntered(MouseEvent e) {
redispatchMouseEvent(e);
}
public void mouseClicked(MouseEvent e) {
redispatchMouseEvent(e);
}
public void mouseMoved(MouseEvent e) {
redispatchMouseEvent(e);
}
public void mouseDragged(MouseEvent e) {
redispatchMouseEvent(e);
}
private void redispatchMouseEvent(MouseEvent e) {
Container content = getContentPane();
Point glassPoint = e.getPoint();
Point contentPoint = SwingUtilities.convertPoint(glassPane, glassPoint, content);
Component component = SwingUtilities.getDeepestComponentAt(content, contentPoint.x, contentPoint.y);
if(component == null || !SwingUtilities.isDescendingFrom(component, picture)) {
glassPane.setVisible(false);
}
}
};
glassPane.addMouseMotionListener(l);
glassPane.addMouseListener(l);
picture.addMouseListener(new MouseAdapter() {
@Override
public void mouseEntered(MouseEvent e) {
Card c = picture.getCard();
if(c == null) return;
Image i = ImageCache.getOriginalImage(c);
if(i == null) return;
if(i.getWidth(null) < 300) return;
glassPane.setVisible(true);
}
});
}//addListeners()
private void setup() {
multi = 0.25 + (0.001 *questData.getWin());
if (multi > 0.6)
multi = 0.6;
addListeners();
//construct topTable, get all cards
topModel = new CardShopTableModel(new CardList(), this);
topModel.addListeners(topTable);
topTable.setModel(topModel);
topModel.resizeCols(topTable);
//construct bottomModel
bottomModel = new CardShopTableModel(this);
bottomModel.addListeners(bottomTable);
bottomTable.setModel(bottomModel);
topModel.resizeCols(bottomTable);
setSize(1024, 768);
this.setResizable(false);
Dimension screen = getToolkit().getScreenSize();
Rectangle bounds = getBounds();
bounds.width = 1024;
bounds.height = 768;
bounds.x = (screen.width - bounds.width) / 2;
bounds.y = (screen.height - bounds.height) / 2;
setBounds(bounds);
//TODO use this as soon the deck editor has resizable GUI
// //Use both so that when "un"maximizing, the frame isn't tiny
// setSize(1024, 740);
// setExtendedState(Frame.MAXIMIZED_BOTH);
}//setupAndDisplay()
public Gui_CardShop(QuestData qd) {
questData = qd;
try {
jbInit();
} catch(Exception ex) {
ErrorViewer.showError(ex);
}
}
public Card getCard() {
return detail.getCard();
}
public void setCard(Card card) {
detail.setCard(card);
picture.setCard(card);
}
private void jbInit() throws Exception {
border1 = new EtchedBorder(EtchedBorder.RAISED, Color.white, new Color(148, 145, 140));
titledBorder1 = new TitledBorder(BorderFactory.createEtchedBorder(Color.white, new Color(148, 145, 140)),
"All Cards");
border2 = BorderFactory.createEtchedBorder(Color.white, new Color(148, 145, 140));
titledBorder2 = new TitledBorder(border2, "Owned Cards");
this.getContentPane().setLayout(null);
jScrollPane1.setBorder(titledBorder1);
jScrollPane1.setBounds(new Rectangle(19, 20, 726, 346));
jScrollPane2.getViewport().setBackground(new Color(204, 204, 204));
jScrollPane2.setBorder(titledBorder2);
jScrollPane2.setBounds(new Rectangle(19, 458, 726, 218));
sellButton.setBounds(new Rectangle(180, 403, 146, 49));
//removeButton.setIcon(upIcon);
if(!Gui_NewGame.useLAFFonts.isSelected()) sellButton.setFont(new java.awt.Font("Dialog", 0, 13));
sellButton.setText("Sell Card");
sellButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(ActionEvent e) {
sellButton_actionPerformed(e);
}
});
buyButton.setText("Buy Card");
buyButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(ActionEvent e) {
buyButton_actionPerformed(e);
}
});
if(!Gui_NewGame.useLAFFonts.isSelected()) buyButton.setFont(new java.awt.Font("Dialog", 0, 13));
buyButton.setBounds(new Rectangle(23, 403, 146, 49));
detail.setBounds(new Rectangle(765, 23, 239, 323));
picture.setBounds(new Rectangle(765, 372, 239, 338));
picture.addMouseListener(new CustomListener());
//Do not lower statsLabel any lower, we want this to be visible at 1024 x 768 screen size
this.setTitle("Card Shop");
jScrollPane3.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
jScrollPane3.setBounds(new Rectangle(6, 168, 225, 143));
jPanel3.setBounds(new Rectangle(7, 21, 224, 141));
jPanel3.setLayout(gridLayout1);
gridLayout1.setColumns(1);
gridLayout1.setRows(0);
creditsLabel.setBounds(new Rectangle(19, 365, 720, 31));
creditsLabel.setText("Total credits: " + questData.getCredits());
if(!Gui_NewGame.useLAFFonts.isSelected()) creditsLabel.setFont(new java.awt.Font("Dialog", 0, 14));
sellPercentageLabel.setBounds(new Rectangle(350, 403, 250, 31));
sellPercentageLabel.setText("(Sell percentage: " + multi+")");
if(!Gui_NewGame.useLAFFonts.isSelected()) sellPercentageLabel.setFont(new java.awt.Font("Dialog", 0, 14));
jLabel1.setText("Click on the column name (like name or color) to sort the cards");
jLabel1.setBounds(new Rectangle(20, 1, 400, 19));
this.getContentPane().add(detail, null);
this.getContentPane().add(picture, null);
this.getContentPane().add(jScrollPane1, null);
this.getContentPane().add(jScrollPane2, null);
this.getContentPane().add(creditsLabel, null);
this.getContentPane().add(buyButton, null);
this.getContentPane().add(sellButton, null);
this.getContentPane().add(sellPercentageLabel, null);
this.getContentPane().add(jLabel1, null);
jScrollPane2.getViewport().add(bottomTable, null);
jScrollPane1.getViewport().add(topTable, null);
glassPane = new JPanel() {
private static final long serialVersionUID = 7394924497724994317L;
@Override
protected void paintComponent(java.awt.Graphics g) {
Image image = ImageCache.getOriginalImage(picture.getCard());
g.drawImage(image, glassPane.getWidth() - image.getWidth(null), glassPane.getHeight()
- image.getHeight(null), null);
}
};
setGlassPane(glassPane);
}
void buyButton_actionPerformed(ActionEvent e) {
int n = topTable.getSelectedRow();
if(n != -1) {
Card c = topModel.rowToCard(n);
if(c.getValue() <= questData.getCredits())
{
bottomModel.addCard(c);
bottomModel.resort();
topModel.removeCard(c);
questData.subtractCredits(c.getValue());
questData.addCard(c);
questData.removeCardFromShopList(c);
creditsLabel.setText("Total credits: " + questData.getCredits());
//3 conditions" 0 cards left, select the same row, select next row
int size = topModel.getRowCount();
if(size != 0) {
if(size == n) n--;
topTable.addRowSelectionInterval(n, n);
}
}
else
{
JOptionPane.showMessageDialog(null, "Not enough credits!");
}
}//if(valid row)
}//buyButton_actionPerformed
void sellButton_actionPerformed(ActionEvent e) {
int n = bottomTable.getSelectedRow();
if(n != -1) {
Card c = bottomModel.rowToCard(n);
bottomModel.removeCard(c);
topModel.addCard(c);
topModel.resort();
//bottomModel.removeCard(c);
questData.addCardToShopList(c);
questData.addCredits((long) (multi * c.getValue()));
questData.removeCard(c);
creditsLabel.setText("Total credits: " + questData.getCredits());
//3 conditions" 0 cards left, select the same row, select next row
int size = bottomModel.getRowCount();
if(size != 0) {
if(size == n) n--;
bottomTable.addRowSelectionInterval(n, n);
}
}//if(valid row)
}//sellButton_actionPerformed
@SuppressWarnings("unused")
// stats_actionPerformed
private void stats_actionPerformed(CardList list) {
}
//refresh Gui from deck, Gui shows the cards in the deck
@SuppressWarnings("unused")
// refreshGui
private void refreshGui() {
Deck deck = Constant.Runtime.HumanDeck[0];
if(deck == null) //this is just a patch, i know
deck = new Deck(Constant.Runtime.GameType[0]);
topModel.clear();
bottomModel.clear();
Card c;
ReadBoosterPack pack = new ReadBoosterPack();
for(int i = 0; i < deck.countMain(); i++) {
c = AllZone.CardFactory.getCard(deck.getMain(i), Constant.Player.Human);
//add rarity to card if this is a sealed card pool
if(Constant.Runtime.GameType[0].equals(Constant.GameType.Sealed)) c.setRarity(pack.getRarity(c.getName()));
bottomModel.addCard(c);
}//for
if(deck.isSealed() || deck.isDraft()) {
//add sideboard to GUI
for(int i = 0; i < deck.countSideboard(); i++) {
c = AllZone.CardFactory.getCard(deck.getSideboard(i), Constant.Player.Human);
c.setRarity(pack.getRarity(c.getName()));
topModel.addCard(c);
}
} else {
CardList all = AllZone.CardFactory.getAllCards();
for(int i = 0; i < all.size(); i++)
topModel.addCard(all.get(i));
}
topModel.resort();
bottomModel.resort();
}////refreshGui()
public class CustomListener extends MouseAdapter {
}
}

View File

@@ -67,6 +67,7 @@ public class Gui_DeckEditor_Menu extends JMenuBar implements NewConstants {
private final DeckIO boosterDeckIO = deckIO; private final DeckIO boosterDeckIO = deckIO;
private boolean isDeckSaved; private boolean isDeckSaved;
private String currentDeckName; private String currentDeckName;
private String currentGameType; private String currentGameType;
@@ -257,6 +258,12 @@ public class Gui_DeckEditor_Menu extends JMenuBar implements NewConstants {
}//setupSortMenu() }//setupSortMenu()
public void populateShop(CardList shop, CardList owned)
{
deckDisplay.updateDisplay(shop, owned);
}
public void newConstructed() { public void newConstructed() {
if(debugPrint) System.out.println("New Constructed"); if(debugPrint) System.out.println("New Constructed");
@@ -944,6 +951,11 @@ public class Gui_DeckEditor_Menu extends JMenuBar implements NewConstants {
deckDisplay.setTitle("Deck Editor : " + currentDeckName); deckDisplay.setTitle("Deck Editor : " + currentDeckName);
} }
public void setTitle(String s)
{
deckDisplay.setTitle(s);
}
public String getDeckName() { public String getDeckName() {
return currentDeckName; return currentDeckName;
} }

View File

@@ -35,10 +35,12 @@ public class Gui_Quest extends JFrame {
private JLabel difficultlyLabel = new JLabel(); private JLabel difficultlyLabel = new JLabel();
private JLabel winLostLabel = new JLabel(); private JLabel winLostLabel = new JLabel();
private JLabel rankLabel = new JLabel(); private JLabel rankLabel = new JLabel();
private JLabel creditsLabel = new JLabel();
@SuppressWarnings("unused") @SuppressWarnings("unused")
// border1 // border1
private Border border1; private Border border1;
private TitledBorder titledBorder1; private TitledBorder titledBorder1;
private JButton cardShopButton = new JButton();
private JButton deckEditorButton = new JButton(); private JButton deckEditorButton = new JButton();
private JPanel jPanel2 = new JPanel(); private JPanel jPanel2 = new JPanel();
private JButton playGameButton = new JButton(); private JButton playGameButton = new JButton();
@@ -73,7 +75,7 @@ public class Gui_Quest extends JFrame {
//center window on the screen //center window on the screen
Dimension screen = this.getToolkit().getScreenSize(); Dimension screen = this.getToolkit().getScreenSize();
setBounds(screen.width / 4, 50, //position setBounds(screen.width / 4, 50, //position
500, 540); //size 500, 610); //size
//if user closes this window, go back to "Quest Options" screen //if user closes this window, go back to "Quest Options" screen
this.addWindowListener(new WindowAdapter() { this.addWindowListener(new WindowAdapter() {
@@ -87,6 +89,7 @@ public class Gui_Quest extends JFrame {
//set labels //set labels
difficultlyLabel.setText(questData.getDifficulty()); difficultlyLabel.setText(questData.getDifficulty());
rankLabel.setText(questData.getRank()); rankLabel.setText(questData.getRank());
creditsLabel.setText("Credits: " + questData.getCredits());
String s = questData.getWin() + " wins / " + questData.getLost() + " losses"; String s = questData.getWin() + " wins / " + questData.getLost() + " losses";
winLostLabel.setText(s); winLostLabel.setText(s);
@@ -121,7 +124,7 @@ public class Gui_Quest extends JFrame {
difficultlyLabel.setBounds(new Rectangle(1, 52, 453, 41)); difficultlyLabel.setBounds(new Rectangle(1, 52, 453, 41));
difficultlyLabel.setFont(new java.awt.Font("Dialog", 0, 25)); difficultlyLabel.setFont(new java.awt.Font("Dialog", 0, 25));
difficultlyLabel.setHorizontalAlignment(SwingConstants.CENTER); difficultlyLabel.setHorizontalAlignment(SwingConstants.CENTER);
winLostLabel.setText("23 wins / 10 loses"); winLostLabel.setText("23 wins / 10 losses");
winLostLabel.setBounds(new Rectangle(1, 130, 453, 43)); winLostLabel.setBounds(new Rectangle(1, 130, 453, 43));
winLostLabel.setFont(new java.awt.Font("Dialog", 0, 25)); winLostLabel.setFont(new java.awt.Font("Dialog", 0, 25));
winLostLabel.setHorizontalAlignment(SwingConstants.CENTER); winLostLabel.setHorizontalAlignment(SwingConstants.CENTER);
@@ -130,7 +133,21 @@ public class Gui_Quest extends JFrame {
rankLabel.setBounds(new Rectangle(1, 93, 453, 37)); rankLabel.setBounds(new Rectangle(1, 93, 453, 37));
rankLabel.setFont(new java.awt.Font("Dialog", 0, 25)); rankLabel.setFont(new java.awt.Font("Dialog", 0, 25));
rankLabel.setHorizontalAlignment(SwingConstants.CENTER); rankLabel.setHorizontalAlignment(SwingConstants.CENTER);
deckEditorButton.setBounds(new Rectangle(291, 123, 142, 38)); creditsLabel.setBounds(new Rectangle(1, 170, 453, 37));
//creditsLabel.setText("Credits: 1000");
creditsLabel.setHorizontalAlignment(SwingConstants.CENTER);
creditsLabel.setHorizontalTextPosition(SwingConstants.CENTER);
cardShopButton.setBounds(new Rectangle(291, 100, 142, 38));
cardShopButton.setFont(new java.awt.Font("Dialog", 0, 18));
cardShopButton.setText("Card Shop");
cardShopButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(ActionEvent e) {
cardShopButton_actionPerformed(e);
}
});
deckEditorButton.setBounds(new Rectangle(291, 148, 142, 38));
deckEditorButton.setFont(new java.awt.Font("Dialog", 0, 18)); deckEditorButton.setFont(new java.awt.Font("Dialog", 0, 18));
deckEditorButton.setText("Deck Editor"); deckEditorButton.setText("Deck Editor");
deckEditorButton.addActionListener(new java.awt.event.ActionListener() { deckEditorButton.addActionListener(new java.awt.event.ActionListener() {
@@ -139,9 +156,9 @@ public class Gui_Quest extends JFrame {
} }
}); });
jPanel2.setBorder(titledBorder1); jPanel2.setBorder(titledBorder1);
jPanel2.setBounds(new Rectangle(39, 173, 441, 173)); jPanel2.setBounds(new Rectangle(39, 223, 441, 198));
jPanel2.setLayout(null); jPanel2.setLayout(null);
playGameButton.setBounds(new Rectangle(150, 446, 161, 37)); playGameButton.setBounds(new Rectangle(150, 516, 161, 37));
playGameButton.setFont(new java.awt.Font("Dialog", 0, 18)); playGameButton.setFont(new java.awt.Font("Dialog", 0, 18));
playGameButton.setText("Play Game"); playGameButton.setText("Play Game");
playGameButton.addActionListener(new java.awt.event.ActionListener() { playGameButton.addActionListener(new java.awt.event.ActionListener() {
@@ -150,33 +167,35 @@ public class Gui_Quest extends JFrame {
} }
}); });
oppTwoRadio.setText("Bob"); oppTwoRadio.setText("Bob");
oppTwoRadio.setBounds(new Rectangle(15, 50, 397, 41)); oppTwoRadio.setBounds(new Rectangle(15, 75, 250, 41));
oppOneRadio.setSelected(true); oppOneRadio.setSelected(true);
oppOneRadio.setText("Sam"); oppOneRadio.setText("Sam");
oppOneRadio.setBounds(new Rectangle(15, 18, 392, 33)); oppOneRadio.setBounds(new Rectangle(15, 53, 250, 33));
oppThreeRadio.setText("Generated Deck"); oppThreeRadio.setText("Generated Deck");
oppThreeRadio.setBounds(new Rectangle(15, 91, 406, 25)); oppThreeRadio.setBounds(new Rectangle(15, 116, 250, 25));
jLabel5.setText("Your Deck:"); jLabel5.setText("Your Deck:");
jLabel5.setBounds(new Rectangle(15, 126, 125, 29)); jLabel5.setBounds(new Rectangle(15, 151, 125, 29));
deckComboBox.setBounds(new Rectangle(98, 127, 185, 29)); deckComboBox.setBounds(new Rectangle(98, 152, 185, 29));
smoothLandCheckBox.setText("Stack AI land"); smoothLandCheckBox.setText("Stack AI land");
smoothLandCheckBox.setBounds(new Rectangle(154, 385, 153, 21)); smoothLandCheckBox.setBounds(new Rectangle(154, 455, 153, 21));
//smoothLandCheckBox.setSelected(true); //smoothLandCheckBox.setSelected(true);
resizeCheckbox.setText("Resizable Game Area"); resizeCheckbox.setText("Resizable Game Area");
resizeCheckbox.setBounds(new Rectangle(154, 354, 156, 24)); resizeCheckbox.setBounds(new Rectangle(154, 424, 156, 24));
millLoseCheckBox.setText("Milling = Loss Condition"); millLoseCheckBox.setText("Milling = Loss Condition");
millLoseCheckBox.setBounds(new Rectangle(154, 414, 165, 25)); millLoseCheckBox.setBounds(new Rectangle(154, 484, 165, 25));
//resizeCheckbox.setSelected(true); //resizeCheckbox.setSelected(true);
this.getContentPane().add(rankLabel, null); this.getContentPane().add(rankLabel, null);
this.getContentPane().add(jLabel1, null); this.getContentPane().add(jLabel1, null);
this.getContentPane().add(difficultlyLabel, null); this.getContentPane().add(difficultlyLabel, null);
this.getContentPane().add(winLostLabel, null); this.getContentPane().add(winLostLabel, null);
this.getContentPane().add(creditsLabel,null);
jPanel2.add(jLabel5, null); jPanel2.add(jLabel5, null);
jPanel2.add(deckComboBox, null); jPanel2.add(deckComboBox, null);
jPanel2.add(oppOneRadio, null); jPanel2.add(oppOneRadio, null);
jPanel2.add(oppTwoRadio, null); jPanel2.add(oppTwoRadio, null);
jPanel2.add(oppThreeRadio, null); jPanel2.add(oppThreeRadio, null);
jPanel2.add(cardShopButton, null);
jPanel2.add(deckEditorButton, null); jPanel2.add(deckEditorButton, null);
this.getContentPane().add(playGameButton, null); this.getContentPane().add(playGameButton, null);
this.getContentPane().add(smoothLandCheckBox, null); this.getContentPane().add(smoothLandCheckBox, null);
@@ -208,6 +227,26 @@ public class Gui_Quest extends JFrame {
this.dispose(); this.dispose();
}//deck editor button }//deck editor button
void cardShopButton_actionPerformed(ActionEvent e) {
Command exit = new Command() {
private static final long serialVersionUID = 8567193482568076362L;
public void execute() {
//saves all deck data
QuestData.saveData(AllZone.QuestData);
new Gui_Quest();
}
};
Gui_CardShop g = new Gui_CardShop(questData);
g.show(exit);
g.setVisible(true);
this.dispose();
}//card shop button
void playGameButton_actionPerformed(ActionEvent e) { void playGameButton_actionPerformed(ActionEvent e) {
Object check = deckComboBox.getSelectedItem(); Object check = deckComboBox.getSelectedItem();
if(check == null || getOpponent().equals("")) return; if(check == null || getOpponent().equals("")) return;

View File

@@ -177,13 +177,16 @@ public class Gui_WinLose extends JFrame {
void quitButton_actionPerformed(ActionEvent e) { void quitButton_actionPerformed(ActionEvent e) {
//are we on a quest? //are we on a quest?
if(AllZone.QuestData == null) new Gui_NewGame(); if(AllZone.QuestData == null) new Gui_NewGame();
else { else { //Quest
WinLose winLose = Constant.Runtime.WinLose; WinLose winLose = Constant.Runtime.WinLose;
QuestData quest = AllZone.QuestData; QuestData quest = AllZone.QuestData;
if(winLose.getWin() == 2) quest.addWin(); if(winLose.getWin() == 2) quest.addWin();
else quest.addLost(); else quest.addLost();
//System.out.println("QuestData cardpoolsize:" + AllZone.QuestData.getCardpool().size());
AllZone.QuestData.clearShopList();
if(quest.shouldAddCards(winLose.didWinRecently())) { if(quest.shouldAddCards(winLose.didWinRecently())) {
quest.addCards(); quest.addCards();
JOptionPane.showMessageDialog(null, "You have won new cards."); JOptionPane.showMessageDialog(null, "You have won new cards.");
@@ -193,6 +196,14 @@ public class Gui_WinLose extends JFrame {
quest.addAdditionalCards(); quest.addAdditionalCards();
JOptionPane.showMessageDialog(null, "You have won a random rare."); JOptionPane.showMessageDialog(null, "You have won a random rare.");
} }
if (winLose.didWinRecently())
{
long creds = quest.getCreditsToAdd();
JOptionPane.showMessageDialog(null, "You have earned " + creds + " credits.");
}
winLose.reset(); winLose.reset();
QuestData.saveData(quest); QuestData.saveData(quest);

View File

@@ -50,6 +50,8 @@ public class QuestData implements NewConstants {
private int win; private int win;
private int lost; private int lost;
private long credits;
private String difficulty; private String difficulty;
@@ -63,6 +65,7 @@ public class QuestData implements NewConstants {
//holds String card names //holds String card names
private ArrayList<String> cardPool = new ArrayList<String>(); private ArrayList<String> cardPool = new ArrayList<String>();
private ArrayList<String> newCardList = new ArrayList<String>(); private ArrayList<String> newCardList = new ArrayList<String>();
private ArrayList<String> shopList = new ArrayList<String>();
private QuestData_BoosterPack boosterPack = new QuestData_BoosterPack(); private QuestData_BoosterPack boosterPack = new QuestData_BoosterPack();
@@ -128,6 +131,7 @@ public class QuestData implements NewConstants {
//because cardPool already has basic land added to it //because cardPool already has basic land added to it
cardPool.addAll(list); cardPool.addAll(list);
credits = 250;
} }
@@ -210,9 +214,11 @@ public class QuestData implements NewConstants {
data.win = state.win; data.win = state.win;
data.lost = state.lost; data.lost = state.lost;
data.credits = state.credits;
data.rankIndex = state.rankIndex; data.rankIndex = state.rankIndex;
data.difficulty = state.difficulty; data.difficulty = state.difficulty;
data.shopList = state.shopList;
data.cardPool = state.cardPool; data.cardPool = state.cardPool;
data.myDecks = state.myDecks; data.myDecks = state.myDecks;
data.aiDecks = state.aiDecks; data.aiDecks = state.aiDecks;
@@ -234,6 +240,22 @@ public class QuestData implements NewConstants {
return new ArrayList<String>(cardPool); return new ArrayList<String>(cardPool);
} }
public ArrayList<String> getShopList() {
if (shopList != null)
return new ArrayList<String>(shopList);
else
return null;
}
public void setShopList(ArrayList<String> list)
{
shopList = list;
}
public void clearShopList() {
shopList.clear();
}
//rename - removeDeck, addDeck //rename - removeDeck, addDeck
//copy - addDeck //copy - addDeck
@@ -348,12 +370,60 @@ public class QuestData implements NewConstants {
cardPool.addAll(newCards); cardPool.addAll(newCards);
//getAddedCards() uses newCardList //getAddedCards() uses newCardList
newCardList.addAll(newCards); newCardList.addAll(newCards);
} }
public void addCard(Card c)
{
cardPool.add(c.getName());
}
public void removeCard(Card c)
{
String s = c.getName();
if (!cardPool.contains(s))
return;
for(int i=0;i<cardPool.size();i++)
{
String str = cardPool.get(i);
if (str.equals(s)){
cardPool.remove(i);
break;
}
}
}
public void addCardToShopList(Card c)
{
shopList.add(c.getName());
}
public void removeCardFromShopList(Card c)
{
String s = c.getName();
if (!shopList.contains(s))
return;
for(int i=0;i<shopList.size();i++)
{
String str = shopList.get(i);
if (str.equals(s)){
shopList.remove(i);
break;
}
}
}
public long getCreditsToAdd()
{
long creds = (long) (10 + (0.2 * win));
this.addCredits(creds);
return creds;
}
//gets all of the cards that are in the cardpool //gets all of the cards that are in the cardpool
public ArrayList<String> getCards() { public ArrayList<String> getCards() {
//copy CardList in order to keep private variables private //copy CardList in order to keep private variables private
@@ -406,6 +476,19 @@ public class QuestData implements NewConstants {
return lost; return lost;
} }
public void addCredits(long c)
{
credits+=c;
}
public void subtractCredits(long c)
{
credits-=c;
}
public long getCredits() {
return credits;
}
//should be called first, because the difficultly won't change //should be called first, because the difficultly won't change
public String getDifficulty() { public String getDifficulty() {
return difficulty; return difficulty;
@@ -426,7 +509,7 @@ public class QuestData implements NewConstants {
return rankArray[rankIndex]; return rankArray[rankIndex];
} }
//add cards after a certain number of wins or loses //add cards after a certain number of wins or losses
public boolean shouldAddCards(boolean didWin) { public boolean shouldAddCards(boolean didWin) {
int n = addCardsArray[convertDifficultyToIndex()]; int n = addCardsArray[convertDifficultyToIndex()];
@@ -482,10 +565,12 @@ public class QuestData implements NewConstants {
QuestData_State state = new QuestData_State(); QuestData_State state = new QuestData_State();
state.win = q.win; state.win = q.win;
state.lost = q.lost; state.lost = q.lost;
state.credits = q.credits;
state.difficulty = q.difficulty; state.difficulty = q.difficulty;
state.rankIndex = q.rankIndex; state.rankIndex = q.rankIndex;
state.cardPool = q.cardPool; state.cardPool = q.cardPool;
state.shopList = q.shopList;
state.myDecks = q.myDecks; state.myDecks = q.myDecks;
state.aiDecks = q.aiDecks; state.aiDecks = q.aiDecks;

View File

@@ -24,9 +24,10 @@ public class QuestData_State implements Serializable {
private static final long serialVersionUID = 7007940230351051937L; private static final long serialVersionUID = 7007940230351051937L;
int rankIndex, win, lost; int rankIndex, win, lost;
long credits;
String difficulty; String difficulty;
ArrayList<String> cardPool; ArrayList<String> cardPool, shopList;
Map<String, Deck> myDecks, aiDecks; Map<String, Deck> myDecks, aiDecks;
public QuestData_State() {} public QuestData_State() {}
@@ -35,12 +36,14 @@ public class QuestData_State implements Serializable {
* This constructor is used by QestData_State in the default package to create a replacement object for the * This constructor is used by QestData_State in the default package to create a replacement object for the
* obsolete class. * obsolete class.
*/ */
public QuestData_State(int rankIndex, int win, int lost, String difficulty, ArrayList<String> cardPool, Map<String, Deck> myDecks, Map<String, Deck> aiDecks) { public QuestData_State(int rankIndex, int win, int lost, long credits, String difficulty, ArrayList<String> cardPool, ArrayList<String> shopList, Map<String, Deck> myDecks, Map<String, Deck> aiDecks) {
this.rankIndex = rankIndex; this.rankIndex = rankIndex;
this.win = win; this.win = win;
this.lost = lost; this.lost = lost;
this.credits = credits;
this.difficulty = difficulty; this.difficulty = difficulty;
this.cardPool = cardPool; this.cardPool = cardPool;
this.shopList = shopList;
this.myDecks = myDecks; this.myDecks = myDecks;
this.aiDecks = aiDecks; this.aiDecks = aiDecks;
} }

View File

@@ -13,9 +13,6 @@ import forge.properties.NewConstants;
public class ReadBoosterPack implements NewConstants { public class ReadBoosterPack implements NewConstants {
// final private String commonFilename = Constant.IO.baseDir +"data/common.txt";
// final private String uncommonFilename = Constant.IO.baseDir +"data/uncommon.txt";
// final private String rareFilename = Constant.IO.baseDir +"data/rare.txt";
final private static String comment = "//"; final private static String comment = "//";
@@ -26,7 +23,6 @@ public class ReadBoosterPack implements NewConstants {
private CardList uncommonList; private CardList uncommonList;
private CardList rareList; private CardList rareList;
public static void main(String[] args) { public static void main(String[] args) {
//testing //testing
ReadBoosterPack r = new ReadBoosterPack(); ReadBoosterPack r = new ReadBoosterPack();
@@ -140,6 +136,34 @@ public class ReadBoosterPack implements NewConstants {
return pack; return pack;
} }
public CardList getShopCards(int numberWins)
{
CardList list = new CardList();
int numberRares = 1 + numberWins / 15;
if (numberRares > 10 )
numberRares = 10;
for (int i=0;i<numberRares;i++)
list.add(getRandomCard(rareList));
int numberUncommons = 3 + numberWins/10;
if (numberUncommons > 20)
numberUncommons = 20;
for(int i = 0; i < numberUncommons; i++)
list.add(getRandomCard(uncommonList));
int numberCommons = 5 + numberWins/5;
if (numberCommons > 35)
numberCommons = 35;
for(int i = 0; i < numberCommons; i++)
list.add(getRandomCard(commonList));
return list;
}
//return CardList of 5 or 6 cards, one for each color and maybe an artifact //return CardList of 5 or 6 cards, one for each color and maybe an artifact
private CardList getVariety(CardList in) { private CardList getVariety(CardList in) {
CardList out = new CardList(); CardList out = new CardList();

View File

@@ -0,0 +1,68 @@
package forge;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.util.HashMap;
import java.util.Map;
import forge.error.ErrorViewer;
import forge.properties.ForgeProps;
import forge.properties.NewConstants;
public class ReadPriceList implements NewConstants {
final private static String comment = "//";
private HashMap<String, Long> priceMap;
public ReadPriceList() {
setup();
}
private void setup() {
priceMap = readFile(ForgeProps.getFile(QUEST.PRICE));
}//setup()
private HashMap<String, Long> readFile(File file) {
BufferedReader in;
HashMap<String, Long> map = new HashMap<String, Long>();
try {
in = new BufferedReader(new FileReader(file));
String line = in.readLine();
//stop reading if end of file or blank line is read
while(line != null && (line.trim().length() != 0)) {
if(!line.startsWith(comment)) {
String s[] = line.split("=");
String name = s[0].trim();
String price = s[1].trim();
try {
long val = Long.parseLong(price.trim());
map.put(name, val);
} catch (NumberFormatException nfe) {
System.out.println("NumberFormatException: " + nfe.getMessage());
}
}
line = in.readLine();
}//if
} catch(Exception ex) {
ErrorViewer.showError(ex);
throw new RuntimeException("ReadPriceList : readFile error, " + ex);
}
return map;
}//readFile()
public Map<String,Long> getPriceList()
{
return priceMap;
}
}

View File

@@ -81,6 +81,8 @@ public interface NewConstants {
public static final String UNCOMMON = "quest/uncommon"; public static final String UNCOMMON = "quest/uncommon";
public static final String RARE = "quest/rare"; public static final String RARE = "quest/rare";
public static final String PRICE = "quest/price";
public static final String EASY = "quest/easy"; public static final String EASY = "quest/easy";
public static final String MEDIUM = "quest/medium"; public static final String MEDIUM = "quest/medium";
public static final String HARD = "quest/hard"; public static final String HARD = "quest/hard";