stage.set_background("schoolhallway")
sprite = codesters.Sprite("person8")
stage.set_gravity(4)
stage.disable_floor()
sprite.set_gravity_off()
sprite.go_to(0, -220)
score = 0
score_board = codesters.Display(score)
my_info = ["cellphone", "address", "birthdate"]
def left_key():
sprite.move_left(20)
# add other actions...
stage.event_key("left", left_key)
def right_key():
sprite.move_right(20)
# add other actions...
stage.event_key("right", right_key)
def interval():
x = random.randint(-230, 230)
info_img = random.choice(my_info)
# sprite = codesters.Sprite("image", x, y)
info = codesters.Sprite(info_img, x, 275)
# add any other actions...
stage.event_interval(interval, 3)
def collision(sprite, hit_sprite):
# add any other actions...
global score
stage.remove_sprite(hit_sprite)
score += 1
sprite.event_collision(collision)
t = codesters.Teacher()
try:
tval1 = t.find_function('update')[0][0]
tval1a = t.get_indent_at_line(tval1)
tval2 = t.find_function('update')[0][1].replace(' ', '')
except:
tval1 = "DNE"
tval1a = "DNE"
tval2 = "DNE"
t1 = TestObjective()
t1.add_success(tval2 == 'score_board.update(score)' and tval1a == 4, "Great job!")
t1.add_failure(tval1 == "DNE", "Did you add an Update Display command to your Collision Event?")
t1.add_failure('score_board.' not in tval2, "Did you change the name in front of the command to score_board?")
t1.add_failure('(score)' not in tval2, "Did you change the name inside the parentheses to score?")
tester = TestManager()
tester.add_test_list([t1])
tester.run_tests()
tester.display_first_feedback()
-
Run Code
-
Activity Submitted!
提交作品
-
下个活动
-
Stop Running Code
-
Show Chart
-
Show Console
-
Reset Code Editor
-
Codesters How To (opens in a new tab)