Search in sources :

Example 6 with Card

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();
    }
}
Also used : CorruptFileException(CustomDecks.CorruptFileException) ImageIcon(javax.swing.ImageIcon) JLabel(javax.swing.JLabel) CustomDeck(CustomDecks.CustomDeck) IOException(java.io.IOException) Card(Cards.Card)

Example 7 with Card

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;
}
Also used : HashMap(java.util.HashMap) HashSet(java.util.HashSet) Card(Cards.Card)

Example 8 with Card

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;
}
Also used : FileWriter(java.io.FileWriter) ArrayList(java.util.ArrayList) File(java.io.File) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) Card(Cards.Card) BufferedWriter(java.io.BufferedWriter)

Example 9 with Card

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;
}
Also used : TrapCard(Traps.TrapCard) Card(Cards.Card)

Example 10 with Card

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);
}
Also used : ImageIcon(javax.swing.ImageIcon) JLabel(javax.swing.JLabel) Card(Cards.Card)

Aggregations

Card (Cards.Card)12 ArrayList (java.util.ArrayList)3 ImageIcon (javax.swing.ImageIcon)3 JLabel (javax.swing.JLabel)3 File (java.io.File)2 IOException (java.io.IOException)2 KelpieCard (Cards.Base.KelpieCard)1 CorruptFileException (CustomDecks.CorruptFileException)1 CustomDeck (CustomDecks.CustomDeck)1 SettingsPane (GUI.SettingsPane)1 Minion (Minions.Minion)1 TrapCard (Traps.TrapCard)1 Sticker (cardgame1.Sticker)1 Dimension (java.awt.Dimension)1 ActionEvent (java.awt.event.ActionEvent)1 ActionListener (java.awt.event.ActionListener)1 MouseEvent (java.awt.event.MouseEvent)1 MouseListener (java.awt.event.MouseListener)1 BufferedWriter (java.io.BufferedWriter)1 FileNotFoundException (java.io.FileNotFoundException)1