package com.dot.dominion.domain;
import java.util.Collections;
import java.util.Stack;
public class Deck {
private Stack<Card> deck;
//protected boolean isFaceDown;
/**
* Basic constructor
*/
public Deck() {
deck = new Stack<Card>();
}
/**
* Add a card to the top of the deck.
*
* @param card The card to be added to the deck
*/
public void addToDeck( Card card ) {
deck.push( card );
}
/**
* Add a card to the bottom of the deck.
*
* @param card The card to be placed at the bottom of the deck
*/
public void addToBottomDeck( Card card ) {
deck.add( card );
}
/**
* Draw from the top of the deck.
*
* @return The card drawn
* null if the deck is empty
*/
public Card draw() {
if(! deck.empty() )
return deck.pop();
else
return null;
}
public boolean isEmpty() {
if( deck.size() == 0 )
return true;
else
return false;
}
/**
* Peek at the bottom card of the deck
*
* @return The card at the bottom of the deck.
* null if the deck is empty
*/
public Card peekAtBottom() {
if(! deck.empty() )
return deck.get( deck.size() - 1 );
else
return null;
}
/**
* Peek at the top card of the deck.
*
* @return The card at the top of the deck
* null if the deck is empty
*/
public Card peekAtTop() {
if(! deck.empty() )
return deck.peek();
else
return null;
}
/**
* Shuffle the deck
*/
public void shuffle() {
Collections.shuffle( deck );
}
/**
* Number of cards left in the Deck.
*
* @return The amount of cards left in the Deck.
*/
public int size() {
return deck.size();
}
/**
* Empties the deck.
*/
public void clear() {
deck.clear();
}
}
|