import java.awt.Color;
import java.util.Enumeration;


public class UvaKeg extends UvaStudent {
    // OVERVIEW: A UvaKeg is a subtype of UvaStudent that represents a keg.  It
    //does not move or initiate conversation, but it does respond and can become
    //empty (OutStudent)

    protected boolean inTurn;
    protected boolean response;
    protected UvaStudent friend;
    protected boolean isTalking;
    protected boolean isResponding;
    protected boolean isHappy;
    protected String quote;
    protected String name;
    protected int firstIndex = 0;
    protected String gender;
    private int kegCount = 50;
    static private int counterG = 0;
    static private int counterK = 0;
    static synchronized private String getNextName () {
	counterK++;
	return "Keg" + counterK;
    }


    public UvaKeg () {
	inTurn = false;
	friend = null;
	isTalking = false;
	isResponding = false;
        isHappy = false;
        name = getNextName ();
        gender = "NotDefined";
    }

    public Color getColor()
    {
	if (inTurn) {
	    return Color.gray;
	} else {
	    if (isResponding) {
		return Color.yellow;
	    } else if (isHappy) {
		return Color.red;
	    }else {
		return Color.gray;
	    }
        }
    }//@nowarn NonNullResult // ESC/Java doesn't know Color constants are not null

    public boolean respond (String sex) {
	//requires sex != null
        //Effects: Prints UvaKeg response, subtracts from kegCount, checks
        //if keg is empty, if so, calls OutStudent on UvaKeg
        isTalking = false;
	isResponding = true;
	System.err.println (name + " responds: Phssssh...");
	--kegCount;
        System.err.println (name + " Keg still going.., " + kegCount
          + "beers left!");
        delay (1000);
	isResponding = false;
        if (kegCount == 0){
          System.err.println (name + " is cashed!");
          outStu(this);
        }
        return false;
    }

    public boolean respondPlayer () {
	//Effects: Prints UvaKeg response, subtracts from kegCount, checks
        //if keg is empty, if so, calls OutStudent on UvaKeg
        isTalking = false;
	isResponding = true;
	System.err.println (name + " responds: Phssssh...");
        --kegCount;
	delay (1000);
	isResponding = false;
        if (kegCount == 0){
          System.err.println (name + " is cashed!");
          OutStudent k = new OutStudent();
          Grid gKeg = getGrid();//@nowarn
          //Grid is being used, must be initialized
          gKeg.setObjectAt(this.getRow(), this.getColumn(), k);
        }
        return false;
    }

   public void executeTurn () throws RuntimeException{}
    //no action is taken
}