ADVERTENCIA : Este programa tiene un error de lógica. La vaca tiene hambre y quiere comerse el heno, ¡pero no pasa nada!

REGLA: Un controlador de eventos vincula un sprite a una función que se llama cada vez que se activa el evento.

  • Hacer clic Corre y mira lo que pasa. Mire en el código para ver dónde debería estar comiendo el heno la vaca.
  • Arregle el programa agregando un controlador de eventos a la función main() para que ocurra el evento de colisión.
  • Hacer clic Ejecute para probar si arregló el programa. Cuando esté arreglado, haga clic en Enviar y siguiente

    To navigate the page using the TAB key, first press ESC to exit the code editor.

    def add_sprite(): """ Add cow sprite to the stage and set its speed """ cow = codesters.Sprite("cow",-400, -150) cow.set_x_speed(3) return cow def setup_stage(): """ Set up the stage with background and sprites """ stage.set_background("barn") stage.disable_right_wall() hay = codesters.Sprite("hay",-150,-150) hay = codesters.Sprite("hay",0,-150) hay = codesters.Sprite("hay",150,-150) def collision(sprite, hit_sprite): """ Collision event for the cow to eat hay """ if hit_sprite.get_image_name() == "hay": sprite.say("yum!",.2) hit_sprite.hide() def main(): """ Sets up the program and calls other functions """ setup_stage() sprite = add_sprite() main()
    • Run Code
    • Enviar Trabajo
    • Actividad Siguiente
    • Show Console
    • Reset Code Editor
    • Codesters How To (opens in a new tab)