add guessing game
This commit is contained in:
parent
ff9844fa41
commit
da1c4fcb34
1 changed files with 25 additions and 0 deletions
25
guess.lisp
Executable file
25
guess.lisp
Executable file
|
@ -0,0 +1,25 @@
|
|||
(setf *random-state* (make-random-state t))
|
||||
(defparameter *ans* (+ 1 (random 9)))
|
||||
(defvar *guess*)
|
||||
(defparameter *lives* 3)
|
||||
(loop
|
||||
(if (= *lives* 0)
|
||||
(return (format t "Game over!~%"))
|
||||
(format t "~%"))
|
||||
|
||||
(format t "Guess a number:~%")
|
||||
(defparameter *guess* (read))
|
||||
(handler-case
|
||||
(check-type *guess* number)
|
||||
(simple-type-error ()
|
||||
(defparameter *guess* 0)
|
||||
)
|
||||
)
|
||||
(cond
|
||||
((= *guess* *ans*) (return (format t "Correct!~%")))
|
||||
((> *guess* *ans*) (format t "Too high!~%"))
|
||||
((< *guess* *ans*) (format t "Too low!~%"))
|
||||
)
|
||||
(defparameter *lives* (- *lives* 1))
|
||||
)
|
||||
|
Loading…
Reference in a new issue