Learn by Building Workshop Skills GitHub Türkçe Workshop › Klondike Solitaire › Step 28 of 40
Where did you grab it? What we are doing Sometimes you want a different place than the one a tap picks, so cards can also be dragged. First, drag remembers where
the card was grabbed: dx, dy, the pointer's offset from the card's corner, and the pointer itself, x, y.
```js
const cx = pileX(h.key)
const cy = cardY(h.key, h.index)
drag = { from: h.key, index: h.index, dx: p.x - cx, dy: p.y - cy, x: p.x, y: p.y, moved: false }
```What it means
cx, cy is the held card's top-left corner.
dx, dy is how far the pointer is from that corner; it stays the same while dragging.
x, y is where the pointer is now; moved will tell a drag from a tap.
Your turn In the pointerdown listener, replace the last line (drag = { from: h.key, index: h.index }) with the three lines.
Skills: Keyboard and mouse input
← Count the moves Follow the pointer →
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