コード例 #1
0
    protected virtual async SysTask KnightSwapTask(TileController firstTile, TileController secondTile)
    {
        Vector2Int travelVec = secondTile.BoardPos - firstTile.BoardPos;

        // Pull off all the horizontal swaps before the vertical ones
        while (travelVec.x != 0)
        {
            // Find the appropriate adjacent tile, swap the first one with it, and update
            // the travelVec accordingly.
            int        xOffset      = (int)Mathf.Sign(travelVec.x);
            Vector2Int otherTilePos = firstTile.BoardPos;
            otherTilePos.x += xOffset;
            TileController toSwapWith = tileBoard.GetTileAt(otherTilePos);

            await AdjacentSwapTask(firstTile, toSwapWith);

            travelVec.x -= xOffset; // Bring the value closer to 0
        }

        // Similar logic for the vertical swaps
        while (travelVec.y != 0)
        {
            int        xOffset      = (int)Mathf.Sign(travelVec.y);
            Vector2Int otherTilePos = firstTile.BoardPos;
            otherTilePos.y += xOffset;
            TileController toSwapWith = tileBoard.GetTileAt(otherTilePos);

            await AdjacentSwapTask(firstTile, toSwapWith);

            travelVec.y -= xOffset;
        }
    }
コード例 #2
0
    IList <TileController> GetValidTilesAtPositions(IList <Vector2Int> tilePositions)
    {
        IList <TileController> validTiles = new List <TileController>();

        foreach (Vector2Int position in tilePositions)
        {
            TileController tile = gameBoard.GetTileAt(position);
            if (TileIsValid(tile))
            {
                validTiles.Add(tile);
            }
        }

        return(validTiles);
    }