# Is there any way to get all connected tiles?

**URL:** <https://forum.makecode.com/t/is-there-any-way-to-get-all-connected-tiles/21294>\
**Category:** Help\
**Created:** [July 17, 2023, 4:39pm UTC](https://forum.makecode.com/t/is-there-any-way-to-get-all-connected-tiles/21294 "2023-07-17T16:39:04Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![MrNoahMango](https://avatars.discourse-cdn.com/v4/letter/m/9e8a1a/32.png) [@MrNoahMango](https://forum.makecode.com/u/MrNoahMango)\
**Post date:** [July 17, 2023, 4:39pm UTC](https://forum.makecode.com/t/is-there-any-way-to-get-all-connected-tiles/21294/1 "2023-07-17T16:39:04Z")

</div>

i am making a minesweeper game and need a way to get a list of all connected tiles and then destroy all sprites of a certain type on those tiles.

---

<div class="post-metadata">

**Author:** ![YuHayate](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/yuhayate/32/8275_2.png) [@YuHayate](https://forum.makecode.com/u/YuHayate)\
**Post date:** [July 20, 2023, 10:45pm UTC](https://forum.makecode.com/t/is-there-any-way-to-get-all-connected-tiles/21294/2 "2023-07-20T22:45:07Z")

</div>

well… i have an idea but it might not work super fast  
so here is my idea, set the tile you want to start to a certain tile  
then use a while loop with`(tilesAdded != 0)`  
then in the loop put `tilesAdded = 0`  
then add a for loop and check all four sides to see if the correct is there and set that tile to (your temporary tile) and run `tilesAdded++` or in other words modify tilesAdded of one  
then after the loop set all tiles (your temporary tile) to the correct tile

```auto
tiles.setTileAt((x,y), (your temporary tile))
while (tilesAdded != 0) {
    let ilesAdded = 0
    for (let valeur of tiles.getTilesByType(`myTile`)) {
        if (tiles.tileAtLocationEquals(valeur.getNeighboringLocation(CollisionDirection.Left), (the tile you ar looking for))) {
            tiles.setTileAt(valeur.getNeighboringLocation(CollisionDirection.Left), (your temporary tile))
            tilesAdded += 1
        }
        if (tiles.tileAtLocationEquals(valeur.getNeighboringLocation(CollisionDirection.Right), (the tile you ar looking for))) {
            tiles.setTileAt(valeur.getNeighboringLocation(CollisionDirection.Right), (your temporary tile))
            tilesAdded += 1
        }
        if (tiles.tileAtLocationEquals(valeur.getNeighboringLocation(CollisionDirection.Top), (the tile you ar looking for))) {
            tiles.setTileAt(valeur.getNeighboringLocation(CollisionDirection.Top), (your temporary tile))
            tilesAdded += 1
        }
        if (tiles.tileAtLocationEquals(valeur.getNeighboringLocation(CollisionDirection.Bottom), (the tile you ar looking for))) {
            tiles.setTileAt(valeur.getNeighboringLocation(CollisionDirection.Bottom), (your temporary tile))
            tilesAdded += 1
        }
    }
}
for (let valeur of tiles.getTilesByType((your temporary tile))) {
    tiles.setTileAt(valeur.getNeighboringLocation(CollisionDirection.Left), (the tile you want))
}

```
