Nauč se Python > Kurzy > Hadí workshop pro PyLadies > Had > Logika hry Had

Logika hry Had – Řešení [5]

    def move(self):
        old_x, old_y = self.snake[-1]
        dir_x, dir_y = self.snake_direction
        new_x = old_x + dir_x
        new_y = old_y + dir_y
        new_head = new_x, new_y

        # Kontrola vylezení z hrací plochy
        if new_x < 0:
            exit('GAME OVER')
        if new_y < 0:
            exit('GAME OVER')
        if new_x >= self.width:
            exit('GAME OVER')
        if new_y >= self.height:
            exit('GAME OVER')

        self.snake.append(new_head)
        if new_head in self.food:
            self.food.remove(new_head)
        else:
            del self.snake[0]

Toto je stránka lekce z kurzu, který probíhá nebo proběhl naživo s instruktorem.