Exemple #1
0
    // 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);
    }
Exemple #2
0
    // 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;
    }
Exemple #3
0
    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);
    }
Exemple #4
0
 public CursorOnHighlightedTile(Tileable tile, TileStatesFactory stateGenerator)
 {
     this.tile = tile;
     states    = stateGenerator;
 }
Exemple #5
0
 public TileIdle(Tileable tile, TileStatesFactory stateGenerator)
 {
     this.tile = tile;
     states    = stateGenerator;
 }
Exemple #6
0
 public TileHighlighted(Tileable tile, TileStatesFactory stateGenerator)
 {
     this.tile = tile;
     states    = stateGenerator;
 }
Exemple #7
0
 // 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();
 }