diff options
| author | Charles <sircharlesaze@gmail.com> | 2019-12-08 12:24:57 +0100 |
|---|---|---|
| committer | Charles <sircharlesaze@gmail.com> | 2019-12-08 12:24:57 +0100 |
| commit | 90e41c14a5e7fba3c6ad25afe729ba6bdbd73f88 (patch) | |
| tree | 1112039ad0594a57f1e06352e0d7335733808256 /game.adb | |
| parent | 4b367c25b0365be8fe38381136353a659d5ce545 (diff) | |
| download | snake-master.tar.gz snake-master.tar.bz2 snake-master.zip | |
Diffstat (limited to 'game.adb')
| -rw-r--r-- | game.adb | 14 |
1 files changed, 13 insertions, 1 deletions
@@ -21,7 +21,7 @@ package body Game is function Next(game: in out T_Game) return Boolean is new_head: constant T_Position := Next_Head(game); begin - if not In_Border(game, new_head) then + if not In_Border(game, new_head) or else In_Body(game, new_head) then return false; end if; Enqueue(game.snake, new_head); @@ -94,4 +94,16 @@ package body Game is return pos.y >= 1 and pos.y <= game.height and pos.x >= 1 and pos.x <= game.width; end In_Border; + function In_Body(game: T_Game; pos: T_Position) return Boolean is + cursor: T_List := game.snake.front; + begin + while cursor /= null loop + if pos = cursor.data then + return true; + end if; + cursor := cursor.next; + end loop; + return false; + end In_Body; + end Game; |
