Workshop › Minesweeper › Step 9 of 26
reveal(cell) opens a cell. The very first reveal also places the mines around it and starts the game: a state goes
from 'ready' to 'playing'.
```js
let state // 'ready' (before the first click), 'playing', 'won' or 'lost'
function newGame() {
grid = Array.from({ length: SIZE }, (_, row) =>
Array.from({ length: SIZE }, (_, col) => ({ row, col, mine: false, count: 0, revealed: false })),
)
state = 'ready'
}
function reveal(start) {
if (start.revealed) return
if (state === 'ready') {
placeMines(start)
state = 'playing'
}
start.revealed = true
}
```revealed: false; every new game starts 'ready'.return right away.newGame, add revealed: false to the cell, and write state = 'ready' at the end.let grid, write let state ....placeMines, leave an empty line and write reveal. Press Run.Skills: Game states
← Count the mines around Open cells look different →