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)
t = codesters.Teacher()
func = t.find_block('def')
try:
tval1 = func[3][1]
tval2 = func[3][0]
except:
func = "DNE"
tval1 = "DNE"
tval2 = "DNE"
try:
tval3 = len(func)
except:
tval3 = -1
try:
tval4 = t.find_function('event_collision')[0][1]
except:
tval4 = "DNE"
t1 = TestObjective()
t1.add_success('collision' in tval1 and tval3 == 4, "Great job!")
t1.add_failure(tval4 != "DNE" and tval3 < 4, "Did you delete an event from your code?")
t1.add_failure(tval1 == "DNE", "Did you add a Collision event?")
t1.add_failure('collision' not in tval1, "Did you add a Collision event?")
tester = TestManager()
tester.add_test_list([t1])
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)