package com.dot.dominion.domain;
import java.util.ArrayList;
public class Hand {
private ArrayList<Card> hand; //Hand
/**
* Default constructor
*
*/
public Hand() {
hand = new ArrayList<Card>();
}
/**
* Add a Card to the Hand
*
* @param card The Card to be added
*/
public void addToHand( Card card ) {
if( card != null )
hand.add( card );
}
/**
* Check if a Card exists within the Hand
*
* @param card The Card being checked for
* @return The Card if it exists in the Hand.
* null:
* * the Hand is empty
* * the Card doesn't exist in the Hand
*/
public Card checkCard( Card card ) {
if(! hand.isEmpty() )
return peekCard( hand.indexOf(card) );
else
return null;
}
/**
* Discard the chosen Card from the Hand
*
* @param card The Card to be discarded from the Hand
* @return The Card chosen
* null:
* -- The Hand is empty
* -- The Card doesn't exist
*/
public Card discardCard( Card card ) {
if(! hand.isEmpty() )
return discardCard( hand.indexOf(card) );
else
return null;
}
/**
* Discard the Card at the index from the Hand
*
* @param index The index of the Card
* @return The Card chosen
* null:
* -- The Hand is empty
* -- The Card doesn't exist
*/
public Card discardCard( int index ) {
if(! hand.isEmpty() )
return hand.remove( index );
else
return null;
}
/**
* The size of the Hand
*
* @return The amount of Cards left in the Hand
*/
public int getSize() {
return hand.size();
}
/**
* Check the Card at the specified index in the Hand
*
* @param index The index of the Card
* @return The Card at the index.
* null:
* * if the Hand is empty
* * the Card doesn't exist in the Hand
*/
public Card peekCard( int index ) {
if(! hand.isEmpty() )
return hand.get( index );
else
return null;
}
/**
* The Hand in an array
*
* @return array -- An array of the cards within this Hand
*/
public Card[] toArray() {
Card[] array = new Card[hand.size()];
for( int i = 0; i < hand.size(); i++ )
array[i] = hand.get(i);
return array;
}
}
|