import java.awt.Color;
public class MultiTank extends ComputerTank {
	//OVERVIEW: A MultiTank is a Tank that randomly produces four new computer tanks.
	private boolean inTurn;
	
	public MultiTank(){
		super(300,2,Direction.SOUTH,50,40,8);
	}

	public void multiply() {
		synchronized (getGrid()) {
			int newx1 = getX() + 1;
			int newy1 = getY() + 1;
			int newx2 = getX() - 1;
			int newy2 = getY() - 1;
			Tank sib1 = new ComputerTank();
			Tank sib2 = new ComputerTank();
			Tank sib3 = new ComputerTank();
			Tank sib4 = new ComputerTank();
			try {
				if ((getGrid().validLocation(newx1, getY()))) {
					TankSimulator.multi.play();
					getGrid().setObjectAt(newx1, getY(), sib1);
					sib1.init(newx1, getY(), getGrid());
					sib1.resumeObject();
				}
				if ((getGrid().validLocation(newx2, getY()))) {
					TankSimulator.multi.play();
					getGrid().setObjectAt(newx2, getY(), sib2);
					sib2.init(newx2, getY(), getGrid());
					sib2.resumeObject();
				}
				if ((getGrid().validLocation(getX(), newy1))) {
					TankSimulator.multi.play();
					getGrid().setObjectAt(getX(), newy1, sib3);
					sib3.init(getX(), newy1, getGrid());
					sib3.resumeObject();
				}
				if ((getGrid().validLocation(getX(), newy2))) {
					TankSimulator.multi.play();
					getGrid().setObjectAt(getX(), newy2, sib4);
					sib4.init(getX(), newy2, getGrid());
					sib4.resumeObject();
				}
			} catch (BadLocationException e) {
				System.err.println("BadLocation for Tank");
			}
		}

	}

	public Color getColor() {
		if (inTurn) {
			return Color.white;
		} else {
			return Color.orange;
		}

	}

	public void executeTurn() throws RuntimeException {
		if (rd.nextInt(20) == 5) {
			super.executeTurn();
			multiply();
		} else {
			super.executeTurn();
		}
	}
}