Workshop › Battleship › Step 13 of 35
A message line
What we are doing
A message above the sea tells the player what is going on. It lives in a variable, so any part of the game can change
it.
```js
let message
message = 'Your turn: pick a square'
ctx.fillStyle = 'white'
ctx.font = 'bold 16px sans-serif'
ctx.textAlign = 'left'
ctx.fillText(message, SEA.x, 34)
```
What it means
message is set in reset and drawn every frame above the enemy's sea.
textAlign = 'left' makes the point the left end of the text.
Your turn
- Under
let myShots ... write let message.
- In
reset, under myShots = grid(null), write the message line.
- In
draw, above drawSea(SEA, BIG, myShots), write the four text lines.
Skills: Drawing on a canvas, Game states
← Tap to fire Hit or miss? →
All steps
- A 10 by 10 sea
- A function for any sea
- Your own sea
- Draw again and again
- Grids and ships as lists
- A random fleet
- Two fleets
- Which ship is here?
- Fire at a square
- Show the shots
- Your shot
- Tap to fire
- A message line
- Hit or miss?
- See your own fleet
- Sinking ships
- Darker hits on a sunk ship
- Outline sunk ships
- Win in as few shots as you can
- A record of their shots
- Take turns
- The computer shoots back
- You can lose too
- A heat map
- Shoot the hottest square
- Hunt around a hit
- See the heat map
- H for heat
- Show their ships at the end
- A keyboard cursor
- Move with the arrows
- Fire with Enter, play again
- Your best game
- A side panel
- Build it yourself: ships apart