Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Lære Handling Collisions | Building a Classic Snake Game
Building a Classic Snake Game
course content

Kursusindhold

Building a Classic Snake Game

book
Handling Collisions

Calling game over

We did all the hard work before when created is_body_collision() method, so now we just have to use it. First of all let's ensure that there is a game_over() when the snake head collides with its body.

py

Collision with fruit

Let's consider what should occur when the snake's head collides with a fruit. Naturally, when this happens, the fruit needs to appear in a different location, and the snake's length should increase. This concept is straightforward to understand and also implement:

py

The code snippet above detects if the snake collides with a fruit. Upon collision, the fruit moves to a new position, the snake grows longer.

Opgave

Swipe to start coding

  • Add and implement handle_collision method.
    • Add collision detection for Game Over.
    • Add collision detection with Fruit.

Løsning

Mark tasks as Completed
Switch to desktopSkift til skrivebord for at øve i den virkelige verdenFortsæt der, hvor du er, med en af nedenstående muligheder
Var alt klart?

Hvordan kan vi forbedre det?

Tak for dine kommentarer!

Sektion 1. Kapitel 10
AVAILABLE TO ULTIMATE ONLY
Vi beklager, at noget gik galt. Hvad skete der?
some-alt