aboutsummaryrefslogtreecommitdiff
path: root/game.adb
diff options
context:
space:
mode:
authorCharles <sircharlesaze@gmail.com>2019-12-08 12:24:57 +0100
committerCharles <sircharlesaze@gmail.com>2019-12-08 12:24:57 +0100
commit90e41c14a5e7fba3c6ad25afe729ba6bdbd73f88 (patch)
tree1112039ad0594a57f1e06352e0d7335733808256 /game.adb
parent4b367c25b0365be8fe38381136353a659d5ce545 (diff)
downloadsnake-master.tar.gz
snake-master.tar.bz2
snake-master.zip
Game over if move in snake bodyHEADmaster
Diffstat (limited to 'game.adb')
-rw-r--r--game.adb14
1 files changed, 13 insertions, 1 deletions
diff --git a/game.adb b/game.adb
index cd403e2..b30731c 100644
--- a/game.adb
+++ b/game.adb
@@ -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;