package game.classes {
	
	import flash.display.MovieClip;
	import flash.events.MouseEvent;
	import game.classes.vertline;
	import game.classes.horLine;
	
	public class gameLevel extends MovieClip {
		
		public var currLevelVar:int;
		public var sceneCoords:Array;
		
		
		private var _currLevel:int;
		private var _currSquare:int;
		
		
		private var trysArray:Array = new Array();
		private var _sceneCoords:Array=new Array();
		private var _friendlyCoords:Array=new Array();
		
		
		public function set currSquare(curSq:int):void {
			_currSquare = curSq;
		}
		public function get currSquare():int {
            return _currSquare;  
          }
		  
		  public function get friendlyTrys():Array {
            return _friendlyCoords;  
          }
		public function set currLv(newVal : int):void {
            _currLevel = newVal;
  
          }
		  public function createFriendlys(friendX:int):String{
			 
			  var xMain = Math.floor(friendX/100).toString();
			  var xRemain = friendX%100;
			  trace(xRemain);
			  switch(xRemain){
				  case 25:
				  xMain = xMain + "-1/4";
				  break;
				  case 50:
				  var newXmain:String = xMain + "-1/2";
				  xMain = newXmain;
				  break;
				  case 75:
				  xMain = xMain + "-3/4";
				  break;				  
			  }
			  
			 return xMain + " Units";	 
			  
		  }


		  public function get currLv():int {
            return _currLevel;  
          }
		  public function currCoords():Array {
			  return _sceneCoords;
		  }
		  
		  public function gameLevel(level:int) {
			_currLevel = level;
		}
		public function addCoord(box:square,finX:int,finY:int):void {
			var boxObj = new Object();
			boxObj.friendlyX = createFriendlys(finX);
			boxObj.friendlyY = createFriendlys(finY);
			boxObj.boxN = box;
			_sceneCoords.push(boxObj);
		}
		public function addTry(tryX:Number,tryY:Number,tryNum:int,tryBlock:int):Boolean {
			var trys:Object = new Object();
			var res:Boolean;
			trys.lvl = this.currLevelVar;
			trys.block = tryBlock;
			trys.num = tryNum;
		    trys.thisX =tryX;
			trys.targetX = currCoords()[tryBlock].boxN.x;
			trys.targetY = currCoords()[tryBlock].boxN.y;
		    trys.thisY = tryY;
			//trys.friendlyX = createFriendlys(tryX);
			//trys.friendlyY = createFriendlys(tryY);
			trys.success = tryMove(trys);
			trysArray.push(trys);
			//trace("freindly x " + trys.friendlyX);
			if(trys.success){
				res= true;
			}else{
				res=false;
			}
			return res;
		}

		public function get getTrys():Array {
			return trysArray;
		}
		
         
		 
		 public function tryMove(tryN:Object):Boolean {
			 var tryBool:Boolean;
			 if(((-8) < tryN.thisX && tryN.thisX < (currCoords()[tryN.block].boxN.x+8)) && ((currCoords()[tryN.block].boxN.y-8) < tryN.thisY && tryN.thisY < (currCoords()[tryN.block].boxN.y+8))){
				
				 tryBool= true;
			 }else{
				 tryBool = false;
			 }
			return tryBool;
			
		 }
                 public function startLevel(sceneNum:int):void {
                           currLevelVar = sceneNum;
                         
                   }
		 
		 

 
        
		
	}
	
	
}
