''' Mission 9 Remix 4A (Extra Spicy) Button B will start the program Button A will roll two die at the same time. One function is used and in the function two random numbers and colors are generated. Then two rectangles are drawn to represent the die and draw_text is used to display the numbers on the die. Also Used button D to end game ''' from codex import * import random from time import sleep # Create a list of bright colors to avoid dark colors on the display my_colors = [YELLOW, WHITE, ORANGE, PINK, CYAN, MAGENTA, GRAY, GREEN, RED] # Introduction to program def intro(): # Intro display.print("DOUBLE DIE") display.print("PROGRAM") display.print("A = spin") display.print("B = start") display.print("D = Stop") while True: if buttons.was_pressed(BTN_B): break # One function for random die roll # inputs random number for loop # generates random number to display until loop ends def show_random_die(count): loops = 0 delay = 0.04 while loops < count: display.clear() number1 = random.randrange(1, 7) number2 = random.randrange(1, 7) die_color1 = random.choice(my_colors) die_color2 = random.choice(my_colors) display.draw_rect(25, 80, 80, 80, BLUE) display.draw_rect(125, 80, 80, 80, GREEN) display.draw_text(str(number1), 50, 100, color=die_color1, scale=6) display.draw_text(str(number2), 150, 100, color=die_color2, scale=6) sleep(delay) delay = delay + 0.005 loops = loops + 1 # Main program intro() while True: if buttons.was_pressed(BTN_A): count = random.randrange(5, 10) show_random_die(count) if buttons.was_pressed(BTN_D): break # Ending display.clear() display.print("DONE", scale=5)