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

public class UvaPlayer extends UvaStudent
//Overview:  UvaPlayer is a supertype for classes that contain pickup lines
// and put moves on members of the opposite gender.
{
    protected UvaStudent opposite;
    protected String quoteOpp = "Hey, nice shoes..";
    static private int qCounterOpp = 0;
    static synchronized protected String getNextQuoteOpp()
    //@ensures \result != null
    {
        ++qCounterOpp;
        if (qCounterOpp > 5){
          qCounterOpp = qCounterOpp - 5;
        }
        if (qCounterOpp == 1){
          return "Do you have Windex on your pants?" +
           " Cause I can see myself in them";
        }
        if (qCounterOpp == 2){
          return "Did it hurt when you fell from heaven?";
        }
        if (qCounterOpp == 3){
          return "Hey, nice shoes!";
        }
        if (qCounterOpp == 4){
          return "I'm Drunk!";
        }
        if (qCounterOpp == 5){
          return "Is it just me, or are you hot?";
        }
        return "Error No Player Quote";
   }
   public void talkOpp ()
   //Effects:  Locks this and opposite, then displays dialogue specific to
   //either beer or UvaStudent hitting on another UvaStudent.  Also calls
   //response from opposite.
   {
	Object lock1, lock2;
       	if ((opposite != null) && (opposite.name !=null) && (name != null)) {
            // Always grab the lock for whichever name is alphabetically first
	    if (name.compareTo (opposite.name) < 0)

            {
		lock1 = this;
		lock2 = opposite;
	    } else {
		lock1 = opposite;
		lock2 = this;
	    }
	    synchronized (lock1) {
		synchronized (lock2) {
                  //System.err.println("P in talk");
                  isTalking = true;
	          isResponding = false;

	          System.err.println (name + " says " + quoteOpp);
                  //System.err.println("p after speak, before resp");
	          delay (1000);
                  if (opposite.respondPlayer()){
                    System.err.println (name + " says " + "Yes.  Hey, Nice shoes...");
                    System.err.println (name + " and " + opposite.name + " dance.");
                    //System.err.println("P before happy");
                    happy(this, opposite);
                  }
	        //opposite = null;
                isTalking = false;
                //System.err.println("end of talk");
                opposite = null;
                }
            }
        }else{//System.err.println("P (opposite = null) || (opposite.name =null) || (name = null)");
        }
    }
    public boolean respond(String sex)
    //Requires: sex != null

    //Effects: If sex is same as this.gender, returns response + pickup line.
    //Else, returns standard response from UvaStudent
    {
        //System.err.println("P response");
        if (!(sex.equals(gender)))//@nowarn
        //esc/java does not allow requirements on inhereted methods, but
        //the requirement for all the methods includes sex != null, so does
        //not violate substitution principle.
        {
          isTalking = false;
	  isResponding = true;
	  System.err.println (name + " responds: " + quote + ".  " + quoteOpp);
	  delay (1000);
	  isResponding = false;
          //System.err.println("P possible error");

          return true;
        }
        else {
          super.respond(sex);
        }
        return false;
    }
    public boolean respondPlayer()
    //Effects:  Prints out response to caller, showing interest
    {
        //System.err.println("P response player");
    	isTalking = false;
	isResponding = true;
	System.err.println (name + " responds: " + quote + " Thank you.  Wanna dance?");
        delay (1000);
        return true;
    }

}