Skip to content
This repository was archived by the owner on May 20, 2021. It is now read-only.

Commit 14141e3

Browse files
committed
Don't allow left<->right up<->down
1 parent db7d8a0 commit 14141e3

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

snake.lisp

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,24 @@
3737
"The rest of the SNAKE."
3838
(rest (segments-of snake)))
3939

40-
;; TODO(bsvercl): Don't allow Left<->Right Up<->Down
4140
(defun change-direction (snake direction)
4241
"Modify DIRECTION of SNAKE with NEW-DIRECTION."
43-
(setf (direction-of snake) direction))
42+
(let ((current (direction-of snake)))
43+
;; TODO: This is so bad.
44+
(cond
45+
((and (eq current :left)
46+
(eq direction :right))
47+
(setf (direction-of snake) :left))
48+
((and (eq current :right)
49+
(eq direction :left))
50+
(setf (direction-of snake) :right))
51+
((and (eq current :up)
52+
(eq direction :down))
53+
(setf (direction-of snake) :up))
54+
((and (eq current :down)
55+
(eq direction :up))
56+
(setf (direction-of snake) :down))
57+
(t (setf (direction-of snake) direction)))))
4458

4559
(defun advance (snake ate-food-p)
4660
"Moves the SNAKE according to it's DIRECTION."

0 commit comments

Comments
 (0)