Esempio n. 1
0
    private static TileCoords GetNewTileWhenLeavingPentagon(TileCoords currentPenta, TileCoords currentFacing, HexDirection hexDirection, PentagonTraversalStrategy strategy)
    {
        PentaDirection pentaDirection = PentaDirection.Forward;//default

        if (strategy == PentagonTraversalStrategy.LeanLeft)
        {
            switch (hexDirection)
            {
            case HexDirection.Forward:
                pentaDirection = PentaDirection.Forward;
                break;

            case HexDirection.ForwardRight:
                pentaDirection = PentaDirection.ForwardRight;
                break;

            case HexDirection.BackwardRight:
                pentaDirection = PentaDirection.BackwardRight;
                break;

            case HexDirection.Backward:
            case HexDirection.BackwardLeft:
                pentaDirection = PentaDirection.BackwardLeft;
                break;

            case HexDirection.ForwardLeft:
                pentaDirection = PentaDirection.ForwardLeft;
                break;
            }
        }
        else
        {
            pentaDirection = PentaDirection.Forward;
        }
        return(HexMapHelper.GetTileInPentaDirection(currentPenta, currentFacing, pentaDirection));
    }
Esempio n. 2
0
    public static TileCoords GetTileInPentaDirection(TileCoords startTile, TileCoords startFacing, PentaDirection direction)
    {
        Tile tile = instance.baseHexasphere.tiles[startTile.index];

        if (tile.neighbours.Length == 5)
        {
            //count tiles until we find the current facing
            for (int neighborIndex = 0; neighborIndex < tile.neighbours.Length; neighborIndex++)
            {
                Tile neighborTile = tile.neighbours[neighborIndex];
                if (neighborTile.index == startFacing.index)
                {
                    return(new TileCoords {
                        index = tile.neighbours[(neighborIndex + (int)direction) % 5].index
                    });
                }
            }
            throw new Exception("Failed to Find Neighbor");
        }
        else
        {
            throw new Exception("The startTile is not a Pentagon. Use GetTileInHexDirection instead.");
        }
    }