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)
t = codesters.Teacher()
func = t.find_block('def')
call = t.find_function('event_key')
rots = t.find_function('get_rotation')
try:
tval1 = func[0][1]
except:
tval1 = "DNE"
try:
lefts = t.find_function("move_left")
except:
lefts = "DNE"
try:
def_line = int(func[0][0])
except:
def_line = -1
try:
call_line = int(call[0][0])
except:
call_line = -1
try:
tval2a = int(t.find_text('get_rotation')[0][0])
tval2b = t.get_indent_at_line(tval2a)
except:
tval2a = -1
tval2b = -1
t1 = TestObjective()
t1.add_success(len(func) == 1 and "left_key" in tval1, "Great job!")
t1.add_failure(len(func) == 0, "Did you add a Left Key event?")
t1.add_failure(len(func) == 1 and "left_key" not in tval1, "Did you add the correct key event?")
t2 = TestObjective()
t2.add_success(len(lefts) == 0, "Great job!")
t2.add_failure(len(lefts) != 0, "Make sure you delete the .move_left() command in your event!")
t3 = TestObjective()
t3.add_success(tval2a != -1 and tval2b == 4 and def_line <tval2a < call_line, "Great job!")
t3.add_failure(tval2a == -1, "Did you add Get Rotation to your event?")
t3.add_failure(tval2b < 4, "Make sure your .get_rotation() command is indented 4 spaces in your left key event.")
t3.add_failure(tval2b > 4, "Make sure your .get_rotation() command is indented only 4 spaces inside your left key event.")
t3.add_failure(not (def_line <tval2a < call_line), "Make sure your .get_rotation() command is inside your left key event.")
t4 = TestObjective()
t4.add_failure(len(call) != 1, "Oops! Did you delete your left_key event handler?")
tester = TestManager()
tester.add_test_list([t1, t2, t3, t4])
tester.run_tests()
tester.display_first_feedback()
-
Run Code
-
Activity Submitted!
Submit Work
-
Next Activity
-
Stop Running Code
-
Show Chart
-
Show Console
-
Reset Code Editor
-
Codesters How To (opens in a new tab)