# Look after a micro:bit pet: a free micro:bit lesson from Maze Education
# https://maze.education/microbit/lessons/microbit-pet
# MicroPython for the micro:bit Python Editor: https://python.microbit.org

# Look after a micro:bit pet: A feeds, B plays, the logo strokes, and both numbers drop every six seconds (micro:bit V2).
from microbit import *

food = 6
happy = 6
last_drop = running_time()

while True:
    if button_a.was_pressed():
        food = min(food + 3, 9)
        display.show(Image.SURPRISED)
        sleep(500)
    if button_b.was_pressed():
        happy = min(happy + 3, 9)
        display.show(Image.RABBIT)
        sleep(500)
    if pin_logo.is_touched():
        happy = min(happy + 1, 9)
        display.show(Image.HEART)
        sleep(500)
    if running_time() - last_drop > 6000:
        food = max(food - 1, 0)
        happy = max(happy - 1, 0)
        last_drop = running_time()
    if food == 0 or happy == 0:
        display.show(Image.SAD)
    elif food < 4 or happy < 4:
        display.show(Image.CONFUSED)
    else:
        display.show(Image.HAPPY)
    sleep(100)
