/*
 * BOS done by Bug Games Team - www.Bug-Games.net - @BugGames - info@bug-games.net
 * BOS game was an entry for Global Game Jam 2015 www.GlobalGameJam.com
 * Programmer: Danar Kayfi - @DanarKayfi
 * Artiest: Mohammad Al-Dmour - @LightOfDarkness
 * Everything (Code+Art) in this game belongs to Bug Games Team.
 * Some SFX are from soundbible.com.
 */
using UnityEngine;
using System.Collections;
using UnityEngine.UI;

public class enterCMD : MonoBehaviour 
{
	public GameObject bodyText;
	public GameObject newCMD;
	public InputField inputField;

	public AudioClip beep;
	public AudioClip fuzzyBeep;

	private int bodyTextLines = 0;

	// Use this for initialization
	void Start () 
	{
		bodyTextLines = 0;
		inputField.Select();
		inputField.ActivateInputField();
	}
	
	// Update is called once per frame
	void Update () 
	{
	
	}

	public void endInput()
	{


		if(bodyTextLines >= 22)
		{
			bodyText.GetComponent<Text> ().text = "";
			bodyTextLines = 0;
		}

		bodyText.GetComponent<Text> ().text += ">";
		bodyText.GetComponent<Text> ().text += newCMD.GetComponent<Text> ().text.ToLower();
		bodyText.GetComponent<Text> ().text += "\n";

		checkCMD (newCMD.GetComponent<Text> ().text.ToLower());

		bodyTextLines += 1;
		inputField.Select();
		inputField.ActivateInputField();
	}

