需求: 做一个棋盘上是方块的消除游戏,移动方块,方块达到要求消除方块?
逻辑:方块移动(播放移动动画)=》满足消除要求(播放消除动画)=》填补方块(播放填补动画)=》满足消除要求(播放消除动画)
问题:逻辑是顺序的,但是动画是异步的;希望的是动画也是同步处理逻辑;但是实际用await 也不是同步逻辑;请问请问是否哪里有问题?
实际执行顺序为 updateBoard=>matchHandle=>removePieces=>upOffset
希望执行顺序为:updateBoard=>matchHandle=>removePieces=>dropLine=》upOffset
main()
{
await updateBoard();
await this.upOffset();
if (isFinish()) {
this.result()
} else {
await updateBoard();
}
}
function upOffset(){
//填补逻辑
}
export async function updateBoard() {
await updateBoardFor();
}
async function updateBoardFor() {
await matchHandle();
let dropBool = await dropPieces();
if (!dropBool) return;
updateBoardFor();
}
async function matchHandle() {
let matchesRow = checkForMatches();
if (matchesRow >= 0) {
await removePieces(matchesRow);
await dropLine(matchesRow);
matchHandle();
}
}