Workshop › Klondike Solitaire › Step 35 of 40
You won!
What we are doing
When the game is won, a dark panel in the middle says so, and the clock stops.
```js
if (won) {
ctx.fillStyle = 'rgba(15, 23, 42, 0.85)'
ctx.fillRect(60, 240, canvas.width - 120, 80)
ctx.fillStyle = 'white'
ctx.textAlign = 'center'
ctx.font = 'bold 22px sans-serif'
ctx.fillText('You won in ' + moves + ' moves!', canvas.width / 2, 275)
ctx.font = '15px sans-serif'
ctx.fillText('Tap for a new game', canvas.width / 2, 302)
}
function loop() {
if (!won) frames += 1
```
What it means
- The panel is 60 pixels in from each side (
canvas.width - 120 wide), 85% opaque dark blue.
- Both texts are centered on the canvas.
if (!won) in loop stops the clock.
Your turn
- In
draw, under the Moves text line, write the if (won) block.
- In
loop, put if (!won) in front of frames += 1.
Skills: Game states, Drawing on a canvas
← Winning A new game →
All steps
- The green table
- Draw one card
- The face of a card
- Red and black
- A deck of 52
- Shuffle
- Piles in one object
- Deal the seven columns
- A place for every pile
- Put the piles on the table
- Fan out the columns
- Outlines for empty places
- Turn over a card
- Space turns a card
- Go through the stock again
- What is under the pointer?
- Hitting a card in a column
- Tap the stock
- Rule 1: building a column
- Rule 2: building a foundation
- Move cards by the rules
- Turn over the uncovered card
- Find where a card goes
- Pick up a card
- Tap to move
- A move counter
- Count the moves
- Where did you grab it?
- Follow the pointer
- Draw the held cards at the pointer
- Drop it where you want
- Drop a king into an empty column
- A clock
- Winning
- You won!
- A new game
- The best time
- Snapshots of the table
- Undo
- Build it yourself: finish by itself