Exemple #1
0
		/// <summary>
		/// Initializes a new position.
		/// </summary>
		/// <param name="gridBlock">Grid block of position.</param>
		/// <param name="depth">Remaining depth to traverse.</param>
		/// <param name="prevPos">Previous position in traversal.</param>
		/// <param name="finalPositions">The final positions list of the move tree.</param>
		public Position(GridBlock gridBlock, int depth, Position prevPos, LinkedList<Position> finalPositions) {
			this.gridBlock = gridBlock;
			//Decrease the number of remaining moves.
			depth--;
			adjPos = new Position[4];
			//Only get adjacent positions if more moves remain.
		if(depth > 0 && gridBlock != null) {
				//For each adjacent gridblock.
				for(int i = 0; i < 4; i++) {
					//Get the adjacent gridblock, if it exists.
					GridBlock adjGridBlock = gridBlock.getAdj(i);
					//Check if the adjacent gridblock exists, and if it can be occupied.
					if(adjGridBlock != null && adjGridBlock.unitInstalled == false)
						//Set the adjacent gridblock as a space that can be moved to.
						adjPos[i] = new Position(adjGridBlock, depth, this, finalPositions);
				}
			} else {
				//If no more moves remain, add to final positions.
				finalPositions.AddLast(this);
			}
		}
	/// <summary>
	/// called by the unit when it moves
	/// </summary>
	/// <param name="">.</param>
	public void setMovmentDirection(GridBlock currentGridBlockTmp, Direction movmentDirection){
		currentGridBlock = currentGridBlockTmp;
		gridBlockMovingTo = currentGridBlockTmp.getAdj(movmentDirection);
		switch(movmentDirection){
		case Direction.UP:
			transform.Translate(0, 0, 0.7f);
			break;
		case Direction.DOWN:
			transform.Translate(0, 0, -0.7f);
			break;
		case Direction.LEFT:
			transform.Translate(-0.7f, 0, 0);
			break;
		case Direction.RIGHT:
			transform.Translate(0.7f, 0, 0);
			break;
		default:
			break;
		}
		directionMoving = movmentDirection;
	}
	//TODO work on unit overlap
	/// <summary>
	/// Display unit's projected movement through this block.
	/// </summary>
	/// <param name="cameFrom">Block this unit is coming from.</param>
	/// <param name="isGoingTo">Block this unit is going to.</param>
	///<returns> A refrence to the spriteControlers for moveArmIn (0) and moveArmOut (1)
	/// when the action is preformed set there color to Color.Clear</returns>
	public SpriteControler[] displayMoveOnQueue(GridBlock cameFrom, GridBlock isGoingTo){

		SpriteControler moveArmIn = null;
		SpriteControler moveArmOut = null;

		for(int i = 0; i < 4; i++){
			if(isGoingTo.getAdj(i) == cameFrom){
				moveArmOut = cameFrom.spriteDisplayScript.movementDirections[i];
				// Faster than mod 4.
				i += 2;
				if(i > 3){
					i -= 4;
				}
				moveArmIn = isGoingTo.spriteDisplayScript.movementDirections[i];
				break;
			}
		}
		//TODO Make move arm in add out visible using color.
		if(moveArmIn == null || moveArmOut == null){
			Debug.LogError("cameFrom and isGoingTo were not adjacent!\n" +
			"null was returned to the action");
			return null;
		}
		moveArmIn.setColor(Color.white);
		moveArmOut.setColor(Color.white);

		SpriteControler[] sc = { moveArmIn, moveArmOut };

		return sc;
	}