// public IEnumerator CoroutineMoveTowards (int[] intCoords){ // yield return new WaitForSeconds (3); // Debug.Log ("coroutineMoveTowardscalled"); // float[] newCords = new float[2]; // newCords [0] = intCoords [0] + 0.5f; // newCords [1] = intCoords [1] + 0.5f; // //// moveToCoords[0] = intCoords[0] + 0.5f; //// moveToCoords[1] = intCoords[1] + 0.5f; // startMoving = true; // // if (startMoving) { // float step = speed * Time.deltaTime; // Vector3 TargetPosition = new Vector3 (newCords [0], 0.05f, newCords [1]); // transform.position = Vector3.MoveTowards (transform.position, TargetPosition, step); // // if (transform.position == TargetPosition) { // startMoving = false; // moveToCoords = null; // // } // // } // // } public void SplitUnit() { Debug.Log("Unit split requested"); RUnit squareDictionaryRUnit = gameController.FindSquareDictionrayUnitByCoords(coords); strength = strength / 2; squareDictionaryRUnit.strength = strength; //Get a random square that is available for this unit to move into , in order to instantiate the new piece into. int[] coordsToInstantiateSplitUnit = board.possibleMovementCoords [Random.Range(0, board.possibleMovementCoords.Count)]; // get a random avaialbe square that this piece could have moved into that we can place the piece in, string stringCoordsToInstantiateSplitUnit = gameController.ConvertArrayToString(coordsToInstantiateSplitUnit); //convert these coords to string gameController.game.ConstructNewUnit(stringCoordsToInstantiateSplitUnit, allegiance, unitType, strength); //create a new unit in the SquareDictionary gameController.game.squareDictionary [stringCoordsToInstantiateSplitUnit].unitOccupyingSquare.numMoves = 0; // set the new units numMOves to 0; board.PlaceUnit(gameController.game.squareDictionary [stringCoordsToInstantiateSplitUnit].unitOccupyingSquare); // and now instantiate this piece on the actual board board.RegenerateFogOfWar(); //regenerate fog of war (as the unit might have been placed on the border //Take a move and sync this unit to the game.squareDictionary RUnit. squareDictionaryRUnit.numMoves -= 1; //take a move gameController.SyncSceneUnitToDictionaryUnit(squareDictionaryRUnit, this.gameObject); // and sync this unit's value to the dictionary above. board.DeselectPiece(); //clear the selector squares, hide the UnitHUD and deselect the unit in gameController. }
public void ShowPossibleSquares(int[] intCoords, RUnit unit) { //After clicking on one of your units, show the squares that you can move to, take and merge with. //Debug.Log ("Show Possible Squares called"); ClearAllSelectorSquares(); // if any are already instantiated for any reason, clear this and the lists that contain the movement squares etc. GameObject selectionSquare; if (unit.unitType == UnitType.Army) { for (int x = -1; x <= 1; x++) { for (int z = -1; z <= 1; z++) { Vector3 selectorCoord = new Vector3(); selectorCoord.x = intCoords [0] + x + 0.5f; selectorCoord.z = intCoords [1] + z + 0.5f; int[] positionCoords = new int[] { intCoords[0] + x, intCoords[1] + z }; string coordsAsString = gameController.ConvertArrayToString(positionCoords); if (selectorCoord.x < 0.5f || selectorCoord.z < 0.5f || selectorCoord.x > gameController.game.boardWidth || selectorCoord.z > gameController.game.boardHeight) { // don't instantiate out of range ie. do nothing (return cancels the loop) } else if (gameController.game.squareDictionary [coordsAsString].squareOccupied) { //if there is a unit there if (gameController.game.squareDictionary [coordsAsString].unitOccupyingSquare.allegiance == unit.allegiance && gameController.game.squareDictionary [coordsAsString].unitOccupyingSquare.unitType == UnitType.Army) { //if it is a unit of my allegiance there if (unit.coords != coordsAsString) { //stops a blue square forming on original position; selectionSquare = blueSelectionSquarePrefab; mergeableSquareCoords.Add(positionCoords); GameObject newUnit = Instantiate(selectionSquare, selectorCoord, Quaternion.identity, selectionSquaresSpawner); newUnit.tag = "selectorSquare"; } else { //if we want to instantiate a special square that says where it came from. } } else if (gameController.game.squareDictionary [coordsAsString].unitOccupyingSquare.allegiance == unit.allegiance && gameController.game.squareDictionary [coordsAsString].unitOccupyingSquare.unitType == UnitType.Fortress) { //If the unit in that space is a fortress of my allegiance then do nothing } else { //if it is an enemy unit there selectionSquare = redSelectionSquarePrefab; battleSquareCoords.Add(positionCoords); GameObject newUnit = Instantiate(selectionSquare, selectorCoord, Quaternion.identity, selectionSquaresSpawner); newUnit.tag = "selectorSquare"; } } else { //there is no unit there and it is a moveable square selectionSquare = greenSelectionSquarePrefab; GameObject newUnit = Instantiate(selectionSquare, selectorCoord, Quaternion.identity, selectionSquaresSpawner); newUnit.tag = "selectorSquare"; possibleMovementCoords.Add(positionCoords); } } } } }