Workshop › Puzzle Bobble-style Bubble Shooter › Step 25 of 31
You win when the board is empty (plus 1000 points). You lose when any bubble hangs below the danger line near the shooter.
```js
const DANGER = 440 // a bubble below this line ends the game
let state // 'playing', 'won' or 'lost'
state = 'playing'
const cells = grid.flatMap((row, r2) => row.map((color2, c2) => ({ r: r2, c: c2, color: color2 })))
if (cells.every((cell) => cell.color < 0)) {
state = 'won'
score += 1000
} else if (cells.some((cell) => cell.color >= 0 && cellPos(cell.r, cell.c).y + R > DANGER)) state = 'lost'
```cells is every cell as { r, c, color }, in one list.every empty: won. Otherwise, some bubble whose bottom edge is below DANGER: lost.SPEED, write DANGER; under let drop, write let state; in reset, under drop = 0, write state = 'playing'.attach, under the drop line, write the check.Skills: Game states
← The ceiling comes down The danger line →