''' Day 3 Remix - Advanced Level Continuous play until BTN_A is pressed ''' from codex import * from time import sleep import random delay = 1 count = 0 keepGoing = True # 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 count = 0 keep_going = True pixels.set(0, BLACK) pixels.set(1, BLACK) pixels.set(2, BLACK) pixels.set(3, BLACK) 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 keep_going: # Get the next random dice roll num2 = random.randrange(6) + 1 # Check to see if the U button was pressed for a higher number if buttons.was_pressed(BTN_U): display.clear() display.draw_text(str(num2), scale=20, color=YELLOW, x=70, y=40) if num2 >= num1: pixels.set(count, GREEN) count = count + 1 if count == 4: keep_going = False else: sleep(delay) keep_going = False num1 = num2 # Check to see if the D button was pressed for a lower number elif buttons.was_pressed(BTN_D): display.clear() display.draw_text(str(num2), scale=20, color=WHITE, x=70, y=40) if num2 <= num1: pixels.set(count, GREEN) count = count + 1 if count == 4: keep_going = False else: sleep(delay) keep_going = False num1 = num2 # Win/Loss 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) # Play until A is pressed if buttons.was_pressed(BTN_A): break # Ending message display.clear() display.draw_text("DONE", scale=5, color=RED, x=55, y=100) sleep(delay*2) display.clear() pixels.set(0, BLACK) pixels.set(1, BLACK) pixels.set(2, BLACK) pixels.set(3, BLACK)