stage.set_background("underwater")
sprite = codesters.Sprite("fish")
sprite.go_to(-100, -220)
stage.disable_floor()
stage.set_gravity(4)
sprite.set_gravity_off()
def right_key():
sprite.move_right(20)
# add other actions...
stage.event_key("right", right_key)
def left_key():
sprite.move_left(20)
# add other actions...
stage.event_key("left", left_key)
score = 0
#my_display = codesters.Display(my_var, x, y)
score_board = codesters.Display(score, -200, 200)
def interval():
rand_x = random.randint(-250, 250)
# sprite = codesters.Circle(x, y, diameter, "color")
food = codesters.Circle(rand_x, 260, 10, "sienna")
# add any other actions...
stage.event_interval(interval, 2)
def collision(sprite, hit_sprite):
stage.remove_sprite(hit_sprite)
global score
score += 1
score_board.update(score)
# add any other actions...
sprite.event_collision(collision)
t = codesters.Teacher()
gravs = t.get_parameters_for_function('set_gravity')
freqs = t.get_parameters_for_function('event_interval')
lefts = t.get_parameters_for_function('move_left')
rights = t.get_parameters_for_function('move_right')
try:
tval1 = int(gravs[0][0])
except:
tval1 = "DNE"
try:
tval2 = float(freqs[0][1])
except:
tval2 = "DNE"
try:
tval3 = int(lefts[0][0])
except:
tval3 = "DNE"
try:
tval4 = int(rights[0][0])
except:
tval4 = "DNE"
print(tval1)
t1 = TestObjective()
t1.add_success(tval1 != 4, "Great job!")
t1.add_failure(tval1 == "DNE", "Did you delete .set_gravity()?")
t1.add_failure(tval1 == 4, "Did you change the number in .set_gravity?")
t2 = TestObjective()
t2.add_success(tval2 != 2.0, "Great job!")
t2.add_failure(tval2 == "DNE", "Did you delete the interval event handler?")
t2.add_failure(tval2 == 2, "Did you change the number in the interval event handler?")
t3 = TestObjective()
t3.add_success((tval3 == tval4) and (tval3 != 20 and tval4 != 20) and (tval3 != "DNE" and tval4 != "DNE"), "Great job!")
t3.add_failure(tval3 == "DNE", "Did you delete .move_left()?")
t3.add_failure(tval3 == 20, "Did you change the number in .move_left?")
t4 = TestObjective()
t4.add_success((tval3 == tval4) and (tval3 != 20 and tval4 != 20) and (tval3 != "DNE" and tval4 != "DNE"), "Great job!")
t4.add_failure(tval4 == "DNE", "Did you delete .move_right()?")
t4.add_failure(tval4 == 20, "Did you change the number in .move_right?")
t4.add_failure(tval3 != tval4, "Are you moving the same amount left and right?")
tester = TestManager()
tester.add_test_list([t1, t2, t3, t4])
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)