Workshop › 2048 › Step 21 of 26

Win and lose screens

What we are doing

When the game is not playing, a see-through layer covers the board with a message: gold with You win!, or pale with Game Over.

```js
if (state !== 'playing') {
  ctx.fillStyle = state === 'won' ? 'rgba(237, 194, 46, 0.5)' : 'rgba(238, 228, 218, 0.75)'
  ctx.fillRect(0, TOP, canvas.width, canvas.width)
  ctx.fillStyle = state === 'won' ? '#f9f6f2' : '#776e65'
  ctx.font = 'bold 44px sans-serif'
  ctx.fillText(state === 'won' ? 'You win!' : 'Game Over', canvas.width / 2, TOP + 170)
  ctx.font = '18px sans-serif'
  ctx.fillText(state === 'won' ? 'Press Space to keep going' : 'Press Space to try again', canvas.width / 2, TOP + 220)
}
```

What it means

Your turn

At the end of draw, after the loops, leave an empty line and write the if block.

Skills: Drawing on a canvas

All steps

  1. The board
  2. Sixteen cells
  3. A grid of numbers
  4. A color for every number
  5. Numbers on the tiles
  6. Big numbers, smaller text
  7. Find the empty cells
  8. A new tile
  9. Two tiles to start
  10. Slide a row
  11. Merge equal tiles
  12. Move left
  13. The arrow key
  14. Only real moves count
  15. Right is left, reversed
  16. Up and down are columns
  17. Score
  18. Is there a move left?
  19. Game over
  20. Making 2048
  21. Win and lose screens
  22. Space to go on
  23. Best score
  24. Swipes
  25. A tap is not a swipe
  26. Build it yourself: undo