Search in sources :

Example 11 with Card

use of Cards.Card in project cardgame1 by joey101937.

the class DeckBuilder method addCard.

/**
 * Attempts to add a card to deck.
 * If the card is not able to be added due to custom deck restrictions, it will prompt the user and not add the card
 * @param c card to add
 */
public void addCard(Card c) {
    if (c.heroClass != product.deckClass && c.heroClass != HeroClass.Neutral) {
        JOptionPane.showMessageDialog(null, c.heroClass + " card cannot be added to " + product.deckClass + " deck.");
        return;
    }
    if (product.deck.size() + 1 > CustomDeck.MAX_NUM_CARDS) {
        JOptionPane.showMessageDialog(null, "Maximum number of cards in deck");
        return;
    }
    int numCopies = 0;
    for (Card card : product.deck) {
        if (card.name == c.name) {
            numCopies++;
        }
    }
    if (numCopies + 1 > CustomDeck.MAX_NUM_COPIES) {
        JOptionPane.showMessageDialog(null, "Cannot have more than " + CustomDeck.MAX_NUM_COPIES + " copies of the same card in a deck");
        return;
    }
    product.deck.add(c);
    updateList();
}
Also used : Card(Cards.Card)

Example 12 with Card

use of Cards.Card in project cardgame1 by joey101937.

the class DeckBuilder method init.

/**
 * initializes core components
 */
private void init() {
    panel = new BackgroundPane(Main.BackgroundImage);
    panel.setSize(this.getSize());
    panel.setLayout(null);
    this.add(panel);
    scroll = new JScrollPane();
    scroll.setSize(700, 500);
    scroll.setLocation(10, 100);
    scroll.getVerticalScrollBar().setUnitIncrement(20);
    scroll.getHorizontalScrollBar().setEnabled(false);
    interior = new JPanel();
    interior.setLocation(0, 0);
    interior.setSize(700, 1000);
    interior.setPreferredSize(interior.getSize());
    interior.setBackground(Color.gray);
    scroll.add(interior);
    scroll.setViewportView(interior);
    panel.add(scroll);
    interior.setLayout(null);
    titleLabel = new JLabel();
    titleLabel.setSize(300, 50);
    titleLabel.setText("DECK BUILDER");
    titleLabel.setLocation(400, 20);
    titleLabel.setFont(titleFont);
    panel.add(titleLabel);
    classTitle = new JLabel();
    classTitle.setFont(classTitleFont);
    classTitle.setText("Deck Class:");
    classTitle.setLocation(20, 10);
    classTitle.setSize(200, 30);
    panel.add(classTitle);
    classCombo = new JComboBox();
    classCombo.setSize(new Dimension(200, 25));
    classCombo.setLocation(20, 50);
    classCombo.addItem(HeroClass.Neutral);
    classCombo.addItem(HeroClass.Ocean);
    classCombo.addItem(HeroClass.Undead);
    classCombo.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            updateDeckClass();
        }
    });
    panel.add(classCombo);
    classLabel = new JLabel();
    classLabel.setSize(80, 80);
    classLabel.setLocation(230, 20);
    classLabel.setIcon(new ImageIcon(product.deckClass.getClassIcon()));
    panel.add(classLabel);
    isValidLabel = new JLabel();
    isValidLabel.setSize(200, 100);
    isValidLabel.setLocation(770, 550);
    isValidLabel.setFont(classTitleFont);
    updateIsValidLabel();
    isValidLabel.addMouseListener(new MouseListener() {

        @Override
        public void mouseClicked(MouseEvent e) {
        }

        @Override
        public void mousePressed(MouseEvent e) {
            if (!product.isValid()) {
                String toDisplay = "";
                for (String s : product.diagnose()) {
                    toDisplay += (s + "\n");
                }
                JOptionPane.showMessageDialog(null, toDisplay);
            }
        }

        @Override
        public void mouseReleased(MouseEvent e) {
        }

        @Override
        public void mouseEntered(MouseEvent e) {
        }

        @Override
        public void mouseExited(MouseEvent e) {
        }
    });
    panel.add(isValidLabel);
    loadButton = new JButton();
    loadButton.setSize(100, 50);
    loadButton.setLocation(510, 600);
    loadButton.setText("Load...");
    loadButton.setFont(classTitleFont);
    loadButton.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            mainBuilder.setEnabled(false);
            DeckLoaderScratch dl = new DeckLoaderScratch(mainBuilder);
        }
    });
    panel.add(loadButton);
    clearButton = new JButton();
    clearButton.setSize(100, 50);
    clearButton.setLocation(410, 600);
    clearButton.setText("Clear");
    clearButton.setFont(classTitleFont);
    clearButton.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            product.deck.clear();
            mainBuilder.updateList();
        }
    });
    panel.add(clearButton);
    saveButton = new JButton();
    saveButton.setSize(100, 50);
    saveButton.setText("Save...");
    saveButton.setFont(classTitleFont);
    saveButton.setLocation(610, 600);
    panel.add(saveButton);
    saveButton.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            String givenName = JOptionPane.showInputDialog("Save as...");
            if (givenName == null || givenName.trim().equals("")) {
                JOptionPane.showMessageDialog(null, "No name detected");
                return;
            }
            if (!isStringSafe(givenName)) {
                JOptionPane.showMessageDialog(null, "Name cannot contain the following characters:\n ~ # % * { } [ ] < > ? /\\ + |");
                return;
            }
            product.deckName = givenName;
            File f = new File("Decks/" + givenName + ".deck");
            if (f.exists()) {
                int shouldOverwrite = JOptionPane.showConfirmDialog(null, "Deck already exists. Overwrite?");
                // user doesnt want to overwrite
                if (shouldOverwrite != 0)
                    return;
            }
            product.export();
            JOptionPane.showMessageDialog(null, "Deck Saved!\n" + f.getAbsolutePath());
        }
    });
    int column = 0;
    int row = 0;
    for (Card c : Card.getCardList()) {
        CardIcon ci = new CardIcon(c, this);
        ci.setLocation(10 + column * (c.sprite.getWidth() + 30), row * (c.sprite.getHeight() + 20));
        column++;
        if (column > 2) {
            row++;
            column = 0;
        }
        interior.add(ci);
    }
    interior.setPreferredSize(new Dimension(700, row * (300 + 20)));
}
Also used : JScrollPane(javax.swing.JScrollPane) JPanel(javax.swing.JPanel) ImageIcon(javax.swing.ImageIcon) MouseEvent(java.awt.event.MouseEvent) JComboBox(javax.swing.JComboBox) ActionEvent(java.awt.event.ActionEvent) JButton(javax.swing.JButton) JLabel(javax.swing.JLabel) Dimension(java.awt.Dimension) Card(Cards.Card) MouseListener(java.awt.event.MouseListener) ActionListener(java.awt.event.ActionListener) File(java.io.File)

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