Workshop › Scorched Earth-style Artillery › Step 17 of 23
When a shot leaves a tank at 0 health the game is over: you win if it's the computer's tank, you lose if it's yours. A box says so, and Space starts a new game with new hills.
```js
function endTurn() {
if (tanks[1].hp === 0) state = 'won'
else if (tanks[0].hp === 0) state = 'lost'
else {
turn = 1 - turn
state = 'aiming'
if (turn === 1) thinking = 60
}
}
if (state === 'won' || state === 'lost') reset()
else if (turn === 0) fire()
if (state === 'won' || state === 'lost') {
ctx.fillStyle = 'rgba(15, 23, 42, 0.8)'
ctx.fillRect(140, 110, 280, 80)
ctx.fillStyle = 'white'
ctx.textAlign = 'center'
ctx.font = 'bold 22px sans-serif'
ctx.fillText(state === 'won' ? 'You win!' : 'You lose', W / 2, 145)
ctx.font = '15px sans-serif'
ctx.fillText('Space or tap to play again', W / 2, 172)
}
```'won' and 'lost' nothing flies, aims or thinks, so the game waits for Space.endTurn with the win and lose checks first.draw, draw the game-over box.Skills: Game states