import java.awt.Color;

public class Students extends Player {
	//  OVERVIEW: Student is a subtype of Player which interacts with 
	//  the crawler.  They randomly walk around waiting for interaction.
	
	private boolean /*@non_null@*/inTurn;
	protected String /*@non_null@*/state;
		// Currently in the middle of a turn (used for coloring)

		public Students() {
			inTurn = false;
			state = "Students";
		}

		public void executeTurn() throws RuntimeException
		// Note: requires isInitialized is inherited from SimObject
		// EFFECTS: Picks a random direction and tries to move that way. 
		//          If the move is not successful, tries another location.

		{
			inTurn = true;
			Direction dir = Direction.randomDirection();
			int newy = getY() + dir.northerlyDirection();
			int newx = getX() + dir.easterlyDirection();
		
			if (getGrid().validLocation(newx, newy)) {
				 synchronized (getGrid()){
				 if  (getGrid().isSquareEmpty(newx, newy)) { //@nowarn Pre
					// Here, we simulate interaction by sleeping
					delay(500);				
					setLocation(newx, newy);
				}
			}
			}

			inTurn = false;
		}

		public Color getColor() 
		//	Effects: returns the color associated with this
		{
			if (inTurn) {
				return Color.cyan;
			} else {
				return Color.cyan;
			}
		} //@nowarn Post // ESC/Java doesn't know Color constants are not null
	}


//class modeled loosely after Philosopher.java