''' Mission 9 Remix 3C Makes the die roll into a game: Player A and Player B Each player presses his/her button to roll the die. Use a counter to add up each die roll. First one to designated number wins. NOTE: I created a color list so BLACK and the dark colors are not options. NOTE: This game does not force player A and then player B, so they could go out of order. Coding can be added to force playing in the correct order. ''' from codex import * import random from time import sleep my_colors = [BROWN, RED, ORANGE, GREEN, YELLOW, BLUE, PURPLE, GRAY, WHITE, CYAN, MAGENTA, PINK] # Introduction to program def intro(): # Intro display.print("DIE ROLL", color=CYAN, scale=3) display.print("GAME", color=CYAN, scale=3) display.print("") display.print("U to begin") display.print("") display.print("Player A spins") display.print("Player B spins") display.print("First one to", color=YELLOW) display.print("20 wins!", color=YELLOW) while True: if buttons.was_pressed(BTN_U): break # One function for random die roll # inputs random number for loop # generates random number to display until loop ends def show_random_die(player, color, count): global count_a, count_b loops = 0 delay = 0.04 display.clear() display.print("PLAYER "+player, color, scale=4) sleep(1) while loops < count: display.clear() number = random.randrange(1, 7) display.print("", scale=8) # Moves text down from top corner display.print(number, random.choice(my_colors), scale=10) sleep(delay) delay = delay + 0.005 loops = loops + 1 if player == "A": count_a = count_a + number else: count_b = count_b + number def ending(): display.clear() display.print("The winner is", scale=3) if count_a >= final: display.print("Player A!", color=RED, scale=5) display.print("Points scored", scale=3) display.print(count_a, color=RED, scale=5) else: display.print("Player B!", color=GREEN, scale=5) display.print("Points scored", scale=3) display.print(count_b, color=GREEN, scale=5) # Global Variables count_a = 0 count_b = 0 final = 20 # Main program intro() while True: if buttons.was_pressed(BTN_A): # generate random # of arrow spins, display final arrow count = random.randrange(5, 10) show_random_die("A", RED, count) if buttons.was_pressed(BTN_B): # generate random # of dice rolls, display final roll count = random.randrange(5, 10) show_random_die("B", GREEN, count) if count_a >= final or count_b >= final: break # Ending display.clear() ending()