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)
def release_key(sprite):
sprite.say("BLAST OFF!", 1, "white")
sprite.move_forward(575)
stage.wait(0.1)
sprite.go_to(0, -210)
# add other actions...
sprite.event_key_release("space", release_key)
def collision(sprite, hit_sprite):
global score
# add any other actions...
sprite.event_collision(collision)
t = codesters.Teacher()
func = t.find_text('collision')
call = t.find_function('event_collision')
adds = t.find_text('+=')
updates = t.get_parameters_for_function('update')
updates_text = t.find_text('update')
removes = t.find_text('remove_sprite')
remove_params = t.get_parameters_for_function('remove_sprite')
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:
tval2a = int(adds[0][0])
tval2b = t.get_indent_at_line(tval2a)
tval2c = adds[0][1].replace(" ", '')
except:
tval2a = -1
tval2b = -1
tval2c = "DNE"
try:
tval3a = int(updates_text[1][0])
tval3b = t.get_indent_at_line(tval3a)
tval3c = updates[1][0]
except:
tval3a = -1
tval3b = -1
tval3c = "DNE"
try:
tval4a = int(removes[0][0])
tval4b = t.get_indent_at_line(tval4a)
tval4c = remove_params[0][0]
except:
tval4a = -1
tval4b = -1
tval4c = "DNE"
event_check = TestObjective()
event_check.add_success(len(func) == 2 and def_line != -1 and def_line_indent == 0 and call_line_indent == 0, "Great job!")
event_check.add_failure(def_line == -1, "Oops! Did you delete your Collision event?")
event_check.add_failure(def_line_indent > 0 or call_line_indent > 0, "Oops! Make sure your Collision event is NOT indented inside another event.")
t1 = TestObjective()
t1.add_success(tval2a != -1 and tval2b == 4 and tval2c == "score+=1" and def_line <tval2a < call_line, "Great job!")
t1.add_failure(tval2a == -1, "Did you add Increase Value to your event?")
t1.add_failure(tval2a != -1 and tval2c != "score+=1", "Did you add 1 to score correctly?")
t1.add_failure(tval2b < 4, "Make sure your += command is indented 4 spaces in your collision event.")
t1.add_failure(tval2b > 4, "Make sure your += command is indented only 4 spaces inside your collision event.")
t1.add_failure(not (def_line <tval2a < call_line), "Make sure your -= command is inside your collision event.")
t2 = TestObjective()
t2.add_success(tval3a != -1 and tval3b == 4 and tval3c == 'score' and def_line <tval3a < call_line, "Great job!")
t2.add_failure(tval3a == -1, "Did you add Update Display to your collision event?")
t2.add_failure(tval3a != -1 and tval3c != "score", "Did you update score_display with the score variable?")
t2.add_failure(tval3b < 4, "Make sure your .update() command is indented 4 spaces in your collision event.")
t2.add_failure(tval3b > 4, "Make sure your .update() command is indented only 4 spaces inside your collision event.")
t2.add_failure(not (def_line <tval3a < call_line), "Make sure your .update() command is inside your collision event.")
t3 = TestObjective()
t3.add_success(tval4a != -1 and tval4b == 4 and tval4c == 'hit_sprite' and def_line <tval4a < call_line, "Great job!")
t3.add_failure(tval4a == -1, "Did you add Remove Sprite to your collision event?")
t3.add_failure(tval4a != -1 and tval4c != "hit_sprite", "Did you change sprite to hit_sprite in .remove_sprite()?")
t3.add_failure(tval4b < 4, "Make sure your .remove_sprite() command is indented 4 spaces in your collision event.")
t3.add_failure(tval4b > 4, "Make sure your .remove_sprite() command is indented only 4 spaces inside your collision event.")
t3.add_failure(not (def_line <tval4a < call_line), "Make sure your .remove_sprite() command is inside your collision event.")
tester = TestManager()
tester.add_test_list([event_check, t1, t2, t3])
tester.run_tests()
tester.display_first_feedback()