|
@@ -193,27 +193,33 @@ class Board {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- this.actionQueue.execute(SpawnTileAction, (x, y) => this.spawnTile(x, y)).then(() => {
|
|
|
- for (let x = 0; x < this.boardSize.x; x++) {
|
|
|
- const columnTiles = this.tiles.filter((tile) => tile.position.x == x).sort((tileA, tileB) => tileA.position.y < tileB.position.y)
|
|
|
+ this.collapse()
|
|
|
|
|
|
- let bottom = this.boardSize.y
|
|
|
- columnTiles.forEach((tile, index) => {
|
|
|
- if (tile.position.y < bottom) {
|
|
|
- bottom -= 1
|
|
|
- this.actionQueue.push(new TileFallAction(tile, bottom))
|
|
|
-
|
|
|
- }
|
|
|
- })
|
|
|
- }
|
|
|
-
|
|
|
- this.actionQueue.execute(TileFallAction).then(() => {
|
|
|
+ this.actionQueue.execute(SpawnTileAction, (x, y) => this.spawnTile(x, y)).then(() => {
|
|
|
+ this.collapse().then(() => {
|
|
|
this.checkForMatches()
|
|
|
})
|
|
|
})
|
|
|
|
|
|
|
|
|
}
|
|
|
+
|
|
|
+ collapse() {
|
|
|
+ for (let x = 0; x < this.boardSize.x; x++) {
|
|
|
+ const columnTiles = this.tiles.filter((tile) => tile.position.x == x).sort((tileA, tileB) => tileA.position.y < tileB.position.y)
|
|
|
+
|
|
|
+ let bottom = this.boardSize.y
|
|
|
+ columnTiles.forEach((tile, index) => {
|
|
|
+ if (tile.position.y < bottom) {
|
|
|
+ bottom -= 1
|
|
|
+ this.actionQueue.push(new TileFallAction(tile, bottom))
|
|
|
+
|
|
|
+ }
|
|
|
+ })
|
|
|
+ }
|
|
|
+
|
|
|
+ return this.actionQueue.execute(TileFallAction)
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
Board.TILE_PADDING = 4
|