import java.util.ArrayList; import java.util.Collections; public class Deck { protected ArrayList topdeck; protected ArrayList discard; protected ArrayList hand; public Card drawCard(){ if (topdeck.size()<=0) return null; Card card=topdeck.get(0); topdeck.remove(0); hand.add(card); return card; } public Deck() { SQLDriver d = new SQLDriver(); d.setupTable(); topdeck = new ArrayList(); hand = new ArrayList(); discard = new ArrayList(); for (int i = 0; i < 60; i++){ topdeck.add(d.getRandomCard()); } Shuffle(); for (int i = 0; i < 7; i++){ drawCard(); } } private void Shuffle() { Collections.shuffle(topdeck); } public ArrayList getTopdeck() { return topdeck; } public void setTopdeck(ArrayList topdeck) { this.topdeck = topdeck; } public ArrayList getDiscard() { return discard; } public void setDiscard(ArrayList discard) { this.discard = discard; } public ArrayList getHand() { return hand; } public void setHand(ArrayList hand) { this.hand = hand; } @Override public String toString() { return "Deck [discard=" + discard + ", hand=" + hand + ", topdeck=" + topdeck + "]"; } public void showHand() { int maxName = 0; int maxType = 0; for (Card c : hand) { if (c.cardName.length() > maxName) { maxName = c.cardName.length(); } if (c.creatureType.length() > maxType) { maxType = c.creatureType.length(); } } for (int i = 0; i < hand.size(); i++) { Card c=hand.get(i); System.out.print((i+1) + " " + c.cardName); for (int ii = c.cardName.length(); ii < maxName; ii++) { System.out.print(" "); } System.out.print(" (" + c.creatureType + ")"); for (int ii = c.creatureType.length(); ii < maxType; ii++) { System.out.print(" "); } System.out.print("\t" +(c.manaCost>=0? c.manaCost :0) + "M\t" + c.power + "P\t" + c.toughness + "T\n"); } System.out.println(""); } }