-
Notifications
You must be signed in to change notification settings - Fork 1
/
dungeon.lisp
114 lines (97 loc) · 3.42 KB
/
dungeon.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
(load "colors")
(load "map")
(load "items")
(load "player")
(load "monsters")
(load "combat")
(defun view-inventory ()
(loop for item across *inventory*
for i below (length *inventory*)
do (princ (+ i 1))
(princ " ")
(princ (view-item item))
(fresh-line))
(princ "Select an item: ")
NIL)
(defun go-up ()
(let ((new-position (cons (car (player-position *player*)) (+ (cdr (player-position *player*)) 1))))
(if (get-node new-position)
(move-player new-position)
(format t "You can't go that way."))))
(defun go-down ()
(let ((new-position (cons (car (player-position *player*)) (- (cdr (player-position *player*)) 1))))
(if (get-node new-position)
(move-player new-position)
(format t "You can't go that way."))))
(defun go-right ()
(let ((new-position (cons (+ (car (player-position *player*)) 1) (cdr (player-position *player*)))))
(if (get-node new-position)
(move-player new-position)
(format t "You can't go that way."))))
(defun go-left ()
(let ((new-position (cons (- (car (player-position *player*)) 1) (cdr (player-position *player*)))))
(if (get-node new-position)
(move-player new-position)
(format t "You can't go that way."))))
(defun move-player (new-position)
(set-visited new-position)
(setf (player-position *player*) new-position))
(defun quit-game ()
(setf *running* nil))
(defun main-menu ()
(case (read)
(up (go-up))
(k (go-up))
(down (go-down))
(j (go-down))
(left (go-left))
(h (go-left))
(right (go-right))
(l (go-right))
(inventory (view-inventory))
(pickup (pickup-item))
(quit (quit-game))
(exit (quit-game))
(bye (quit-game))
(q (quit-game))
(t (progn
(format t "What?")
(main-menu))))
(when (on-monsters?)
(FIGHT! *player* (get-monsters))))
(defun user-commands ()
'("Movement:" " up down left right" "Items:" " inventory (View and manage items)" " pickup (Pick up the item at current location)" "Game:" " quit (Exit game)"))
(defun print-menu (x position-function)
(funcall position-function 0)
(format t "~a" (text-color :fg 'blue :text "Commands" :to-string t))
(let ((line-number 1))
(mapcar
(lambda (line)
(funcall position-function (incf line-number))
(text-color :bg 'red :text " ")
(format t " ~a ~%" line))
(user-commands))
(ansi-goto (cons x (incf line-number)))
(format t "~a~%" (text-color :fg 'blue :text "Inventory" :to-string t))
(let ((item-number 0))
(mapcar
(lambda (item)
(ansi-goto (cons x (incf line-number)))
(text-color :fg 'white :bg 'red :text item-number)
(incf item-number)
(format t " ~a" (view-item item)))
*inventory*)
(ansi-goto (cons x (incf line-number)))
(text-color :fg 'blue :text "Status"))))
(defun game-loop ()
(draw-map)
(main-menu)
(when *running* (game-loop)))
(defun new-game ()
(defparameter *running* t)
(defparameter *player* (make-player :health 30 :position (cons 3 3)))
(make-map 25 25)
(loop for i upto 40 do (set-contents (random-node *width* *height*) (random-item)))
(loop for i upto 40 do (set-contents (random-node *width* *height*) (list (new-hydra))))
(game-loop))
(new-game)