Workshop › Battleship › Step 21 of 35
Battleship is played in turns. After your shot it is the computer's turn, and a timer makes it wait half a second
before it shoots, so you can see what happens.
```js
const THINK = 30 // frames the computer waits before it shoots
let turn // 'you' or 'them'
let timer
turn = 'you'
if (state !== 'playing' || turn !== 'you' || myShots[r][c]) return
turn = 'them'
timer = THINK
```turn says whose turn it is; the game starts with yours.playerShoots refuses to shoot when it is not your turn.HOME, write THINK; under let theirShots, write turn and timer.reset, under theirShots = grid(null), write turn = 'you'.playerShoots, add turn !== 'you' || to the first line, and write the two lines at the end.Skills: Game states
← A record of their shots The computer shoots back →