Skip to content

Commit a9f56c8

Browse files
committed
新增檢測是否完成遊戲的功能
1 parent ebb9694 commit a9f56c8

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

script.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ let hasFlippedCard = false;
1414
let lockBoard = false;
1515
let firstCard, secondCard;
1616
let cardNum = 28;
17+
let mathedCard = 0;
1718
let gamemode=2;
1819
// 洗牌
1920
shuffle();
@@ -48,7 +49,18 @@ function disableCards() {
4849
// 匹配成功後移除點擊事件
4950
firstCard.closest('.show').classList="hide";
5051
secondCard.closest('.show').classList="hide";
51-
resetBoard();
52+
// 檢查是否完成遊戲
53+
mathedCard += 2;
54+
if (mathedCard === cardNum) {
55+
setTimeout(() => {
56+
alert("破關成功!");
57+
// 破關後重置遊戲
58+
resetGame();
59+
}, 500);
60+
} else {
61+
resetBoard();
62+
}
63+
5264
}
5365

5466
function unflipCards() {

0 commit comments

Comments
 (0)