فهرست منبع

spawning and collapsing at the same time

Justin Gilman 1 سال پیش
والد
کامیت
e269b91942
1فایلهای تغییر یافته به همراه20 افزوده شده و 14 حذف شده
  1. 20 14
      js/libraries/components/matchthree/Board.js

+ 20 - 14
js/libraries/components/matchthree/Board.js

@@ -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