Workshop › Battleship › Step 3 of 35
Your own sea
What we are doing
Your own fleet sails on a second, smaller sea at the bottom, with a title above it. The same function draws it.
```js
const SMALL = 20 // cell size of your own sea
const HOME = { x: 30, y: 440 }
ctx.fillStyle = 'white'
ctx.font = 'bold 14px sans-serif'
ctx.fillText('Your fleet', HOME.x, HOME.y - 10)
drawSea(HOME, SMALL)
```
What it means
SMALL is the square size of your sea, HOME its top-left corner.
font sets the text size and typeface; fillText writes the title 10 pixels above your sea.
drawSea(HOME, SMALL) reuses the function for the second sea.
Your turn
- Under
const BIG write SMALL; under const SEA write HOME.
- At the very end, leave an empty line and write the four lines.
Skills: Drawing on a canvas
← A function for any sea Draw again and again →
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