Nauč se Python > Materiály > Snake Workshop for PyLadies > The Snake > Game logic

Game logic – Řešení [1]

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

# Checking if the player has gone outside of the game area
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')

new_head = new_x, new_y
self.snake.append(new_head)
del self.snake[0]

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