using UnityEngine;
using UnityEngine.UI;
using System.Collections;

public class InputManager : MonoBehaviour {

	public Ship ship;
	public EnemyManager eManager;
	public EnemySpawner spawner;

	public Image qImage;
	public Image wImage;
	public Image eImage;

	void Start()
	{
		eManager.setWButtonSelected(false);
		eManager.setEButtonSelected(false);
		eManager.setQButtonSelected(true);
		qImage.color=Color.green;
	}

	// Update is called once per frame
	void Update () 
	{
		//Ship Controls
		if(Input.GetButton("Up"))
		{
			ship.transform.Translate(0, ship.speed * Time.deltaTime, 0);
		}
		if(Input.GetButton("Down"))
		{
			ship.transform.Translate(0, -ship.speed * Time.deltaTime, 0);
		}

		if(Input.GetButton("Right"))
		{
			ship.transform.Translate(ship.speed * Time.deltaTime, 0, 0);
		}
		if(Input.GetButton("Left"))
		{
			ship.transform.Translate(-ship.speed * Time.deltaTime, 0, 0);
		}
		
		if(Input.GetButton("OnFire"))
		{
			ship.OnFire();
		}

		//Enemy Controls
		if(Input.GetKeyDown(KeyCode.Q))
		{
			if(!eManager.getQButtonSelected())
			{
				eManager.setQButtonSelected(true);
				if(eManager.getWButtonSelected())
				{
					eManager.setWButtonSelected(false);
					wImage.color=Color.white;
				}
				if(eManager.getEButtonSelected())
				{
					eManager.setEButtonSelected(false);
					eImage.color=Color.white;
				}
				//Show Q enemy type is selected
				qImage.color=Color.green;
			}
		}
		if(Input.GetKeyDown(KeyCode.W))
		{
			if(!eManager.getWButtonSelected())
			{
				eManager.setWButtonSelected(true);
				if(eManager.getQButtonSelected())
				{
					eManager.setQButtonSelected(false);
					qImage.color=Color.white;
				}
				if(eManager.getEButtonSelected())
				{
					eManager.setEButtonSelected(false);
					eImage.color=Color.white;
				}
				//Show W enemy type is selected
				wImage.color=Color.green;
			}
		}
		if(Input.GetKeyDown(KeyCode.E))
		{
			if(!eManager.getEButtonSelected())
			{
				eManager.setEButtonSelected(true);
				if(eManager.getQButtonSelected())
				{
					eManager.setQButtonSelected(false);
					qImage.color=Color.white;
				}
				if(eManager.getWButtonSelected())
				{
					eManager.setWButtonSelected(false);
					wImage.color=Color.white;
				}
				//Show E enemy type is selected
				eImage.color=Color.green;
			}
		}


		if(Input.GetKeyDown(KeyCode.Alpha1))
		{
			if(eManager.getQButtonSelected())
			{
				//fire q type enemy from position 1
				spawner.spawnEnemy(0,0);
			}
			else if(eManager.getWButtonSelected())
			{
				//fire w type enemy from position 1
				spawner.spawnEnemy(1,0);
			}
			else if(eManager.getEButtonSelected())
			{
				//fire e type enemy from position 1
				spawner.spawnEnemy(2,0);
			}
		}
		if(Input.GetKeyDown(KeyCode.Alpha2))
		{
			if(eManager.getQButtonSelected())
			{
				//fire q type enemy from position 2
				spawner.spawnEnemy(0,1);
			}
			else if(eManager.getWButtonSelected())
			{
				//fire w type enemy from position 2
				spawner.spawnEnemy(1,1);
			}
			else if(eManager.getEButtonSelected())
			{
				//fire e type enemy from position 2
				spawner.spawnEnemy(2,1);
			}
		}
		if(Input.GetKeyDown(KeyCode.Alpha3))
		{
			if(eManager.getQButtonSelected())
			{
				//fire q type enemy from position 3
				spawner.spawnEnemy(0,2);
			}
			else if(eManager.getWButtonSelected())
			{
				//fire w type enemy from position 3
				spawner.spawnEnemy(1,2);
			}
			else if(eManager.getEButtonSelected())
			{
				//fire e type enemy from position 3
				spawner.spawnEnemy(2,2);
			}
		}
		if(Input.GetKeyDown(KeyCode.Alpha4))
		{
			if(eManager.getQButtonSelected())
			{
				//fire q type enemy from position 4
				spawner.spawnEnemy(0,3);
			}
			else if(eManager.getWButtonSelected())
			{
				//fire w type enemy from position 4
				spawner.spawnEnemy(1,3);
			}
			else if(eManager.getEButtonSelected())
			{
				//fire e type enemy from position 4
				spawner.spawnEnemy(2,3);
			}
		}
		if(Input.GetKeyDown(KeyCode.Alpha5))
		{
			if(eManager.getQButtonSelected())
			{
				//fire q type enemy from position 5
				spawner.spawnEnemy(0,4);
			}
			else if(eManager.getWButtonSelected())
			{
				//fire w type enemy from position 5
				spawner.spawnEnemy(1,4);
			}
			else if(eManager.getEButtonSelected())
			{
				//fire e type enemy from position 5
				spawner.spawnEnemy(2,4);
			}
		}
		if(Input.GetKeyDown(KeyCode.Alpha6))
		{
			if(eManager.getQButtonSelected())
			{
				//fire q type enemy from position 1
				spawner.spawnEnemy(0,5);
			}
			else if(eManager.getWButtonSelected())
			{
				//fire w type enemy from position 1
				spawner.spawnEnemy(1,5);
			}
			else if(eManager.getEButtonSelected())
			{
				//fire e type enemy from position 1
				spawner.spawnEnemy(2,5);
			}
		}
		if(Input.GetKeyDown(KeyCode.Alpha7))
		{
			if(eManager.getQButtonSelected())
			{
				//fire q type enemy from position 1
				spawner.spawnEnemy(0,6);
			}
			else if(eManager.getWButtonSelected())
			{
				//fire w type enemy from position 1
				spawner.spawnEnemy(1,6);
			}
			else if(eManager.getEButtonSelected())
			{
				//fire e type enemy from position 1
				spawner.spawnEnemy(2,6);
			}
		}
	}
}
