Atölye › Renk Hafızası (Simon) › 14/27. adım
Dizide birden çok tuş olunca hepsini sırayla göstermeliyiz. Bunu bir for döngüsüyle yapamayız: döngü bütün diziyi
tek bir karede bitirir, göz hiçbir şey görmez.
Bunun yerine gösteriyi birçok kareye yayarız: showAt sıradaki adımı hatırlar; her tuştan sonra zamanlayıcı yeniden
kurulur. Dizi bitince sıra oyuncuya geçer.
```js
let showAt // which step of the sequence is being shown, and when
showAt = 0
if (showAt === sequence.length) {
state = 'input'
return
}
// Light the next pad, then wait a little longer than it stays lit, so repeats are two separate flashes.
light(sequence[showAt], 30)
showAt += 1
timer = 30 + 8
```let showAt → dizinin sıradaki hangi adımının gösterileceği. nextRound içinde showAt = 0: baştan başla.if (showAt === sequence.length) { → bütün adımlar gösterildiyse...state = 'input' → ...sıra oyuncuda,return → ...ve çık.light(sequence[showAt], 30) → sıradaki tuşu 30 kare yak. sequence[showAt] dizinin showAt numaralı elemanı.showAt += 1 → bir sonraki adıma geç.timer = 30 + 8 → bir sonraki tuşa kadar 38 kare bekle.let state ... satırının altına let showAt ... satırını yaz.nextRound içinde state = 'showing' satırının altına showAt = 0 yaz.update'in sonundaki light(sequence[0], 30) ve state = 'input' satırlarını sil; yerine yeni satırları yaz.nextRound() satırını geçici olarak üç kez yaz. Sonra teke indir.Beceriler: Oyun durumları, Oyun döngüsü
← Bilgisayar bir tuş gösterir İzle, sonra sıra sende →