public void SelectGemTile(Vector3Int centerCubeCoordinates, GemType gemType)
    {
        var colouredBorderTile = gemType == GemType.Blue ? _blueBorderHexTile : _redBorderHexTile;

        SetTile(centerCubeCoordinates, colouredBorderTile);

        var neighbours = CoordinateUtils.Neighbours(centerCubeCoordinates)
                         .Where(_boardTilesCubeCoordinates.Contains).ToList();

        var jumpNeighbours = neighbours.SelectMany(CoordinateUtils.Neighbours)
                             .Where(cell => _boardTilesCubeCoordinates.Contains(cell) && !neighbours.Contains(cell) &&
                                    centerCubeCoordinates != cell);

        var emptyNeighbours     = neighbours.Where(cell => GemPlacementManager.Instance.GemTypeAt(cell) == GemType.None);
        var emptyJumpNeighbours = jumpNeighbours.Where(cell => GemPlacementManager.Instance.GemTypeAt(cell) == GemType.None);

        foreach (var cubeCoord in emptyNeighbours)
        {
            SetTile(cubeCoord, _borderHexTile);
        }
        foreach (var cubeCoord in emptyJumpNeighbours)
        {
            SetTile(cubeCoord, colouredBorderTile);
        }
    }
    public IEnumerator SwapGemsAround(GemType gemType, Vector3Int cubeCoordinates)
    {
        var neighboursToSwap = CoordinateUtils.Neighbours(cubeCoordinates)
                               .Where(n => {
            var gemTypeAt = GemTypeAt(n);
            return(gemTypeAt != GemType.None && gemTypeAt != gemType);
        })
                               .ToList();

        if (neighboursToSwap.Count <= 0)
        {
            yield break;
        }

        EffectsManager.Instance.PlayDisappearSound();
        foreach (var coroutine in neighboursToSwap.Select(n => StartCoroutine(RemoveGem(n))).ToList())
        {
            yield return(coroutine);
        }

        EffectsManager.Instance.PlayAppearSound();
        foreach (var coroutine in neighboursToSwap.Select(n => StartCoroutine(PutGem(gemType, n))).ToList())
        {
            yield return(coroutine);
        }
    }
    private bool CanMoveFrom(Vector3Int pos)
    {
        var neighbours = CoordinateUtils.Neighbours(pos).Where(GridManager.Instance.CellInBounds).ToList();

        if (neighbours.Any(n => GemPlacementManager.Instance.GemTypeAt(n) == GemType.None))
        {
            return(true);
        }

        var jumpNeighbours = neighbours.SelectMany(CoordinateUtils.Neighbours).Where(GridManager.Instance.CellInBounds);

        return(jumpNeighbours.Any(n => GemPlacementManager.Instance.GemTypeAt(n) == GemType.None));
    }
    private IEnumerator AnimateHexPins(Vector3Int cubeCoordinates)
    {
        var neighbours = CoordinateUtils.Neighbours(cubeCoordinates);

        var directions = neighbours.Where(n => GemPlacementManager.Instance.GemTypeAt(n) != GemType.None &&
                                          GemPlacementManager.Instance.GemTypeAt(n) != _currentPlayer)
                         .Select(n => CoordinateUtils.GetDirection(cubeCoordinates, n))
                         .ToList();

        if (directions.Count == 0)
        {
            yield return(null);
        }
        else
        {
            yield return(Instantiate(
                             _hexPinsPrefab,
                             GridManager.Instance.GetTileCenterPosition(cubeCoordinates),
                             Quaternion.identity)
                         .Animate(directions, _currentPlayer));
        }
    }
Esempio n. 5
0
 private List <Vector3Int> ValidNeighbours(Vector3Int cell)
 {
     return(CoordinateUtils.Neighbours(cell)
            .Where(Grid.Contains)
            .ToList());
 }