Skip to content

Commit

Permalink
Merge pull request #25 from codecurious-bln/chapter3-and-4
Browse files Browse the repository at this point in the history
Suggestions for Chapter 3 and 4
  • Loading branch information
ggpasqualino authored Feb 10, 2020
2 parents 7568e36 + 0d543f6 commit ade7d42
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
2 changes: 2 additions & 0 deletions docs/tutorial/02-draw-a-snake.md
Original file line number Diff line number Diff line change
Expand Up @@ -252,3 +252,5 @@ snake = %{body: [{9, 9}, {10, 9}, {11, 9}], size: 3}
```

![snake of 3 tiles on game screen](./../images/03-three-tile-snake.png)

[Let's make the snake move](./03-let-the-snake-move.md)
10 changes: 6 additions & 4 deletions docs/tutorial/03-let-the-snake-move.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,13 +109,13 @@ Now we're ready to implement the movement logic. Let's recall what happens durin
defp move_snake(%{snake: snake} = state) do
%{body: body, direction: direction} = snake

# new head
# new head's position
[head | _] = body
new_head = move(state, head, direction)

# truncate body
size = length(body)
new_body = Enum.take([new_head | body], size)
# place a new head on the tile that we want to move to
# and remove the last tile from the snake tail
new_body = List.delete_at([new_head | body], -1)

state
|> put_in([:snake, :body], new_body)
Expand Down Expand Up @@ -176,3 +176,5 @@ config :snake, :viewport, %{
```

![snake moving](./../images/04-moving-snake.gif)

[Let's control the snake](./04-control-snake-movements.md)

0 comments on commit ade7d42

Please sign in to comment.