/*
 * Created on Nov 22, 2004
 *
 * Utilizes Java Power Tools (JPT)
 * http://www.ccs.neu.edu/jpt/
 * 
 */

/**
 *Authored by Brandon Schory
 *
 *With help, inspiration, and code from Richard Rasala, Mike Battista, Ken Eimer, and Matt DeGennaro
 *
 */

import edu.neu.ccs.gui.*;

public class Dealer extends Person{
	
	//Variable Declarations
    int total;
	static Card DealersFirst;
	int NumberOfAces;
	int NumberOfCards;
	
	/** Keeps track of all aspects of the Dealer's Cards including:
	 * - Number of Aces
	 * - Number of Cards
	 * - Calls the Total() function
	 * - Calls the ReturnCardImage() function
	 */
	protected void DealerCards(Card c){
	    if(c.value == 11){
			NumberOfAces++;
		}		
		NumberOfCards += 1;
		total = Total(c.value, total);
		if (NumberOfCards == 1){
			DealersFirst = c;
			BlackJack.DealerCards[0].setPaintable(new ImagePaintable(Deck.Images[52]));
		}
		else{
		    Person.ReturnCardImage(c, BlackJack.DealerCards, NumberOfCards);
		}
		
	}
	
	/** Contorls the Dealers AI, which follows certain rules:
	 * - Stay at any value over 16
	 * - Hit otherwise
	 * Tests for a "soft hand" (posession of aces)
	 * If there is an ace, subtracts 10 points from the Dealer's total to keep from busting, and repeats DealerAI()
	 * Checks if dealer busts
	 * Initializes the BlackJack.FinalStep() function if dealer does not bust
	 */
	public void DealerAI(){
		while(total < 17){DealerCards(BlackJack.DrawCard());}
		BlackJack.DealerTotal.setViewState(total + "");
		if(total > 21 && NumberOfAces > 0 ){
			total -= 10;
			NumberOfAces--;
			DealerAI();}
		else if(total > 21){BlackJack.EndGame2();}
		else{BlackJack.FinalStep();}
	}
	
	/** Creates a new Dealer*/
	public Dealer(){
		total = 0;
		NumberOfAces = 0;
		NumberOfCards = 0;
	}
}

