Skip to content

Instantly share code, notes, and snippets.

@ASxa86
Last active August 29, 2015 13:58
Show Gist options
  • Save ASxa86/10208274 to your computer and use it in GitHub Desktop.
Save ASxa86/10208274 to your computer and use it in GitHub Desktop.
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