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)
t = codesters.Teacher()
func = t.find_text('def')
call = t.find_function('event_key')
rot_param = t.get_parameters_for_function('set_rotation')
try:
tval1 = func[1][1]
except:
tval1 = "DNE"
try:
rights = t.find_function("move_right")
except:
rights = "DNE"
try:
def_line = int(func[1][0])
except:
def_line = -1
try:
call_line = int(call[1][0])
except:
call_line = -1
try:
tval2a = int(t.find_text('get_rotation')[1][0])
tval2b = t.get_indent_at_line(tval2a)
except:
tval2a = -1
tval2b = -1
try:
tval3 = rot_param[1][0]
except:
tval3 = "DNE"
try:
tval4a = int(t.find_text('set_rotation')[1][0])
tval4b = t.get_indent_at_line(tval4a)
except:
tval4a = -1
tval4b = -1
t1 = TestObjective()
t1.add_success(len(func) == 2 and "right_key" in tval1, "Great job!")
t1.add_failure(len(func) < 2, "Did you add a Right Key event?")
t1.add_failure(len(func) == 2 and "right_key" not in tval1, "Did you add the correct key event?")
t2 = TestObjective()
t2.add_success(len(rights) == 0, "Great job!")
t2.add_failure(len(rights) != 0, "Make sure you delete the .move_right() 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 right key event.")
t3.add_failure(tval2b > 4, "Make sure your .get_rotation() command is indented only 4 spaces inside your right key event.")
t3.add_failure(not (def_line <tval2a < call_line), "Make sure your .get_rotation() command is inside your right key event.")
t4 = TestObjective()
t4.add_success((tval3 == "rotation-3" or tval3 == "3-rotation") and tval4a != -1 and def_line < tval4a < call_line, "Great job!")
t4.add_failure(tval3 == "DNE", "Did you add Set Rotation with the event?")
t4.add_failure(tval3 != "rotation-3" and tval3 != "3-rotation", "Did you change the argument in .set_rotation?")
t4.add_failure(not (def_line < tval4a < call_line), "Make sure your .set_rotation() command is inside your right key event.")
t4.add_failure(tval4b < 4, "Make sure your .set_rotation() command is indented 4 spaces in your right key event.")
t4.add_failure(tval4b > 4, "Make sure your .set_rotation() command is indented only 4 spaces inside your right key event.")
t5 = TestObjective()
t5.add_failure(len(call) != 2, "Oops! Did you delete either event handler?")
tester = TestManager()
tester.add_test_list([t1, t2, t3, t4, t5])
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)