Пример #1
0
def ready(now):
    pixels.fill(OFF)
    k = int(now) % 2
    for color, idx in OPTIONS.values():
        pixels[idx] = color if k else OFF
    after(0.2, ready)
    pixels.show()
Пример #2
0
def ready(now):
    pixels.fill(OFF)
    k = int(now) % 2
    for color, idx in OPTIONS.values():
        pixels[idx] = color if k else OFF
    after(0.2, ready)
    pixels.show()
Пример #3
0
def finish(now):
    pixels.fill(OFF)
    for idx, value in enumerate(state.results):
        if value:
            pixels[idx] = REWARD[value]
    pixels.show()

    state.reset()
    after(3, main)
Пример #4
0
def finish(now):
    pixels.fill(OFF)
    for idx, value in enumerate(State.results):
        if value:
            pixels[idx] = REWARD[value] 
    pixels.show()

    State.reset()
    after(3, main)
Пример #5
0
def play(now):
    if not state.ready:
        return

    good = 1 if state.pos == 7 else 0
    pixels.fill(REWARD[good])
    pixels[state.pos] = REWARD[not good]
    pixels.show()

    state.results[state.round] = good
    state.round += 1
    state.pos = random.randint(0, 9)

    after(0.5, main)
Пример #6
0
def play(now):
    if not State.ready:
        return

    good = 1 if State.pos == 7 else 0
    pixels.fill(REWARD[good])
    pixels[State.pos] = REWARD[not good]
    pixels.show()

    State.results[State.round] = good
    State.round += 1
    State.pos = random.randint(0, 9)

    after(0.5, main)
Пример #7
0
def main(now):
    if not state.ready:
        pixels.fill(OFF)
        pixels[2] = FLASH[int(now) % 2]
        pixels.show()
        return after(0.1, main)

    if state.round >= ROUNDS:
        return after(0, finish)

    after(SPEEDS[state.round], main)
    state.pos += 1
    if state.pos >= 10:
        state.pos = 0

    render()
Пример #8
0
def main(now):
    if not State.ready:
        pixels.fill(OFF)
        pixels[2] = FLASH[int(now) % 2]
        pixels.show()
        return after(0.1, main)

    if State.round >= ROUNDS:
        return after(0, finish)

    after(SPEEDS[State.round], main)
    State.pos += 1
    if State.pos >= 10:
        State.pos = 0

    render()
Пример #9
0
def fail(now):
    print("fail")
    state.phase = FAIL
    pixels.fill(RED)
    pixels.show()
    if state.pos < 1:
        after(0.5, clear)
        after(1, fail)
        state.pos = 1
    else:
        after(0.5, clear)
        after(1, begin)
Пример #10
0
def fail(now):
    print("fail")
    state.phase = FAIL
    pixels.fill(RED)
    pixels.show()
    if state.pos < 1:
        after(0.5, clear)
        after(1, fail)
        state.pos = 1
    else:
        after(0.5, clear)
        after(1, begin)
Пример #11
0
def show(now):
    if state.pos < len(state.sequence):
        name = state.sequence[state.pos]
        print("show {}".format(name))
        render(name)

        state.pos += 1
        after(0.5, clear)
        after(0.75, show)
    else:
        clear()
        state.watch()
        after(TIMEOUT, fail)
Пример #12
0
def show(now):
    if state.pos < len(state.sequence):
        name = state.sequence[state.pos]
        print("show {}".format(name))
        render(name)

        state.pos += 1
        after(0.5, clear)
        after(0.75, show)
    else:
        clear()
        state.watch()
        after(TIMEOUT, fail)
Пример #13
0
def press(now, color):
    if state.phase == READY:
        state.begin()
        cancel(ready)
        render(color, sound=False)
        after(0.1, clear)
        after(1, show)

    elif state.phase == WATCH:
        if color == state.sequence[state.pos]:
            render(color)
            after(0.5, clear)
            state.pos += 1
            if state.pos == len(state.sequence):
                state.show()
                after(1, show)
                cancel(fail)
            else:
                after(TIMEOUT, fail)
        else:
            after(0, fail)
Пример #14
0
def begin(now):
    state.reset()
    enable_speaker(state.sound)
    after(0.5, ready)
    print("ready")
Пример #15
0
def begin(now):
    state.reset()
    enable_speaker(state.sound)
    after(0.5, ready)
    print("ready")
Пример #16
0
def press(now, color):
    if state.phase == READY:
        state.begin()
        cancel(ready)
        render(color, sound=False)
        after(0.1, clear)
        after(1, show)

    elif state.phase == WATCH:
        if color == state.sequence[state.pos]:
            render(color)
            after(0.5, clear)
            state.pos += 1
            if state.pos == len(state.sequence):
                state.show()
                after(1, show)
                cancel(fail)
            else:
                after(TIMEOUT, fail)
        else:
            after(0, fail)