Click the green play button! Match the blue number at the top of the screen by turning light bulbs on or off. The red number at the bottom is what number you have created by turning lightbulbs on. The purple number at the bottom is that same number in binary. Getting a correct answer adds time to your timer!

def make_confetti(): stage.event_interval(None) confetti.show() confetti.set_bottom(250) confetti.set_rotation(random.randint(0, 360)) confetti.glide_to(0, -300) confetti.hide() for bulb in light_bulbs: if bulb.on == True: bulb.load_image("bulb_off_bdb") bulb.set_size(0.4) bulb.on = False binary_sprite.set_text("00000000") stage.event_interval(interval, 1) def click(sprite): global random_int, score, timer if sprite.get_image_name() == "bulb_off_bdb": sprite.load_image("bulb_on_bfc") sprite.on = True else: sprite.load_image("bulb_off_bdb") sprite.on = False sprite.set_size(0.4) # sprite.say(sprite.value, .5) # add other actions... total_value = 0 binary_value = "" for bulb in light_bulbs: if bulb.on == True: total_value += bulb.value binary_value += str(1) else: binary_value += str(0) value_sprite.set_text(total_value) binary_sprite.set_text(binary_value) if total_value == random_int: make_confetti() score+=1 score_display.update(score) random_int = random.randint(0, 255) target_value.set_text(random_int) timer += 2 timer_display.update(timer) # Title: confetti_355 # License: # Source: https://docs.google.com/drawings/d/e/2PACX-1vScbnkuF5R5uoGh9X9XMBfFTcKP8ZuHywqDxs4p4VpiOT3bflrkvK2cZg0bkZ83dDiXnbhyEClmkbfF/pub?w=365&amp;h=348 confetti = codesters.Sprite("confetti_355", 0, 500) confetti.hide() confetti.set_size(1.3) confetti.set_speed(5) label_num = 128 x = -210 light_bulbs = [] for c in range(8): sprite = codesters.Sprite("bulb_off_bdb", x, 75) sprite.set_size(.4) label = codesters.Text(label_num, x, 165) sprite.value = label_num sprite.on = False label_num/=2 x += 60 light_bulbs.append(sprite) sprite.event_click(click) value_sprite = codesters.Text(0, 0, -75, "red") value_sprite.set_text_size(72) binary_sprite = codesters.Text("00000000", 0, -195, "purple") binary_sprite.set_text_size(65) random_int = random.randint(0, 255) target_value = codesters.Text(random_int, 0, 220, "blue") score = 0 timer = 30 #my_display = codesters.Display(my_var, x, y) score_display = codesters.NewDisplay(score, 210, 225, "Score:") timer_display = codesters.NewDisplay(timer, -210, 225, "Time") def interval(): global timer timer -=1 timer_display.update(timer) if timer <= 0: for bulb in light_bulbs: bulb.event_click(None) stage.event_interval(None) value_sprite.set_text("Game Over!") binary_sprite.set_text("Click Run and try to beat your high score!") binary_sprite.set_text(15) stage.event_interval(interval, 1) #################################################### # This code creates the optional instructions # #################################################### stage.event_interval(None) run_instructions = stage.ask("Do you want to read instructions? Type yes or no").lower() if run_instructions == "yes" or run_instructions == "y": import codesters import random from codesters.demo import Demo from codesters import Text # Create Demo instance demo = Demo() class newDemo(Demo): def create_continue_button(self): text = "Continue" background_sprite = codesters.Rectangle(-203, -219, 125, 62.5, "green", "black") button = self.create_button(text, -197, -220, True, "white", "#07A7E0", 90, 200, "white") self.stage.remove_sprite(button.background_sprite) button.background_sprite = background_sprite self.add_hover_opacity_element(button) return button demo = newDemo() blocker = codesters.Square(0, 0, 500, "white", "black") blocker.set_line_thickness(25) instructions = Text("Play this game to convert decimal numbers\n\nto binary numbers!\n\n") stage.wait(3) instructions.set_text("Play this game to convert decimal numbers\n\nto binary numbers!\n\nClick the continue button!") demo.continue_action() target_value.move_to_front() instructions.set_text("This blue number is the number you will convert!\n\n") stage.wait(3) value_sprite.move_to_front() instructions.set_text("This blue number is the number you will convert!\n\nThis red number is the binary number\n\nyou have created.") stage.wait(2) demo.continue_action() binary_sprite.move_to_front() instructions.set_text("Lastly, this purple number is the red number\n\n - in binary!") stage.wait(2) demo.continue_action() instructions.set_text("") opacity = .9 for counter in range(10): blocker.set_opacity(opacity) stage.wait(0.05) opacity -= .1 instructions.set_y(instructions.get_y()-20) instructions.set_text("Click a light bulb to add a 1 in that binary place value.\n") stage.wait(2) instructions.set_text("Click a light bulb to add a 1 in that binary place value.\nConvert the blue number!") stage.wait(5) stage.remove_sprite(instructions) else: stage.wait(0.5) stage.event_interval(interval)
  • Run Code
  • Show Console
  • Codesters How To (opens in a new tab)