我正在製作一個非常簡單的html5帆布遊戲。我希望這樣做,當玩家失去全部3條生命時,遊戲重置。如何編寫一個循環來檢查生命=== 0?
我在想我可以做一個while循環,它總是檢查生命=== 0然後運行一個函數,但是這打破了遊戲,沒有任何東西出現在畫布上。
這是我的代碼。
var lives = 3;
while (lives <= 0) {
var fullReset = function() {
// Throw the monster somewhere on the screen randomly
monster.x = 1 + (Math.random() * (canvas.width - 64));
monster.y = 1 + (Math.random() * (canvas.height - 64));
monster2.x = 1 + (Math.random() * (canvas.width - 100));
monster2.y = 1 + (Math.random() * (canvas.height - 100));
// player start again
hero.x = canvas.width/2;
hero.y = canvas.height/2;
//score resets
monstersCaught() = 0;
lives() = 3;
}
fullReset();
}
如果(住=== 0) – prgrm