Last active
August 29, 2015 13:58
-
-
Save ASxa86/10208274 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.*; | |
public class Deck | |
{ | |
private ArrayList<Card> deck = new ArrayList<Card>(); | |
public Deck() | |
{ | |
for(Card.Suit s : Card.Suit.values()) | |
{ | |
for(Card.Type t : Card.Type.values()) | |
{ | |
this.deck.add(new Card(t, s)); | |
} | |
} | |
} | |
public void shuffle() | |
{ | |
long seed = System.nanoTime(); | |
Collections.shuffle(this.deck, new Random(seed)); | |
} | |
public void shuffle(ArrayList<Card> hand) | |
{ | |
for(Card c : hand) | |
{ | |
this.deck.add(c); | |
} | |
this.shuffle(); | |
} | |
public int size() | |
{ | |
return this.deck.size(); | |
} | |
public ArrayList<Card> draw(int number) | |
{ | |
ArrayList<Card> cards = new ArrayList<Card>(); | |
for(int i = 0; i < number; i++) | |
{ | |
cards.add(this.deck.remove(0)); | |
} | |
return cards; | |
} | |
public int cardCount() | |
{ | |
return this.deck.size(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment