Workshop › Klondike Solitaire › Step 17 of 40
In a column the cards overlap, so a point can be inside several of them. The one drawn last is on top, so we test from the last card down, and the first match wins.
```js
if (key[0] === 't') {
for (let i = pile.length - 1; i >= 0; i--) {
const cy = cardY(key, i)
if (y >= cy && y <= cy + CH) return { key, index: i }
}
} else if (y >= TOP_Y && y <= TOP_Y + CH) return { key, index: pile.length - 1 }
```i from the last card down to 0 and returns the first card whose rectangle contains y.else if handles the top row as before.In hit, replace the if (key[0] !== 't' && ...) line with the new lines.
Skills: Collision detection
← What is under the pointer? Tap the stock →