''' Day 3 Remix - Intermediate Level ''' from codex import * from time import sleep import random delay = 1 count = 0 correct = 0 # Intro display.draw_text("Roll Dice", scale=3, x=35, y=80) display.draw_text("Game", scale=4, x=35, y=120) sleep(delay) display.clear() display.draw_text("Press U for HIGHER", scale=2, x=10, y=80) display.draw_text("Press D for LOWER", scale=2, x=10, y=120) display.draw_text("Press B to start", scale = 2, color=RED, x=35, y=180) sleep(delay*3) # Start game while True: # Start game with button B if buttons.was_pressed(BTN_B): # Reset the board for each game display.clear() # Select first random number num1 = random.randrange(6) + 1 display.draw_text(str(num1), color=GREEN, scale=20, x=70, y=40) sleep(delay) while count < 4: num2 = random.randrange(6) + 1 if buttons.was_pressed(BTN_U): display.clear() sleep(delay) display.draw_text(str(num2), scale=20, color=GREEN, x=70, y=40) # If the new roll is higher, show correct if num2>=num1: pixels.set(count, GREEN) sleep(delay) count = count + 1 num1 = num2 correct = correct + 1 else: sleep(delay) break elif buttons.was_pressed(BTN_D): display.clear() sleep(delay) display.draw_text(str(num2), scale=20, color=GREEN, x=70, y=40) # If the new roll is lower, show corre if num2 <= num1: pixels.set(count, GREEN) sleep(delay) count = count + 1 num1 = num2 else: sleep(delay) break # Ending message if count == 4: display.clear() display.draw_text("You WON", scale=4, color=BLUE, x=30, y=80) else: display.clear() display.draw_text("You LOST", scale=4, color=RED, x=30, y=80) break