	void checkCMD(string cmd)
	{

		inputField.GetComponent<InputField> ().text = "";

		bool validCMD = false;
		bool validHiddenCMD = false;

		switch (cmd)
		{
		case "stats":
			audio.clip = beep;
			bodyText.GetComponent<Text> ().text += "CMD: " + sharedvalues.cmdDiscovered + "/" + sharedvalues.Totalcmd;
			bodyText.GetComponent<Text> ().text += "  ---  ";
			bodyText.GetComponent<Text> ().text += "game: " + sharedvalues.gamesDiscovered + "/" + sharedvalues.Totalgames;
			bodyText.GetComponent<Text> ().text += "  ---  ";
			bodyText.GetComponent<Text> ().text += "Hidden CMD: " + sharedvalues.hiddenCMDDiscovered + "/" + sharedvalues.TotalHiddenCMD;
			bodyText.GetComponent<Text> ().text += "  ---  ";
			bodyText.GetComponent<Text> ().text += "\n";
			bodyTextLines += 1;
			validCMD = true;
			break;
		case "dir":
			audio.clip = beep;
			bodyText.GetComponent<Text> ().text += "game";
			bodyText.GetComponent<Text> ().text += "\n";
			bodyTextLines += 1;
			validCMD = true;
			break;
		case "run game":
			audio.clip = beep;
			if(sharedvalues.FDL)
			{
				bodyText.GetComponent<Text> ().text += "Loading...";
				sharedvalues.gamesDiscovered = 1;
				Application.LoadLevel("Scene_Game");
			}
			else if (sharedvalues.FDS)
					bodyText.GetComponent<Text> ().text += "corrupt data";
				else
					bodyText.GetComponent<Text> ().text += "can not find data";
			bodyText.GetComponent<Text> ().text += "\n";
			bodyTextLines += 1;
			validCMD = true;
			break;

		case "clear":
			audio.clip = beep;
			bodyText.GetComponent<Text> ().text = "";
			bodyTextLines = 0;
			validCMD = true;
			break;
		case "help":
			audio.clip = beep;
			bodyText.GetComponent<Text> ().text += "help - stats - clear - dir - run ... - credit";
			bodyText.GetComponent<Text> ().text += "\n";
			bodyTextLines += 1;
			validCMD = true;
			break;

		case "credit":
			audio.clip = beep;
			bodyText.GetComponent<Text> ().text += "BOS done by Bug Games --- www.bug-games.net";
			bodyText.GetComponent<Text> ().text += "\n";
			bodyText.GetComponent<Text> ().text += "as an entry for Global Game Jam 2015 --- www.globalgamejam.com";
			bodyText.GetComponent<Text> ().text += "\n";
			bodyText.GetComponent<Text> ().text += "\n";
			bodyText.GetComponent<Text> ().text += "Programmer: Danar Kayfi --- @DanarKayfi";
			bodyText.GetComponent<Text> ().text += "\n";
			bodyText.GetComponent<Text> ().text += "Artiest: Mohammad Al-Dmour (Moe) --- @LightOfDarkness";
			bodyText.GetComponent<Text> ().text += "\n";
			bodyText.GetComponent<Text> ().text += "\n";
			bodyText.GetComponent<Text> ().text += "Special Thanks to:";
			bodyText.GetComponent<Text> ().text += "\n";
			bodyText.GetComponent<Text> ().text += "Anmar M. Al-Obaidy --- @PhAnmar";
			bodyText.GetComponent<Text> ().text += "\n";
			bodyText.GetComponent<Text> ().text += "Jordan Gaming Lab (Jam Site) --- www.GamingLab.jo";
			bodyText.GetComponent<Text> ().text += "\n";
			bodyText.GetComponent<Text> ().text += "\n";
			bodyText.GetComponent<Text> ().text += "Note: some SFX are from soundbible.com";
			bodyText.GetComponent<Text> ().text += "\n";
			bodyTextLines +=11;
			validCMD = true;
			break;

			/*-------------------------------*/
		case "":
			bodyTextLines += 1;
			validHiddenCMD = true;
			break;
		case "danar":
			audio.clip = beep;
			audio.clip = beep;
			bodyText.GetComponent<Text> ().text += "danar is the programmer";
			bodyText.GetComponent<Text> ().text += "\n";
			bodyTextLines += 1;
			validHiddenCMD = true;
			break;
		case "moe":
			audio.clip = beep;
			bodyText.GetComponent<Text> ().text += "moe is the artiest";
			bodyText.GetComponent<Text> ().text += "\n";
			bodyTextLines += 1;
			validHiddenCMD = true;
			break;
		case "anmar":
			audio.clip = beep;
			bodyText.GetComponent<Text> ().text += "anmar is the game tester";
			bodyText.GetComponent<Text> ().text += "\n";
			bodyTextLines += 1;
			validHiddenCMD = true;
			break;
		case "bug games":
			audio.clip = beep;
			bodyText.GetComponent<Text> ().text += "BUG GAMES a Passionate Indie Game Developer Team --- www.Bug-Games.net";
			bodyText.GetComponent<Text> ().text += "\n";
			bodyTextLines += 1;
			validHiddenCMD = true;
			break;
		case "ggj15":
			audio.clip = beep;
			bodyText.GetComponent<Text> ().text += "this game made in Global Game Jam 2015 www.GlobalGameJam.com";
			bodyText.GetComponent<Text> ().text += "\n";
			bodyTextLines += 1;
			validHiddenCMD = true;
			break;
		case "lost":
			audio.clip = beep;
			bodyText.GetComponent<Text> ().text += "why are you in (anonymous messages) world";
			bodyText.GetComponent<Text> ().text += "\n";
			bodyTextLines += 1;
			validHiddenCMD = true;
			break;
		case "fuck":
			audio.clip = beep;
			bodyText.GetComponent<Text> ().text += "not appropriate command";
			bodyText.GetComponent<Text> ().text += "\n";
			bodyTextLines += 1;
			validHiddenCMD = true;
			break;
		case "share":
			audio.clip = beep;
			bodyText.GetComponent<Text> ().text += "yes please we need your support ^_^";
			bodyText.GetComponent<Text> ().text += "\n";
			bodyTextLines += 1;
			validHiddenCMD = true;
			break;
		case "what to do?":
			audio.clip = beep;
			bodyText.GetComponent<Text> ().text += "Figure it out urself...kidding...try to run the (game) and beat it";
			bodyText.GetComponent<Text> ().text += "\n";
			bodyTextLines += 1;
			validHiddenCMD = true;
			break;
		case "reset":
			audio.clip = beep;
			bodyText.GetComponent<Text> ().text += "No keep going...";
			bodyText.GetComponent<Text> ().text += "\n";
			bodyTextLines += 1;
			validHiddenCMD = true;
			break;
		case "exit":
			audio.clip = beep;
			bodyText.GetComponent<Text> ().text += "No way you are stuck here hahahaha!";
			bodyText.GetComponent<Text> ().text += "\n";
			bodyTextLines += 1;
			validHiddenCMD = true;
			break;
		case "end":
			audio.clip = beep;
			bodyText.GetComponent<Text> ().text += "Its ur end not mine!";
			bodyText.GetComponent<Text> ().text += "\n";
			bodyTextLines += 1;
			validHiddenCMD = true;
			break;
		case "go to hell":
			audio.clip = beep;
			bodyText.GetComponent<Text> ().text += "ok but you are coming with me!";
			bodyText.GetComponent<Text> ().text += "\n";
			bodyTextLines += 1;
			validHiddenCMD = true;
			break;
		case "what do we do now?":
			audio.clip = beep;
			bodyText.GetComponent<Text> ().text += "i don't know!!! imagine if this was a game jam theme!...Crazy huh!!";
			bodyText.GetComponent<Text> ().text += "\n";
			bodyTextLines += 1;
			validHiddenCMD = true;
			break;
		case "fuck you":
			audio.clip = beep;
			bodyText.GetComponent<Text> ().text += "..................";
			sharedvalues.cmdFoundList.Clear();
			sharedvalues.hiddenCMDFoundList.Clear();
			sharedvalues.cmdDiscovered =0;
			sharedvalues.hiddenCMDDiscovered =0;
			sharedvalues.FDL = false;
			sharedvalues.FDS = false;
			sharedvalues.mainPower = false;
			sharedvalues.Power = false;
			sharedvalues.gamesDiscovered = 0;
			Application.LoadLevel("Scene_loading");
			break;

		default:
			audio.clip = fuzzyBeep;
			bodyText.GetComponent<Text> ().text += "incorrect command";
			bodyText.GetComponent<Text> ().text += "\n";
			bodyTextLines += 1;
			break;
		}
		/*-------------------------------*/


		audio.Play();

		if (!sharedvalues.cmdFoundList.Exists (x => x == cmd) && validCMD)
		{
			sharedvalues.cmdFoundList.Add(cmd);
			sharedvalues.cmdDiscovered +=1;
		}

		if (!sharedvalues.hiddenCMDFoundList.Exists (x => x == cmd) && validHiddenCMD)
		{
			sharedvalues.hiddenCMDFoundList.Add(cmd);
			sharedvalues.hiddenCMDDiscovered +=1;
		}
	}

}
