Atölye › Bilardo › 20/33. adım
İsteka topunu cebe sokmak bir fauldür: sana fazladan bir vuruşa mal olur. Her şey durunca isteka topu başlangıç noktasına geri gelir. O noktada başka bir top duruyorsa, yer bulana kadar biraz sola kayar.
```js
balls = balls.filter((b) => {
if (!pocketed(b)) return true
if (b.cue) shots += 1 // a scratch costs a shot
return false
})
// The cue ball comes back on its spot, or as close to it as there is room.
function respot() {
cue = ball(CUE_START.x, CUE_START.y, '#f8fafc', 0)
while (balls.some((b) => Math.hypot(b.x - cue.x, b.y - cue.y) < R * 2)) cue.x -= R
balls.unshift(cue)
}
if (!balls.includes(cue)) respot()
```filter içindeki fonksiyonun artık bir gövdesi var:if (!pocketed(b)) return true → cebe girmediyse kalsın.if (b.cue) shots += 1 → cebe giren isteka topuysa: faul, bir vuruş ekle.return false → cebe giren her top dizi dışında kalır.respot (yeniden yerleştir):cue = ball(...) → yeni bir isteka topu, başlangıç noktasında.while (koşul) cue.x -= R → while ("olduğu sürece") koşul doğru olduğu sürece tekrar eder: herhangi bir topla
iç içe olduğu sürece R kadar sola kay.balls.unshift(cue) → unshift dizinin başına ekler: isteka topu yine ilk top.update içinde if (!balls.includes(cue)) respot() → her şey durunca, balls isteka topunu içermiyorsa
(includes) onu geri getir.step içindeki filter satırını gövdeli hâliyle değiştir.function update() { satırının üstüne yorumuyla birlikte respot fonksiyonunu yaz; altında bir boş satır kalsın.update içinde if (moving) return ile state = 'aiming' satırlarının arasına respot satırını yaz.Beceriler: Oyun durumları