Example #1
0
    private List <GameTile> GetTilesWithinRangeOfWater()
    {
        //return a list of floor tiles that are within 3 tiles of a waters edge, this means these tiles are valid for spawning live grass
        int validRangeFromWater = 3;         //TODO: public facing

        board.UnMarkAllTiles();
        List <GameTile> waterTiles      = new List <GameTile>();
        List <GameTile> edgeWaterTiles  = new List <GameTile>();
        List <GameTile> validFloorTiles = new List <GameTile>();

        for (int x = 0; x < board.GetCols(); x++)
        {
            for (int y = 0; y < board.GetRows(); y++)
            {
                if (board.GetGrid()[x][y].GetObject() != null && board.GetGrid()[x][y].GetObject().GetComponent <WaterTile>() != null)
                {
                    waterTiles.Add(board.GetGrid()[x][y]);
                }
            }
        }
        foreach (GameTile tile in waterTiles)
        {
            List <GameTile> possibleFloorTiles = board.GetTileCardinalNeighbours(tile);
            foreach (GameTile possibleFloortile in possibleFloorTiles)
            {
                if (possibleFloortile.OpenForPlacement())
                {
                    edgeWaterTiles.Add(possibleFloortile);
                }
            }
        }
        foreach (GameTile tile in edgeWaterTiles)
        {
            List <GameTile> possibleValidFloorTiles = board.GetAllTilesInRange(tile, validRangeFromWater);
            foreach (GameTile possibleValidFloorTile in possibleValidFloorTiles)
            {
                if (possibleValidFloorTile.OpenForPlacement())
                {
                    validFloorTiles.Add(possibleValidFloorTile);
                }
            }
        }
        board.UnMarkAllTiles();
        return(validFloorTiles);
    }