/** Imposta la cella corrente del giocatore * */ public void setCurrentCell(Cell currentCell) { this.curCell = currentCell; List<Vector3> positions = Token.gameObject.GetComponent<PlayerMover>().getPositionsByCell(currentCell); Token.gameObject.transform.position = positions[1]; currentCell.setTokensOnCell(currentCell.getTokensOnCell() + 1); }
public List<Vector3> getPositionsByCell(Cell cell) { List<Vector3> positions = new List<Vector3>(); Vector3 newHighPosition = new Vector3(); Vector3 newLowPosition = new Vector3(); // Ottengo l'oggetto da spostare GameObject Token = gameObject; // Controllo se c'e' qualche altro giocatore nella cella adiacente e in quella attuale. // In tal caso, lo spostamento sara' shiftato di 50m per ogni pedina in piu'. int endRefactorValue = cell.getTokensOnCell(); // Se la prossima cella e' d'angolo, mi comporto in una maniera if (cell.isCorner()) { if (cell.getSide() == 1) { float xValue = GameObject.FindWithTag(cell.getPosition().ToString()).transform.position.x; newLowPosition = new Vector3( 57, 0, 140 + (50 * endRefactorValue) ); newHighPosition = new Vector3( Token.transform.position.x - (Token.transform.position.x - newLowPosition.x) / 2, highnessValue, Token.transform.position.z ); } else if (cell.getSide() == 2) { float zValue = GameObject.FindWithTag(cell.getPosition().ToString()).transform.position.x; newLowPosition = new Vector3( 140 + (50 * endRefactorValue), 0, 1790 ); newHighPosition = new Vector3( Token.transform.position.x, highnessValue, Token.transform.position.z - (Token.transform.position.z - newLowPosition.z) / 2 ); } else if (cell.getSide() == 3) { float xValue = GameObject.FindWithTag(cell.getPosition().ToString()).transform.position.x; newLowPosition = new Vector3( 1790, 0, 1750 + (50 * endRefactorValue) ); newHighPosition = new Vector3( Token.transform.position.x - (Token.transform.position.x - newLowPosition.x) / 2, highnessValue, Token.transform.position.z ); } else if (cell.getSide() == 4) { float zValue = GameObject.FindWithTag(cell.getPosition().ToString()).transform.position.x; newLowPosition = new Vector3( 1710 + (50 * endRefactorValue), 0, 57 ); newHighPosition = new Vector3( Token.transform.position.x, highnessValue, Token.transform.position.z - (Token.transform.position.z - newLowPosition.z) / 2 ); } } // altrimenti faccio avanzare verso destra/sinistra/alto/basso normalmente else { // Se la cella si trova sul primo lato, devo diminuire le X di 150 +/- i refactors if (cell.getSide() == 1) { float xValue = GameObject.FindWithTag(cell.getPosition().ToString()).transform.position.x; newLowPosition = new Vector3( xValue + 100 - (50 * endRefactorValue), 0, 57 ); newHighPosition = new Vector3( Token.transform.position.x - (Token.transform.position.x - newLowPosition.x) / 2, highnessValue, 57 ); } else if (cell.getSide() == 2) { float zValue = GameObject.FindWithTag(cell.getPosition().ToString()).transform.position.z; newLowPosition = new Vector3( 57, 0, zValue + 50 + (50 * endRefactorValue) ); newHighPosition = new Vector3( 57, highnessValue, Token.transform.position.z - (Token.transform.position.z - newLowPosition.z) / 2 ); } else if (cell.getSide() == 3) { float xValue = GameObject.FindWithTag(cell.getPosition().ToString()).transform.position.x; newLowPosition = new Vector3( xValue + 40 + (50 * endRefactorValue), 0, 1790 ); newHighPosition = new Vector3( Token.transform.position.x - (Token.transform.position.x - newLowPosition.x) / 2, highnessValue, 1790 ); } else if (cell.getSide() == 4) { float zValue = GameObject.FindWithTag(cell.getPosition().ToString()).transform.position.z; newLowPosition = new Vector3( 1790, 0, zValue - 50 + (50 * endRefactorValue) ); newHighPosition = new Vector3( 1790, highnessValue, Token.transform.position.z - (Token.transform.position.z - newLowPosition.z) / 2 ); } } positions.Add(newHighPosition); positions.Add(newLowPosition); return positions; }