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

public class UvaPlayerGirl extends UvaPlayer {
     // OVERVIEW: A UvaPlayerGirl is a female type of UvaPlayer

    static private int counter = 0;
    static synchronized private String getNextName ()
    //@ensures \result != null
    {
	counter++;
	return "Sasha" + counter;
    }
    public UvaPlayerGirl () {
	inTurn = false;
	friend = null;
        opposite = null;
	isTalking = false;
	isResponding = false;
        isHappy = false;
        quoteOpp = getNextQuoteOpp();
        quote = getNextQuote();
	name = getNextName();
        gender = "female";
        drinkCount = 5;
        natural = Color.red;
        isOut = false;
    }


    public String getGender(){
      return "female";
    }

public void executeTurn () throws RuntimeException
       // Note: requires isInitialized is inherited from SimObject
       // EFFECTS: First, checks if 'this' has friend or opposite.  If it does,
       // calls talk() or talkOpp respectively on this.  Else picks a
       // random direction and tries to move that way, then checks to see if it
       // has any neighbors, adding them to friend or opposite depending on
       // their gender

    {
	inTurn = true;

	if (opposite != null) {
	    if (!isTalking && !isResponding) {
		talkOpp ();
                opposite = null;
		// delay (600);
	    }
        }
        else if (friend != null) {
	    if (!isTalking && !isResponding) {
		talk ();
                friend = null;
		// delay (600);
            }
	}
        else {
	    synchronized (getGrid ()) {

                 super.executeTurn (); // Continue walking around randomly
		Enumeration neighbors = getNeighbors ();

		while (neighbors.hasMoreElements ()) {
		    SimObject neighbor = (SimObject) neighbors.nextElement ();
                    //@assume neighbor != null
                    //no null neighbors in graph
                    synchronized (neighbor){
                      if (neighbor instanceof UvaStudent) {

                        if (!((neighbor instanceof HappyStudent)
                           || (neighbor instanceof OutStudent))){
                          if ((neighbor instanceof UvaBoy) || (neighbor instanceof UvaPlayerBoy)){
			    UvaStudent newOpposite = (UvaStudent) neighbor;
                            System.err.println (name + " hits on: " +
			      newOpposite.name);

			    if (newOpposite.friend == null) {
				opposite = newOpposite;
				newOpposite.friend = this;
				break;
			    }
			  }

                      else {
                        UvaStudent newFriend = (UvaStudent) neighbor;
                        System.err.println (name + " found a friend: " + newFriend.name);

			    if (newFriend.friend == null) {
				friend = newFriend;
				newFriend.friend = this;
				break;
			    }
                        }
                      }
                    }
                    }
                }
            }
          }
	inTurn = false;
    }
  }