stage.set_background("moon")
sprite = codesters.Sprite("hedgehog", 0, -210)
score = 0
#my_display = codesters.Display(my_var, x, y)
score_display = codesters.Display(score, -210, -210)
time = 60
#my_display = codesters.Display(my_var, x, y)
time_display = codesters.Display(time, 210, -210)
def left_key():
rotation = sprite.get_rotation()
print(rotation)
sprite.set_rotation(rotation+3)
# add other actions...
stage.event_key("left", left_key)
def right_key():
rotation = sprite.get_rotation()
print(rotation)
sprite.set_rotation(rotation-3)
# add other actions...
stage.event_key("right", right_key)
def interval():
global time
time -=1
time_display.update(time)
if time % 2 == 0:
x = random.randint(-230,230)
y = random.randint(0,230)
star = codesters.Star(x, y, 5, 20, "yellow")
if time == 0:
stage.remove_all_events()
stage.event_interval(interval, 1)
t = codesters.Teacher()
disables = t.find_text('disable')
func = t.find_text('release_key')
call = t.find_function('event_key_release')
says = t.get_parameters_for_function('say')
say_text = t.find_text('say')
try:
def_line = int(func[0][0])
def_line_indent = t.get_indent_at_line(def_line)
except:
def_line = -1
def_line_indent = -1
try:
call_line = int(call[0][0])
call_line_indent = t.get_indent_at_line(call_line)
except:
call_line = -1
call_line_indent = -1
try:
spin = t.find_function('turn_right')
except:
spin = "DNE"
try:
tval2a = says[0][0].lower()
say_line = say_text[0][0]
tval2_indent = t.get_indent_at_line(say_line)
except:
tval2a = "DNE"
say_line = -1
tval2_indent = -1
try:
tval2b = int(says[0][1])
except:
tval2b = -1
try:
tval2c = says[0][2]
except:
tval2c = "DNE"
t1 = TestObjective()
t1.add_success(len(func) == 4 and def_line != -1 and def_line_indent == 0 and call_line_indent == 0, "Great job!")
t1.add_failure(def_line == -1, "Did you add a Key Release event?")
t1.add_failure(len(func) == 4 and def_line == -1, "Oops! Did you add the correct event?")
t1.add_failure(def_line_indent > 0 or call_line_indent > 0, "Oops! Make sure your Key Release event is NOT indented inside another event.")
t2 = TestObjective()
t2.add_success(len(spin) == 0, "Great job!")
t2.add_failure(len(spin) != 0, "Make sure you delete the .turn_right() command in your event!")
t3 = TestObjective()
t3.add_success('blast' in tval2a and tval2b == 1 and tval2c == "white" and len(says[0]) == 3, "Great job!")
t3.add_failure(tval2a == "DNE", "Did you add Say for Time inside the Key Release event?")
t3.add_failure(tval2a != "DNE" and len(says[0]) < 2, "Oops! Did you add Say instead of Say for Time?")
t3.add_failure('blast' not in tval2a, 'Did you edit the .say() to say "BLAST OFF!"?')
t3.add_failure(tval2b == 2, 'Did you edit the 2 in .say() to 1?')
t3.add_failure(tval2b > 2, 'Oops! That\'s a long time to say something!')
t3.add_failure(tval2c == "DNE", 'Did you add , "white" after the number in .say()?')
t3.add_creative(tval2c != "DNE" and tval2c != '"white"', "That's a great color too!")
t3_indent = TestObjective()
t3_indent.add_success(tval2_indent == 4 and (def_line < say_line < call_line), "Great job!")
t3_indent.add_failure(tval2_indent != 4, "Make sure you indent .say() (4 spaces total)!")
t3_indent.add_failure(not (def_line < say_line < call_line), "Make sure Disable All Events is inside your NEW if-statement.")
tester = TestManager()
tester.add_test_list([t1, t2, t3, t3_indent])
tester.run_tests()
tester.display_first_feedback()