Atölye › Frogger Tarzı Karşıya Geçiş › 10/22. adım
Kurbağanın üç canı var. Her çarpma bir can götürür; son can da gidince oyun biter: hiçbir şey hareket etmez, tahtanın üstüne bir mesaj gelir.
```js
let lives = 3
let state = 'playing' // 'playing' or 'over'
function die() {
lives -= 1
if (lives > 0) {
newFrog()
return
}
state = 'over'
}
if (state !== 'playing') return
ctx.fillStyle = 'white'
ctx.font = 'bold 18px sans-serif'
ctx.textAlign = 'right'
ctx.fillText('Lives: ' + lives, canvas.width - 10, 27)
if (state === 'over') {
ctx.fillStyle = 'rgba(15, 23, 42, 0.75)'
ctx.fillRect(0, 0, canvas.width, canvas.height)
ctx.fillStyle = 'white'
ctx.textAlign = 'center'
ctx.font = 'bold 32px sans-serif'
ctx.fillText('Game Over', canvas.width / 2, canvas.height / 2)
ctx.font = '18px sans-serif'
ctx.fillText('Press Space to play again', canvas.width / 2, canvas.height / 2 + 32)
}
```let lives = 3, let state = 'playing' → can sayısı ve oyunun durumu.die() → lives -= 1; can kaldıysa yeni kurbağa ve return. Kalmadıysa state = 'over'.hop ve update başında if (state !== 'playing') return → oyun bitince zıplama da trafik de durur.Lives: 2 gibi yazı.if (state === 'over') → bütün tuvali kaplayan %75 koyu, yarı saydam bir perde; üstüne ortalanmış "Game Over" ve Boşluk ile yeniden oynama yazısı.frog satırının altına lives ve state satırlarını yaz.die fonksiyonunun içini yeni satırlarla değiştir.hop ve update fonksiyonlarının ilk satırı if (state !== 'playing') return olsun.draw'ın sonuna, kurbağayı çizen satırın altına can yazısını ve bitiş bloğunu yaz.Beceriler: Oyun durumları