import java.awt.Color;
import java.awt.event.*;

public class UserTank extends Tank implements KeyListener{
	private int key;
	private ItemStatus is;

	public UserTank(){
		this.is = new ItemStatus(this);
		this.hp = 5;
		this.speed = 150;
	}	
	public ItemStatus getItemStatus(){
		return is;
	}
	public Color getColor(){
		return Color.blue;
	}
	public void keyPressed(KeyEvent ke){
		key = ke.getKeyCode();
	}
	public void keyReleased(KeyEvent ke){	
	}
	public void keyTyped(KeyEvent ke){
	}
	public void executeTurn(){
		if(shooting==true){
			delay(gun.getSpeed());
			shooting=false;
		}
		delay(50+speed);
		if(!dead){
			is.update();
			synchronized(getGrid()){
				switch(key){
					case KeyEvent.VK_LEFT:
						moveDir(Direction.WEST);
						break;
					case KeyEvent.VK_RIGHT:
						moveDir(Direction.EAST);
						break;
					case KeyEvent.VK_UP:
						moveDir(Direction.NORTH);
						break;
					case KeyEvent.VK_DOWN:
						moveDir(Direction.SOUTH);
						break;
					case KeyEvent.VK_A:
						shoot();
						break;
					case KeyEvent.VK_Q:
						if(items[0]!=null){
							this.useItem(1);
						}
						break;
					case KeyEvent.VK_W:
						if(items[1]!=null){
							this.useItem(2);
						}
						break;
					case KeyEvent.VK_E:
						if(items[2]!=null){
							this.useItem(3);
						}
						break;
					case KeyEvent.VK_Z:
						if(items[0]!=null){
							items[0].die();
							items[0]=null;
						}
						break;
					case KeyEvent.VK_X:
						if(items[1]!=null){
							items[1].die();
							items[1]=null;
						}
						break;
					case KeyEvent.VK_C:
						if(items[2]!=null){
							items[2].die();
							items[2]=null;
						}
						break;
				}
				key=0;
			}
		}
	}
}