krz/daybyday

iOS learning games for young children: days, months, seasons, numbers, letters, animals and more. education ios kids swift https://krz.sh/apps/daybyday/

DayByDay/Quiz/MovesRound.swift

062549ad26607ce9e973ed2a9a7ef6f853885f83
daybyday/DayByDay/Quiz/MovesRound.swift history · blame · raw

43 lines · 1236 bytes

1 symbol in this file
  • next function, line 40
 1//
 2//  MovesRound.swift
 3//  DayByDay
 4//
 5
 6nonisolated extension LearnBodyPart {
 7    /// Something to do with this part, said aloud.
 8    var command: String {
 9        switch self {
10        case .head:    "Touch your head!"
11        case .eyes:    "Blink your eyes!"
12        case .ears:    "Touch your ears!"
13        case .nose:    "Touch your nose!"
14        case .mouth:   "Point to your mouth!"
15        case .hands:   "Clap your hands!"
16        case .fingers: "Wiggle your fingers!"
17        case .arms:    "Wave your arms!"
18        case .legs:    "March in place!"
19        case .feet:    "Stomp your feet!"
20        case .heart:   "Put your hand on your heart!"
21        case .belly:   "Pat your belly!"
22        }
23    }
24}
25
26/// Five different moves, one after another.
27nonisolated struct MovesRound {
28    static let length = 5
29
30    let parts: [LearnBodyPart]
31    private(set) var index = 0
32
33    init(using rng: inout some RandomNumberGenerator) {
34        parts = Array(LearnBodyPart.allCases.shuffled(using: &rng).prefix(Self.length))
35    }
36
37    var current: LearnBodyPart? { index < parts.count ? parts[index] : nil }
38    var isDone: Bool { current == nil }
39
40    mutating func next() {
41        if index < parts.count { index += 1 }
42    }
43}