pull out string-join to use elsewhere, remove useless hpanel/vpanel, remove useless pos variable from item struct, reformat hardcoded room + add a rat

This commit is contained in:
kiefac 2024-05-25 20:42:15 -04:00
parent d24aad6aaa
commit 45931c006c
5 changed files with 44 additions and 36 deletions

View file

@ -7,15 +7,18 @@
;temporary hard-coded player and room with items for testing, before implementing procgen ;temporary hard-coded player and room with items for testing, before implementing procgen
(define room1 (room "A DARK ROOM" (define room1 (room "A DARK ROOM"
(pos 0 0) (list (armor "LEATHER CAP" 1 "helmet" 2)
(list (armor "LEATHER CAP" (pos 5 9) 1 'helmet 2)) (entity "CHEST"
(list (weapon "BIG SWORD" 4 "sword" 5)))
(creature "STINKY RAT"
(list (item "RAT FLESH" 1))
'rat
6
(list (weapon "YELLOW TOOTH" 1 "invis" 2)
(weapon "SHARP CLAW" 1 "invis" 4))))
(dim 0 0))) (dim 0 0)))
(add-to-inventory! room1 (entity "CHEST"
room1
(list (weapon "BIG SWORD" (pos 5 5) 4 'sword 5))))
(define plyr (player "YOU" (define plyr (player "YOU"
room1
'() '()
'human 20 '() 50)) 'human 20 '() 50))
(add-to-inventory! room1 plyr) (add-to-inventory! room1 plyr)
@ -28,6 +31,6 @@
[verb (first tokens)] [verb (first tokens)]
[args (rest tokens)]) [args (rest tokens)])
(case verb (case verb
[("LOOK") (look args room1)] [("LOOK" "OBSERVE") (look args room1)]
[("TAKE") (take args room1 plyr)] [("TAKE" "GRAB" "GIMME") (take args room1 plyr)]
[else (~a "I don't understand the verb " verb ".")]))))) [else (~a "I don't understand the verb " verb ".")])))))

View file

@ -6,7 +6,7 @@
(define (look what where) (define (look what where)
(if (empty? what) (if (empty? what)
(~a "In this area, there is: " (oxford-object-names where)) (~a "In this area, there is: " (oxford-list (object-names where)))
(let* ([what-str (string-join what)] (let* ([what-str (string-join what)]
[obj (find-object-by-name what-str where)]) [obj (find-object-by-name what-str where)])
(if obj (if obj
@ -34,9 +34,9 @@
(append-str! output (~a "\nIt's at " (creature-health obj) "HP.")) (append-str! output (~a "\nIt's at " (creature-health obj) "HP."))
(if (empty? (creature-equipment obj)) (if (empty? (creature-equipment obj))
(append-str! output (~a "\nIt doesn't look like it's carrying anything.")) (append-str! output (~a "\nIt doesn't look like it's carrying anything."))
(append-str! output (~a "\nIt looks like it's carrying something.")))] (append-str! output (~a "\nIt looks like it's carrying: " (oxford-list (equipment-types obj)))))]
[else [else
(when (entity? obj) (when (entity? obj)
(append-str! output (~a "\nInside is: " (oxford-object-names obj))))] (append-str! output (~a "\nInside is: " (oxford-list (object-names obj)))))]
) )
output)) output))

View file

@ -24,18 +24,17 @@
(render (render
(window (window
#:title "Prok" #:title "Prok"
(hpanel
(vpanel (vpanel
(input @log (input @log
;hack to prevent text editing without disabling the editor ;hack to prevent text editing without disabling the editor
(λ (ev cnt) (let ([old (obs-peek @log)]) (:= @log "") (:= @log old))) (λ (ev cnt) (let ([old (obs-peek @log)]) (:= @log "") (:= @log old)))
#:style '(multiple) #:style '(multiple)
#:min-size '(600 400) #:min-size '(600 400)
#:stretch '(#t #t)
#:font mono) #:font mono)
(input @input (input @input
text-entered text-entered
#:enabled? #t #:enabled? #t
#:style '(single) #:style '(single)
#:font mono)) #:stretch '(#t #f)
(vpanel #:font mono))))
))))

View file

@ -5,7 +5,7 @@
;for clarity - an x/y pair that represents a dimension instead of a position ;for clarity - an x/y pair that represents a dimension instead of a position
(struct dim pos ()) (struct dim pos ())
(struct object (name pos)) (struct object (name))
(struct item object (size)) (struct item object (size))
(struct equipment item (type)) (struct equipment item (type))

View file

@ -11,16 +11,22 @@
(append (creature-equipment where) (entity-inventory where)) (append (creature-equipment where) (entity-inventory where))
(entity-inventory where)))) (entity-inventory where))))
(define (object-names list) (define (object-names where)
(map object-name list)) (map object-name (entity-inventory where)))
(define (oxford-object-names where) (define (equipment-types creature)
(let ([lst (object-names (entity-inventory where))]) (filter string?
(map (λ (e)
(unless (string=? (equipment-type e) "invis")
(equipment-type e)))
(creature-equipment creature))))
(define (oxford-list lst)
(if (empty? lst) (if (empty? lst)
"nothing." "nothing."
(string-join lst ", " (string-join lst ", "
#:before-last ", and " #:before-last ", and "
#:after-last ".")))) #:after-last ".")))
(define-syntax-rule (append-str! str1 str2) (define-syntax-rule (append-str! str1 str2)
(set! str1 (~a str1 str2))) (set! str1 (~a str1 str2)))