示例#1
0
    public HashSet <Hex> GetHexesWithinRange(Hex hex, int range)
    {
        HashSet <Hex> possibleHexes = new HashSet <Hex>();

        for (int x = -range; x <= range; x++)
        {
            for (int y = System.Math.Max(-x - range, -range); y <= System.Math.Min(-x + range, range); y++)
            {
                int       z             = -x - y;
                HexCoords tempHexCoords = new HexCoords(x, y, z);
                tempHexCoords.Add(hex.hexCoords);
                if (HexAtExists(tempHexCoords))
                {
                    possibleHexes.Add(GetHexAtCoords(tempHexCoords).GetComponent <Hex>());
                }
            }
        }
        return(possibleHexes);
    }