use of Cards.Card in project cardgame1 by joey101937.
the class DeckLoaderScratch method loadSelected.
/**
* Loads the deck corresponding to what the combobox has selected.
*/
private void loadSelected() {
try {
for (JLabel jl : cardLabels) {
panel.remove(jl);
}
cardLabels.clear();
chosenDeck = new CustomDeck(savedDecks.get(combo.getSelectedIndex()));
deckTitleLabel.setText(chosenDeck.deckName);
deckTitleLabel.setIcon(new ImageIcon(chosenDeck.deckClass.getHeroPortraitPath()));
int i = 0;
for (Card c : chosenDeck.deck) {
JLabel cardLabel = new CardLabel(c, this);
cardLabel.setSize(300, 22);
cardLabel.setLocation(20, 200 + 22 * i);
panel.add(cardLabel);
cardLabels.add(cardLabel);
i++;
}
if (!chosenDeck.isValid()) {
System.out.println(chosenDeck.diagnose());
isValidLabel.setText("Illegal Deck");
isValidLabel.setIcon(new ImageIcon(Main.assets + "redXsmall.png"));
} else {
isValidLabel.setIcon(new ImageIcon(Main.assets + "checkmarkSmall.png"));
isValidLabel.setText("Confirm");
}
panel.repaint();
core.setVisible(true);
} catch (IOException ex) {
JOptionPane.showMessageDialog(null, "IO Error");
ex.printStackTrace();
} catch (CorruptFileException ex) {
JOptionPane.showMessageDialog(null, "Deck could not be loaded without error: " + ex.getMessage());
ex.printStackTrace();
}
}
use of Cards.Card in project cardgame1 by joey101937.
the class CustomDeck method diagnose.
/**
* returns a list of problems with the deck.
* used to figure out why a deck is illegal
* @return list of string explanations of what went wrong. empty if legal deck
*/
public HashSet<String> diagnose() {
HashSet<String> output = new HashSet<>();
// stores the naame of card with hte num of them in the deck
Map<String, Integer> numCards = new HashMap<>();
for (Card c : deck) {
if (c == null) {
output.add("Null card in deck");
continue;
}
if (c.heroClass != HeroClass.Neutral && c.heroClass != deckClass) {
output.add("A " + deckClass + " deck may not contain " + c.heroClass + " class cards: " + c.name);
}
if (numCards.get(c.name) == null) {
numCards.put(c.name, 1);
} else {
numCards.put(c.name, numCards.get(c.name) + 1);
if (numCards.get(c.name) > MAX_NUM_COPIES) {
output.add("Too many copies of " + c.name + ". Max of " + MAX_NUM_COPIES + " copies.");
}
}
}
// if(deck.size()>MAX_NUM_CARDS) output.add("Deck must have no more than " + MAX_NUM_CARDS + " cards; currently has " + deck.size());
if (deck.size() != 20)
output.add("Deck must have exactly 20 cards. Currently " + deck.size() + ".");
return output;
}
use of Cards.Card in project cardgame1 by joey101937.
the class CustomDeck method export.
/**
* creates a file representation of this deck
* format of the file is
* HeroClass
* card1
* card2
* card3
* ...
*/
public File export() {
File output = new File("Decks" + File.separator + deckName + ".deck");
ArrayList<String> lines = new ArrayList<>();
lines.add(deckClass.name());
for (Card c : deck) {
lines.add(c.name);
}
try {
FileWriter fw = new FileWriter(output, false);
BufferedWriter bw = new BufferedWriter(fw);
for (String s : lines) {
bw.write(s);
System.out.println("writing... " + s);
bw.newLine();
}
bw.close();
} catch (Exception e) {
e.printStackTrace();
}
return output;
}
use of Cards.Card in project cardgame1 by joey101937.
the class SeaSerpentTrapCard method tick.
// intrinsic value of 1. gains value for each applicable fish in hand, plus percent of fish in deck
@Override
public void tick() {
int fishInDeck = 0;
int fishInHand = 0;
intrinsicValue = 1;
for (Card c : owner.hand) {
if (c.cardType == CardType.Minion && c.summon.tribe == Tribe.Fish && c.cost > 1) {
this.intrinsicValue += 4;
fishInHand++;
}
}
for (Card c : owner.deck) {
if (c.cardType == CardType.Minion && c.summon.tribe == Tribe.Fish && c.cost > 1) {
fishInDeck++;
}
}
if (owner.deck.size() != 0)
intrinsicValue += (fishInDeck / owner.deck.size()) * 3;
// if we cant fullfill the 3 fish requirement, this card is worthless
if (fishInHand + fishInDeck < 3 && owner.hand.size() < Hero.maxHandSize)
intrinsicValue = 0;
}
use of Cards.Card in project cardgame1 by joey101937.
the class DeckBuilder method updateList.
/**
* updates the list of added cards in the deck
*/
private void updateList() {
for (JLabel cl : cardLabels) {
panel.remove(cl);
}
cardLabels.clear();
int i = 0;
for (Card c : this.product.deck) {
CardLabel cl = new CardLabel(c);
cardLabels.add(cl);
cl.setSize(300, 22);
cl.setLocation(800, 100 + 22 * i);
panel.add(cl);
i++;
}
JLabel numCards = new JLabel();
numCards.setText(product.deck.size() + "/" + CustomDeck.MIN_NUM_CARDS);
numCards.setSize(300, 22);
numCards.setLocation(800, 100 + 22 * i);
cardLabels.add(numCards);
panel.add(numCards);
classLabel.setIcon(new ImageIcon(product.deckClass.getClassIcon()));
updateIsValidLabel();
this.panel.repaint();
setVisible(true);
}
Aggregations