Atölye › Candy Crush Tarzı Üçlü Eşleştirme › 25/29. adım
İpucunun iki mücevheri sarı çerçeveyle gösterilsin; seçim yine beyaz. Üç ayrı if bloğu yazmak yerine üç
[hücre, renk] çiftini bir listeye koyup tek döngüyle çiziyoruz; hücre yoksa atlıyoruz.
```js
// Outline the selected gem, and after five idle seconds, a possible move.
ctx.lineWidth = 3
for (const [cell, color] of [[selected, '#ffffff'], [hint && hint.a, '#fde047'], [hint && hint.b, '#fde047']]) {
if (!cell) continue
ctx.strokeStyle = color
ctx.strokeRect(LEFT + cell.c * SIZE + 2, TOP + cell.r * SIZE + 2, SIZE - 4, SIZE - 4)
}
```[[selected, '#ffffff'], [hint && hint.a, '#fde047'], [hint && hint.b, '#fde047']] → üç çiftlik liste: seçim beyaz,
ipucunun iki hücresi sarı.hint && hint.a → ipucu varsa onun a'sı, yoksa null. İpucu yokken hint.a yazmak hata verirdi; && soldaki
yanlışsa sağa hiç bakmaz.for (const [cell, color] of ...) → her çifti açıp cell ve color adlarıyla al.if (!cell) continue → hücre yoksa atla.strokeRect artık selected yerine cell ile çiziyor.draw içindeki if (selected) { ... } bloğunun tamamını sil; yerine yorum satırını, lineWidth satırını ve
döngüyü yaz.Beceriler: Canvas üzerine çizim, Diziler ve nesneler
← Beş saniye sonra ipucu Yirmi hamle →