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

public class Streaker extends MobileSimObject {

	protected boolean inTurn;
	protected Color natural = Color.pink;
	protected boolean dead = false;

	public Streaker() {
		inTurn = false;
		dead = false;

	}

	public void die() {
		dead = true;
	}
	public Color getColor()
	//Effects: Gets the color for the simulation of the object depending on the
	//natural color of the object and its current action.
	{

		return natural;
	}

	//	synchronized
	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 successful, return true. If the move fails
	//          because the spot being attempted to move into is already
	//          occupied then return false.

	{
		inTurn = true;

		synchronized (getGrid()) {
			Enumeration neighbors = getNeighbors();
			while (neighbors.hasMoreElements()) {
				SimObject neighbor = (SimObject) neighbors.nextElement();
				if (neighbor instanceof Cabell) {
					if (dead == false) {
						//System.out.println("Congratulations!  You win!");
						getGrid().pauseObjects();	
					}
				}
			}

			Direction dir = Direction.streakerDirCabell();
			int newrow = getRow() + dir.northerlyDirection();
			int newcol = getColumn() + dir.easterlyDirection();

			if (getGrid().validLocation(newrow, newcol)) {
				if (dead = false);
				synchronized (getGrid()) {
					synchronized (this) {
						if (getGrid().isSquareEmpty(newrow, newcol)) {
							setLocation(newrow, newcol);
						}
					}
				}
			}

			inTurn = false;
		}

	}
}