-
Notifications
You must be signed in to change notification settings - Fork 1
/
combat.lisp
53 lines (42 loc) · 1.58 KB
/
combat.lisp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
(defun FIGHT! (player monsters)
; ----- inner functions -----
(labels ((display-intro ()
(princ "----- FIGHT TO THE DEATH! -----")
(terpri))
(display-monsters ()
(loop for monster in monsters
for i from 0
do (format t "~d. ~a~%" i (monster-to-str monster))))
(options ()
(player-attack-options player))
(display-separator ()
(format t "--------------------------------~%"))
(display-options ()
(loop for option in (options)
for i from 0
do (format t "~d. ~a~%" i option)))
(valid-option? (option)
(and (integerp option)
(<= 0 option)
(< option (length (options)))))
(get-option ()
(let ((option (read)))
(if (valid-option? option)
option
(get-option))))
(player-turn ()
(display-monsters)
(display-separator)
(display-options)
(player-attack player (get-option) monsters))
(monsters-turn ()
(loop for monster in monsters
do (monster-attack monster player)))
(play-round ()
(player-turn)
(monsters-turn)))
; ----- steps in a fight -----
(display-intro)
(if (every #'monster-dead? monsters)
nil
(play-round))))