import java.util.*;

/**
 * An encapsulation of a participant in a card game
 *
 * @author  Prof. David Bernstein, James Madison University
 * @version 1.0
 */
public class CardGameParticipant
{

    private Table        table;
    private Vector       down, up;


    protected static final boolean FACE_UP   = true;
    protected static final boolean FACE_DOWN = false;


    /**
     * Default Constructor
     */
    public CardGameParticipant()
    {
	down = new Vector();
	up   = new Vector();
    }




    /**
     * Ask this participant to tell you how many "face up"
     * cards he/she/it has
     *
     * @return  The number of up cards
     */
    public int howManyUpCardsDoYouHave()
    {
	return up.size();
    }



    /**
     * Tell this participant to give back the cards
     * he/she/it is currently holding
     */
    public void giveYourCardsBack()
    {
	down.clear();
	up.clear();
    }



    /**
     * Ask this participant to tell show you a
     * particular "face down" card
     *
     * Children that want to keep their down cards secret
     * (which is almost always the case) will want to override 
     * this method and return null
     *
     * @param  cardIndex  The index number of the down Card
     * @return            The Card (or null)
     */
    protected Card showMeDownCard(int cardIndex)
    {
	return (Card)(down.elementAt(cardIndex));
    }




    /**
     * Ask this participant to tell show you a
     * particular "face up" card
     *
     * @param  cardIndex  The index number of the up Card
     * @return            The Card
     */
    public Card showMeUpCard(int cardIndex)
    {
	return (Card)(up.elementAt(cardIndex));
    }




    /**
     * Instruct this participant to take a card and keep
     * it either "face up" or "face down"
     *
     * @param card          The Card
     * @param faceUpOrDown  FACE_UP or FACE_DOWN
     */
    public void takeThisCard(Card card, boolean faceUpOrDown)
    {
	if (faceUpOrDown == FACE_UP) up.add(card);
	else                         down.add(card);
    }


    /**
     * Instruct this participant to play (or work) at
     * a particular Table
     *
     * @param playAt   The Table to play at
     */
    public void playAtTable(Table playAt)
    {
	table = playAt;
    }


    /**
     * Ask this participant to give you a "list" of all of the
     * players at his/her/its Table
     *
     * @return  All of the Player objects 
     */
    public Player[] whoAreThePlayersAtYourTable()
    {
	return table.getPlayers();
    }



    /**
     * Ask this participant to give you the Dealer
     * at his/her/its Table
     *
     * @return  The Dealer
     */
    public Dealer whoIsTheDealerAtYourTable()
    {
	return table.getDealer();
    }


}
