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

public class UvaPlayerBoy extends UvaPlayer {
    // OVERVIEW: A UvaPlayerBoy is a male type of UvaPlayer

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

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



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 ();
		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 UvaGirl) || (neighbor instanceof UvaPlayerGirl)){
			    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;
    }
 }