/// <summary>
    /// Checks if adjacent neighbors have the same color as this one.
    /// </summary>
    /// <returns>Adjacent neighbors with same color. (Includes himself!)</returns>
    public List <HexagonController> GetAdjacentNeighborsWithSameColor()
    {
        var matches = new List <HexagonController>();
        var values  = Enum.GetValues(typeof(Direction)).Cast <Direction>().ToList();

        for (var i = 0; i < values.Count; i++)
        {
            var firstDir  = values[i];
            var secondDir = i == values.Count - 1 ? values[0] : values[i + 1];

            var firstController =
                HexagonManager.Instance.GetHexagonController(Identifier + ConvertDirectionToIdentifier(firstDir));
            var secondController =
                HexagonManager.Instance.GetHexagonController(Identifier + ConvertDirectionToIdentifier(secondDir));

            if (firstController && secondController &&
                ColorManager.CompareColors(firstController.Color, secondController.Color, Color))
            {
                matches.Add(firstController);
                matches.Add(secondController);
            }
        }

        matches.Add(this);
        return(matches);
    }
Example #2
0
    public List <HexagonController> GetControllersToDestroy()
    {
        var hexagonsToDestroy = HexagonManager.Instance.HexagonControllers
                                .Where(controller => ColorManager.CompareColors(controller.Color, Color)).ToList();

        hexagonsToDestroy.Add(this);
        return(hexagonsToDestroy);
    }
    /// <summary>
    /// Checks neighbor hexagons and returns a list of excluded colors
    /// to prevent points at start.
    /// </summary>
    /// <returns>Excluded colors</returns>
    public List <Color> GetColorsToExclude()
    {
        var colorsToExclude = new List <Color>();
        var neighborhoods   = FindAllNeighborhoodControllers();

        for (var i = 0; i < neighborhoods.Count; i++)
        {
            var first  = neighborhoods[i];
            var second = i == neighborhoods.Count - 1 ? neighborhoods[0] : neighborhoods[i + 1];

            if (ColorManager.CompareColors(first.Color, second.Color))
            {
                colorsToExclude.Add(first.Color);
            }
        }

        return(colorsToExclude);
    }