Workshop › Klondike Solitaire › Step 11 of 40

Fan out the columns

What we are doing

In a real game the cards of a column overlap: a face-down card shows a thin 8-pixel edge, a face-up one 22 pixels, enough to read it. cardY adds up the cards above to find each card's y.

```js
const DOWN_STEP = 8 // how much of a face-down card shows under the next one
const UP_STEP = 22

// The y of card `index` in a tableau column: face-down cards overlap more than face-up ones.
function cardY(key, index) {
  if (key[0] !== 't') return TOP_Y
  let y = TAB_Y
  const pile = piles[key]
  for (let i = 0; i < index; i++) y += pile[i].up ? UP_STEP : DOWN_STEP
  return y
}

    for (let i = first; i < pile.length; i++) drawCardAt(pile[i], x, cardY(key, i))
```

What it means

Your turn

  1. Under TAB_Y write DOWN_STEP and UP_STEP.
  2. Under pileX, leave an empty line and write cardY with its comment.
  3. In draw, replace the last argument of drawCardAt(...) with cardY(key, i). Press Run.

Skills: Functions, Drawing on a canvas

All steps

  1. The green table
  2. Draw one card
  3. The face of a card
  4. Red and black
  5. A deck of 52
  6. Shuffle
  7. Piles in one object
  8. Deal the seven columns
  9. A place for every pile
  10. Put the piles on the table
  11. Fan out the columns
  12. Outlines for empty places
  13. Turn over a card
  14. Space turns a card
  15. Go through the stock again
  16. What is under the pointer?
  17. Hitting a card in a column
  18. Tap the stock
  19. Rule 1: building a column
  20. Rule 2: building a foundation
  21. Move cards by the rules
  22. Turn over the uncovered card
  23. Find where a card goes
  24. Pick up a card
  25. Tap to move
  26. A move counter
  27. Count the moves
  28. Where did you grab it?
  29. Follow the pointer
  30. Draw the held cards at the pointer
  31. Drop it where you want
  32. Drop a king into an empty column
  33. A clock
  34. Winning
  35. You won!
  36. A new game
  37. The best time
  38. Snapshots of the table
  39. Undo
  40. Build it yourself: finish by itself