void checkGameResult() {
if (currentHeight >= TARGET_HEIGHT) {
if (isStable()) {
showDialog("成功!得分:" + score);
saveHighScore(score);
} else {
startFallAnimation(() -> showDialog("倒塌了!"));
}
} else if (timeUp) {
showDialog("時間到,高度不夠");
}
}
boolean isStable() {
float centerX = calculateCenterX();
float baseLeft = baseRect.left, baseRight = baseRect.right;
return centerX > baseLeft && centerX < baseRight;
}
遊戲循環運行在渲染線程,判定結果需 runOnUiThread 或 Handler.post 彈出對話框,避免 ANR。