From 8ca0bf8b42f1b8c0dee5abdfd56b3e84aaf9f118 Mon Sep 17 00:00:00 2001 From: Loic Guegan Date: Wed, 8 May 2019 17:40:47 +0200 Subject: [PATCH] Handle snake grow --- server/game.lisp | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/server/game.lisp b/server/game.lisp index 5658c5a..207b669 100644 --- a/server/game.lisp +++ b/server/game.lisp @@ -42,6 +42,17 @@ (and (or (eq dir :left) (eq dir :right)) ; Goto left or right only if the snake is on the up or down direction (or (eq active-dir :up) (eq active-dir :down))))) +;;; Grow snake of grow-size amount (snake is growing by the tail) +(defun grow-snake (snake grow-size) + (let* ((old-size (first (array-dimensions snake))) + (new-size (+ old-size grow-size)) + (tail (aref snake (- old-size 1))) + (new-tail (coerce (make-array grow-size :initial-element tail) 'list)) + (new-snake (make-array new-size :initial-contents `(,@(coerce snake 'list) ,@new-tail)))) + new-snake)) + + + (defmethod refresh ((g game) &key (dir nil dir-supplied-p)) ;; First, update direction (with-slots ((active-dir dir)) g