// Returns the manhattan distance between two tiles private int CalculateManhattanDist(Tileable destination, Tileable origin) { int xDifference = Math.Abs((int)(destination.GetXLocation() - origin.GetXLocation())); int yDifference = Math.Abs((int)(destination.GetYLocation() - origin.GetYLocation())); return(xDifference + yDifference); }
// Must be called before the tile has it's location updated private void RecordTileMovement(Tileable itemToMove) { // Make the tile the item is moving from empty int previousItemX = RoundXCoordToInt(itemToMove.GetXLocation()); int previousItemY = RoundYCoordToPosInt(itemToMove.GetYLocation()); int newColumn = RoundXCoordToInt(itemToMove.GetFutureXLocation()); int newRow = RoundYCoordToPosInt(itemToMove.GetFutureYLocation()); gameBoard[previousItemX, previousItemY] = emptyBoardTiles[previousItemX, previousItemY]; // Give tile new location on gameboard gameBoard[newColumn, newRow] = itemToMove; }
public GameObject render(Tileable tileManager, Transform parent, clickViews callbacks) { _tileCB = callbacks.contextViewCallback; var Holder = new GameObject("grid"); Holder.transform.SetParent(parent); var grid = Holder.AddComponent <GridLayoutGroup>(); var rect = Holder.GetComponent <RectTransform>(); rect.anchorMin = Vector2.zero; rect.anchorMax = Vector2.one; rect.offsetMax = Vector2.zero; rect.offsetMin = Vector2.zero; var height = rect.rect.height; var width = rect.rect.width; var tileDimHeight = height / tileManager.state.height; var tileDimWidth = width / tileManager.state.width; var tileDim = tileDimHeight < tileDimWidth ? tileDimHeight : tileDimWidth; rect.rect.Set(0, 0, tileDim * tileManager.state.width, tileDim); grid.cellSize = new Vector2(tileDim, tileDim); Holder.AddComponent <AspectRatioFitter>().aspectMode = UnityEngine.UI.AspectRatioFitter.AspectMode.FitInParent; grid.constraint = GridLayoutGroup.Constraint.FixedColumnCount; grid.constraintCount = tileManager.state.width; grid.childAlignment = TextAnchor.UpperCenter; foreach (var tile in tileManager.state.tiles) { tile.value.renderIcon(callbacks) .transform.SetParent(Holder.transform); } return(Holder); }
public CursorOnHighlightedTile(Tileable tile, TileStatesFactory stateGenerator) { this.tile = tile; states = stateGenerator; }
public TileIdle(Tileable tile, TileStatesFactory stateGenerator) { this.tile = tile; states = stateGenerator; }
public TileHighlighted(Tileable tile, TileStatesFactory stateGenerator) { this.tile = tile; states = stateGenerator; }
// Moves a unit to a tile, resets any highlights, checks for end game public void MoveUnitToTile(Tileable destination) { unitToMove.SetLocation(destination.GetXLocation(), destination.GetYLocation(), unitToMove.GetZLocation()); ResetHighlightedTiles(); CheckForEndGame(); }