Esempio n. 1
0
        private bool TryCreateConnectionToModule(Module module, FieldTile tile, List <FieldTile> unavailable)
        {
            if (unavailable.Contains(tile))
            {
                return(false);
            }
            else
            {
                unavailable.Add(tile);
            }

            ConnectionModule connection = tile.TileType == FieldTile.eTileType.Connection ? tile.GetConnectionModule(_ConnectionModules) : CreateConnectionModuleAtPosition(tile.Position);

            if (connection != null)
            {
                if (connection.IsConnected(module.Bounds))
                {
                    return(true);
                }
                else
                {
                    List <FieldTile> tiles = tile.GetAdjacentTilesOfType(FieldTiles, FieldTile.eTileType.Empty, FieldTile.eTileType.Connection);

                    tiles.Sort((x, y) => x.GetDistanceToCenterOfModule(module).CompareTo(y.GetDistanceToCenterOfModule(module)));

                    foreach (FieldTile t in tiles)
                    {
                        if (TryCreateConnectionToModule(module, t, unavailable))
                        {
                            return(true);
                        }
                    }
                }
            }

            return(false);
        }