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)
t = codesters.Teacher()
all_funcs = t.find_text('def')
func = t.find_text('collision')
call = t.find_function('event_collision')
goes_text = t.find_text('go_to')
globs = t.find_text('global')
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:
goes = "DNE"
for i in goes_text:
if def_line < int(i[0]) < call_line:
goes = i[0]
except:
goes = "DNE"
try:
hides = t.find_function('hide')[0]
except:
hides = "DNE"
try:
tval2a = int(globs[1][0])
tval2b = t.get_indent_at_line(tval2a)
tval2c = globs[1][1].replace('global', '').replace(" ", '')
except:
tval2a = -1
tval2b = -1
tval2c = "DNE"
t1 = TestObjective()
t1.add_success(len(all_funcs) == 5 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 Collision event?")
t1.add_failure(len(all_funcs) == 5 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 Collision event is NOT indented inside another event.")
t2 = TestObjective()
t2.add_success(goes == "DNE" and hides == "DNE", "Great job!")
t2.add_failure(goes != "DNE", "Make sure you delete the .go_to() in your collision event!")
t2.add_failure(hides != "DNE", "Make sure you delete the .hide() in your collision event!")
t3 = TestObjective()
t3.add_success(tval2a != -1 and tval2b == 4 and tval2c == "score" and def_line <tval2a < call_line, "Great job!")
t3.add_failure(tval2a == -1, "Did you add Global Variable to your collision event?")
t3.add_failure(tval2c != 'score', "Did you correctly global the score variable?")
t3.add_failure(tval2b < 4, "Make sure your global command is indented 4 spaces in your interval event.")
t3.add_failure(tval2b > 4, "Make sure your global command is indented only 4 spaces inside your interval event.")
t3.add_failure(not (def_line <tval2a < call_line), "Make sure your global command is inside your interval event.")
tester = TestManager()
tester.add_test_list([t1, t2, t3])
tester.run_tests()
tester.display_first_feedback()