stage.set_background("underwater")
sprite = codesters.Sprite("fish")
sprite.go_to(0, -220)
stage.disable_floor()
stage.set_gravity(8)
sprite.set_gravity_off()
score = 0
#my_display = codesters.Display(my_var, x, y)
score_board = codesters.Display(score, -200, 150)
def right_key():
sprite.move_right(30)
# add other actions...
stage.event_key("right", right_key)
def left_key():
sprite.move_left(30)
# add other actions...
stage.event_key("left", left_key)
def interval():
x = random.randint(-250, 250)
# sprite = codesters.Circle(x, y, diameter, "color")
food = codesters.Circle(x, 260, 10, "sienna")
# add any other actions...
stage.event_interval(interval, 1)
def collision(sprite, hit_sprite):
global score
stage.remove_sprite(hit_sprite)
score += 1
score_board.update(score)
# add any other actions...
sprite.event_collision(collision)
t = codesters.Teacher()
set_gravitys = t.find_function("set_gravity_off")
rand_range = t.get_parameters_for_function('randint')
rands = t.find_function('randint')
try:
tval1 = stage.get_gravity()
except:
tval1 = "DNE"
try:
tval2 = set_gravitys[0][1]
except:
tval2 = "DNE"
try:
tval3 = int(rand_range[1][0])
tval4 = int(rand_range[1][1])
except:
tval3 = "DNE"
tval4 = "DNE"
try:
tval5a = int(rands[1][0])
tval5b = t.get_indent_at_line(tval5a)
except:
tval5a = "DNE"
tval5b = -1
try:
tval6a = int(t.find_text('interval():')[0][0])
tval6b = int(t.find_text("event_interval")[0][0])
except:
tval6a = -1
tval6b = -1
t1 = TestObjective()
t1.add_success(tval1 == 0.0, "Great Job!")
t1.add_failure(tval1 != 0, "Did you delete stage.set_gravity?")
t2 = TestObjective()
t2.add_success(tval2 == "DNE", "Great job!")
t2.add_failure(tval2 != "DNE", "Did you delete sprite.set_gravity_off()?")
t3 = TestObjective()
t3.add_success(tval3 == -15 and tval4 == -5 and tval6a < tval5a < tval6b, "Great job!")
t3.add_failure(tval3 == "DNE", "Did you add a Random Integer command inside your interval event?")
t3.add_failure(tval3 != "DNE" and not (tval6a < tval5a < tval6b),"Did you add Random Integer inside the interval event?")
t3.add_failure(tval3 == 1 and tval4 == 10, "Did you change the range of your new random.randint()?")
t3.add_failure(tval5b < 4, "Make sure you indent your Random Integer command inside your interval event.")
t3.add_failure(tval5b > 4, "Make sure you indent your Random Integer command only 4 spaces inside your interval event.")
t3.add_creative((tval3 != 1 and tval3 != -15) and (tval4 != 10 and tval4 != -5), "That's a good range too.")
tester = TestManager()
tester.add_test_list([t1, t2, t3])
tester.run_tests()
tester.display_first_feedback()
-
Run Code
-
Activity Submitted!
Enviar Trabajo
-
Actividad Siguiente
-
Stop Running Code
-
Show Chart
-
Show Console
-
Reset Code Editor
-
Codesters How To (opens in a new tab)