import codesters
import random
from codesters.demo import Demo
from codesters import Text
# Set constants
stage_height = float(stage.get_stage_height())
stage_width = float(stage.get_stage_width())
offstage_below = -1000 # Use as y value to create objects below the stage
wait_time = 1
# Create Demo instance
demo = Demo()
# Set up stage
stage.auto_cache_off()
stage.set_background_color("black")
stage.disable_floor()
# Create random letters/characters to drop down the stage
chars = []
for counter in range(60):
x = random.randint(-550, 550)
binary = codesters.Text(chr(random.randint(33, 255)), x, 300, "green")
binary.set_y_speed(random.randint(-3, -1))
binary.set_physics_on()
binary.set_opacity(random.random())
chars.append(binary)
# Moves the characters down the stage at random speeds;
# when they reach the bottom, they move to a new random x-coordinate and the top of the stage
def interval():
for char in chars:
if char.get_y() <= -(stage_height/2):
char.go_to(random.randint(-550, 550), 310)
char.set_y_speed(random.randint(-3, -1))
stage.event_interval(interval, 0.05)
# Title Cards
lesson_title = Text("Cybersecurity: Introduction", 0, 200, "white")
lesson_title.set_text_width(800)
lesson_title.set_text_size(40)
activity_title = Text("What is a system?", 0, 150, "white")
activity_title.set_text_width(600)
activity_title.set_text_size(30)
stage.wait(wait_time*1)
guide = demo.create_sprite_off_screen("person20", -stage_width/2-50, -150, 1)
guide.glide_to(0, -150)
guide.say("Welcome back! Click Next to start learning about systems.", 0, "white", 19)
stage.wait(wait_time*3)
demo.continue_action()
guide.say("")
lesson_title.set_speed(10)
lesson_title.glide_to(0, 1000)
activity_title.set_speed(10)
activity_title.glide_to(0, 1000)
demo.remove_all_sprites_except([guide]+chars)
def create_bike_parts():
wheel = demo.create_sprite_off_screen("wheel_8f2", -1000, 1000, 1)
chain = demo.create_sprite_off_screen("bike_chain_8df", -1000, 1000, 1)
frame = demo.create_sprite_off_screen("frame_a00", -1000, 1000, .5)
seat = demo.create_sprite_off_screen("bike_seat_ffe", -1000, 1000, .5)
handlebar = demo.create_sprite_off_screen("bike_handles_ee7", -1000, 1000, 1)
bike_sprites = [wheel, chain, frame, seat, handlebar]
for part in bike_sprites:
part.hide()
return bike_sprites
bike_sprites = create_bike_parts()
bike = demo.create_sprite_off_screen("bike_027", -stage_width/2-170, -200, 1)
guide.say("We have defined cybersecurity as the art\nof building secure computer systems...", 0, "white", 20)
stage.wait(wait_time*2)
text = u"★" + " Cybersecurity is all about building secure computer systems that we can trust! "
cyber_def = demo.animate_typing_text(text, -stage_width/3-100, 225, align="left", font_size=25, color = "white", cursor_wait = False)
stage.wait(wait_time*2)
demo.continue_action()
guide.say("It's time to dig deeper into that definition!", 0, "white", 20)
stage.wait(wait_time*2)
demo.continue_action()
guide.say("What *is* a system?", 0, "white", 20)
stage.wait(wait_time*2)
text = u"★" + " A system is a group of parts that work together as a whole "
system_def = demo.animate_typing_text(text, -stage_width/3-100, 175, align="left", font_size=25, color = "white", cursor_wait = True)
guide.say("")
stage.wait(wait_time*2)
demo.continue_action()
guide.say("")
guide_text_2 = codesters.Text("What is a system?\n\nWhat does it mean to be secure?\n\nLet's begin with examples from your own life!", 0, 75)
guide_text_2.set_text_size(20)
guide_text_2.set_text_background("silver", "white", 0.85)
stage.wait(wait_time*4)
demo.continue_action()
stage.event_interval(None)
for char in chars:
char.set_y_speed(0)
char.hide()
keep_stage_elements = [cyber_def, system_def, guide, guide_text_2, bike] + bike_sprites
demo.remove_all_sprites_except(keep_stage_elements + chars)
stage.set_background_color("#ececec")
guide.set_say_color("black")
cyber_def.set_color("black")
system_def.set_color("black")
guide_text_2.set_text("Let's start by looking at a bike!")
stage.wait(wait_time*1.5)
bike.glide_to(-300, -200)
bike_parts = ["wheel", "handle", "handlebar", "gear", "chain", "brake", "bell", "seat", "reflector", "frame", "tire", "pedal", "spoke", "fender", "spring", "saddle"]
def time_for_test_list(question, correct_values, wrong_values, guidance, hint):
guide.say("Let's think about systems!")
stage.wait(wait_time*1.5)
student_input = guide.ask(question).lower().replace(" ", "")
if student_input == "":
guide.say("Oops! Make sure to enter an answer!")
stage.wait(wait_time*2)
student_input = guide.ask(question).lower().replace(" ", "")
elif student_input[-1] == "s":
student_input = student_input[:-1]
try_count = 0
while student_input not in correct_values:
guide.say("Hm... Try again!")
stage.wait(wait_time*1)
guide.say(guidance)
stage.wait(wait_time*1)
try_count += 1
if try_count >= 3:
guide.say(hint)
stage.wait(wait_time*3)
student_input = guide.ask(question).lower().replace(" ", "")
if student_input[-1] == "s":
student_input = student_input[:-1]
def time_for_test(question, correct_answer, wrong_answer, feedback):
guide.say("Let's think about systems!")
stage.wait(wait_time*1.5)
student_input = guide.ask(question).lower().replace(" ", "")
while student_input != correct_answer:
guide.say("Hm... Try again!")
stage.wait(wait_time*1)
guide.say(feedback)
stage.wait(wait_time*1)
if student_input == wrong_answer:
guide.say("Hm... Try again!")
stage.wait(wait_time*1)
else:
guide.say(feedback)
stage.wait(wait_time*1.5)
student_input = guide.ask(question).lower().replace(" ", "")
guide.set_say_position(0, -50, "relative")
stage.wait(wait_time*1)
time_for_test_list("Name a part of a bike!", bike_parts, None, "Enter a bike part!", "Hint: this bike has two ______ to roll on!")
guide_text_2.hide()
guide.say("Great!", 0, "black", 20)
stage.wait(wait_time*2)
guide.say("A bike is made out of multiple parts.", 0, "black", 20)
stage.wait(wait_time*1)
demo.continue_action()
cyber_def.move_up(100)
cyber_def.hide()
system_def.move_up(75)
system_def.show()
guide.say("A bike is made out of multiple parts.", 0, "black", 20)
bike_coords = [(-440, 130+5), (-190, 130+5), (50, 130+5), (250, 130+5), (450, 130+5)]
index = 0
for bike_part in bike_sprites:
bike_part.go_to(bike_coords[index][0], bike_coords[index][1])
bike_part.show()
index += 1
stage.wait(.1)
stage.wait(wait_time*1)
demo.continue_action()
guide.say("These parts work together to let the rider move forward!", 0, "black", 20)
stage.wait(wait_time*2)
demo.continue_action()
guide.say("A bike is an example of a system!", 0, "black", 20)
stage.wait(wait_time*2)
demo.continue_action()
bike.move_forward(stage_width)
guide.say("")
guide.move_forward(100)
for counter in range(len(bike_sprites)):
part = random.choice(bike_sprites)
part.set_speed(10)
part.glide_to(random.randint(-250, -200), random.randint(-200, -100))
bike_sprites.remove(part)
stage.wait(wait_time*1)
time_for_test("Is this a system?", "no", "yes", "Enter yes or no!")
guide.set_say_position(0, -25, "relative")
guide.say("That's right!\n")
stage.wait(wait_time*2)
guide.say("That's right!\nIn a system, the parts affect each other and work together as a whole.")
stage.wait(wait_time*2)
demo.continue_action()
guide.say("That's right!\nIn a system, the parts affect each other and work together as a whole.\nThese parts are not working together!")
stage.wait(wait_time*3)
demo.continue_action()
guide.say("These parts need to be properly\nassembled in order to work as a system.")
stage.wait(wait_time*3)
demo.continue_action()
keep_stage_elements = [cyber_def, guide, guide_text_2, system_def]
demo.remove_all_sprites_except(keep_stage_elements+chars)
guide.say("Let's look at another system!")
stage.wait(wait_time*2)
guide.move_left(350)
desktop = demo.create_sprite_off_screen("desktop_pixel_12b", 100, -180, 1)
stage.wait(wait_time*2)
computer_parts = ["screen", "monitor", "keyboard", "mouse", "hard drive", "memory", "ram", "motherboard",
"processor", "fan", "heat sink", "track_pad", "wire", "power supply"]
time_for_test_list("Name a part of a computer!", computer_parts, None, "Enter a computer part!", "Hint: this computer has a ______ to type with!")
guide.say("Great!")
stage.wait(wait_time*2)
guide.say("A computer is made out of multiple parts.\n\n")
stage.wait(wait_time*1)
demo.continue_action()
keyboard = demo.create_sprite_off_screen("keyboard_4e2", -440, 140, 1)
mouse = demo.create_sprite_off_screen("mouse_b9d", -365, 100, .3)
monitor = demo.create_sprite_off_screen("monitor_154", -245, 140, 1.1)
hard_drive = demo.create_sprite_off_screen("hard_drive_2a9", -100, 130, .8)
motherboard = demo.create_sprite_off_screen("motherboard_04a", 20, 160, .7)
processor = demo.create_sprite_off_screen("processor_ea5", 50, 100, .7)
ram = demo.create_sprite_off_screen("RAM_5f0", 155, 130, 1)
power_supply = demo.create_sprite_off_screen("power_supply_4e3", 350, 130, .6)
fan = demo.create_sprite_off_screen("fan_36e", 455, 130, 1)
computer_parts = [mouse, keyboard, monitor, hard_drive, motherboard, processor, ram, power_supply, fan]
demo.continue_action()
# guide.set_say_position(0, -50, "relative")
guide.say("A computer is made out of multiple parts.\n\nThese parts work together to let the user create files, listen to music, watch movies, and more!")
stage.wait(wait_time*2)
demo.continue_action()
stage.remove_sprite(desktop)
for counter in range(len(computer_parts)):
part = random.choice(computer_parts)
part.set_speed(10)
part.glide_to(random.randint(200, 300), random.randint(-200, -100))
computer_parts.remove(part)
stage.wait(wait_time*1)
time_for_test("Is this a system?", "no", "yes", "Enter yes or no!")
guide.say("That's right!\nEven though all the parts are here, they don't affect each other and are not working together.")
stage.wait(wait_time*3)
demo.continue_action()
demo.remove_all_sprites_except(keep_stage_elements+chars)
stage.set_background_color("black")
system_def.set_color("white")
guide.say("")
guide.glide_to(0, guide.get_y())
for char in chars:
char.set_y_speed(random.randint(-3, -1))
char.show()
stage.event_interval(interval, 0.05)
guide_text_2.set_text("When we look at a system,\nit's important to understand the parts of the system,\n\n")
guide_text_2.show()
stage.wait(wait_time*2)
demo.continue_action()
guide_text_2.set_text("When we look at a system,\nit's important to understand the parts of the system,\nand how each part affects the others!\n")
stage.wait(wait_time*2)
demo.continue_action()
guide_text_2.set_text("For cybersecurity, we need to know about computers, networks, users, hackers, laws, and more!\n\n")
stage.wait(wait_time*2)
demo.continue_action()
guide_text_2.set_text("For cybersecurity, we need to know about computers, networks, users, hackers, laws, and more!\nClick Submit and Continue to continue learning more about systems and cybersecurity!")
guide_text_2.show()
guide.move_forward(stage_width/2+75)
sprite_list = demo.remind_student_to_submit(guide_text_2.get_x() - 175, guide_text_2.get_y() - 60, 25)
for sprite in sprite_list:
if sprite.get_name() == 'line' or sprite.get_name() == 'arrowLine':
sprite.set_color("white")
elif sprite.get_text() != None:
sprite.set_color("white")
tester = TestManager()
tester.display_success_message("Great job!")
stage.wait(wait_time*10)
stage.event_interval(None)
for char in chars:
char.set_y_speed(0)