stage.set_background("halfcourt")
sprite = codesters.Sprite("player1")
sprite.go_to(-175, -150)
net = codesters.Sprite("basketballnet")
net.go_to(215, 175)
stage.set_gravity(10)
sprite.set_gravity_off()
def click(sprite):
ball = codesters.Sprite("basketball")
ball.go_to(-175, -125)
ball.set_x_speed(10)
ball.set_y_speed(10)
# add other actions...
sprite.event_click(click)
stage.disable_right_wall()
t = codesters.Teacher()
event = t.find_text('collision')
handler = t.find_text('event_collision')
col_type = t.find_function('get_image_name')
try:
tval1 = event[0][1]
except:
tval1 = "DNE"
try:
tval2 = handler[0][1]
except:
tval2 = "DNE"
try:
tval3 = col_type[0][1]
except:
tval3 = "DNE"
t1 = TestObjective()
t1.add_success(tval1.replace(' ', '') == 'defcollision(net,hit_sprite):', "Great job!")
t1.add_failure(tval1 == "DNE", "Did you add a Collision with Other Sprite event to your program?")
t1.add_failure('net' not in tval1, "Did you replace the word sprite in the first line with net?")
t1.add_failure('hit_net' in tval1, "Oops! Make sure only change the first word sprite to net.")
t1.add_failure(tval1.replace(' ', '') != 'defcollision(net,hit_sprite):', "Make sure to change the sprite in the first line to net!")
t2 = TestObjective()
t2.add_success(tval2.replace('', '')=='net.event_collision(collision)', "Great job!")
t2.add_failure(tval2 == "DNE", "Oops! Did you delete the last line of your collision event?")
t2.add_failure('sprite,' in tval2, "Make sure you change the word sprite to net in the last line of your Collision Event!")
t2.add_failure(tval2.replace('', '')!='net.event_collision(collision)', "Make sure you change sprite to net in the last line of the Collision Event.")
t3 = TestObjective()
t3.add_success('hit_sprite' in tval3, "Great job!")
t3.add_failure(tval3 == "DNE", "Oops! Make sure you use Collision with Other Sprite.")
t3.add_failure('hit_net' in tval3, "Oops! Make sure you're only changing the first line of the Collision Event.")
t3.add_failure('hit_sprite' not in tval3, "Oops! Try using a Collision with Other Sprite event!")
tester = TestManager()
tester.add_test_list([t1, t2, t3])
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)