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:
parent
d24aad6aaa
commit
45931c006c
|
@ -7,15 +7,18 @@
|
|||
|
||||
;temporary hard-coded player and room with items for testing, before implementing procgen
|
||||
(define room1 (room "A DARK ROOM"
|
||||
(pos 0 0)
|
||||
(list (armor "LEATHER CAP" (pos 5 9) 1 'helmet 2))
|
||||
(list (armor "LEATHER CAP" 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)))
|
||||
(add-to-inventory! room1 (entity "CHEST"
|
||||
room1
|
||||
(list (weapon "BIG SWORD" (pos 5 5) 4 'sword 5))))
|
||||
|
||||
(define plyr (player "YOU"
|
||||
room1
|
||||
'()
|
||||
'human 20 '() 50))
|
||||
(add-to-inventory! room1 plyr)
|
||||
|
@ -28,6 +31,6 @@
|
|||
[verb (first tokens)]
|
||||
[args (rest tokens)])
|
||||
(case verb
|
||||
[("LOOK") (look args room1)]
|
||||
[("TAKE") (take args room1 plyr)]
|
||||
[("LOOK" "OBSERVE") (look args room1)]
|
||||
[("TAKE" "GRAB" "GIMME") (take args room1 plyr)]
|
||||
[else (~a "I don't understand the verb " verb ".")])))))
|
6
look.rkt
6
look.rkt
|
@ -6,7 +6,7 @@
|
|||
|
||||
(define (look what where)
|
||||
(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)]
|
||||
[obj (find-object-by-name what-str where)])
|
||||
(if obj
|
||||
|
@ -34,9 +34,9 @@
|
|||
(append-str! output (~a "\nIt's at " (creature-health obj) "HP."))
|
||||
(if (empty? (creature-equipment obj))
|
||||
(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
|
||||
(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))
|
29
main.rkt
29
main.rkt
|
@ -24,18 +24,17 @@
|
|||
(render
|
||||
(window
|
||||
#:title "Prok"
|
||||
(hpanel
|
||||
(vpanel
|
||||
(input @log
|
||||
;hack to prevent text editing without disabling the editor
|
||||
(λ (ev cnt) (let ([old (obs-peek @log)]) (:= @log "") (:= @log old)))
|
||||
#:style '(multiple)
|
||||
#:min-size '(600 400)
|
||||
#:font mono)
|
||||
(input @input
|
||||
text-entered
|
||||
#:enabled? #t
|
||||
#:style '(single)
|
||||
#:font mono))
|
||||
(vpanel
|
||||
))))
|
||||
(vpanel
|
||||
(input @log
|
||||
;hack to prevent text editing without disabling the editor
|
||||
(λ (ev cnt) (let ([old (obs-peek @log)]) (:= @log "") (:= @log old)))
|
||||
#:style '(multiple)
|
||||
#:min-size '(600 400)
|
||||
#:stretch '(#t #t)
|
||||
#:font mono)
|
||||
(input @input
|
||||
text-entered
|
||||
#:enabled? #t
|
||||
#:style '(single)
|
||||
#:stretch '(#t #f)
|
||||
#:font mono))))
|
|
@ -5,7 +5,7 @@
|
|||
;for clarity - an x/y pair that represents a dimension instead of a position
|
||||
(struct dim pos ())
|
||||
|
||||
(struct object (name pos))
|
||||
(struct object (name))
|
||||
|
||||
(struct item object (size))
|
||||
(struct equipment item (type))
|
||||
|
|
24
utils.rkt
24
utils.rkt
|
@ -11,16 +11,22 @@
|
|||
(append (creature-equipment where) (entity-inventory where))
|
||||
(entity-inventory where))))
|
||||
|
||||
(define (object-names list)
|
||||
(map object-name list))
|
||||
(define (object-names where)
|
||||
(map object-name (entity-inventory where)))
|
||||
|
||||
(define (oxford-object-names where)
|
||||
(let ([lst (object-names (entity-inventory where))])
|
||||
(if (empty? lst)
|
||||
"nothing."
|
||||
(string-join lst ", "
|
||||
#:before-last ", and "
|
||||
#:after-last "."))))
|
||||
(define (equipment-types creature)
|
||||
(filter string?
|
||||
(map (λ (e)
|
||||
(unless (string=? (equipment-type e) "invis")
|
||||
(equipment-type e)))
|
||||
(creature-equipment creature))))
|
||||
|
||||
(define (oxford-list lst)
|
||||
(if (empty? lst)
|
||||
"nothing."
|
||||
(string-join lst ", "
|
||||
#:before-last ", and "
|
||||
#:after-last ".")))
|
||||
|
||||
(define-syntax-rule (append-str! str1 str2)
|
||||
(set! str1 (~a str1 str2)))
|
||||
|
|
Loading…
Reference in a new issue