Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Corrige movimento para baixo, mexendo só a cabeça, e não a cobra toda…
… de uma vez
  • Loading branch information
flavioamieiro committed Mar 28, 2012
1 parent 4ceeabd commit 718ccd1
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
7 changes: 4 additions & 3 deletions snake_game.py
Expand Up @@ -54,9 +54,10 @@ def __init__(self):
self.positions = [[5, 3], [5, 4], [5, 5]]

def move_down(self):
for n, pos in enumerate(self.positions):
pos[1] += 1
self.positions[n] = pos
tail = self.positions.pop(0) # remove the 'tail'
previous_head = self.positions[-1]
new_head = [previous_head[0], (previous_head[1] + 1)]
self.positions.append(new_head)

def move_left(self):
tail = self.positions.pop(0) # remove the 'tail'
Expand Down
6 changes: 6 additions & 0 deletions snake_test.py
Expand Up @@ -12,6 +12,12 @@ def test_move_snake_down_from_initial_position(self):
snake.move_down()
self.assertEqual(snake.positions, [[5, 4], [5, 5], [5, 6]])

def test_move_horizontal_snake_down(self):
snake = Snake()
snake.positions = [[4, 3], [5, 3], [6, 3]]
snake.move_down()
self.assertEqual(snake.positions, [[5, 3], [6, 3], [6, 4]])

def test_move_snake_left_from_initial_position(self):
snake = Snake()
snake.move_left()
Expand Down

0 comments on commit 718ccd1

Please sign in to comment.