look verb object description

This commit is contained in:
kiefac 2024-05-23 15:22:05 -04:00
parent 1264f30a8a
commit 36b3ac4a48
2 changed files with 41 additions and 9 deletions

View file

@ -2,14 +2,14 @@
(require "structs.rkt")
(provide interpret)
;temporary hard-coded room with items for testing, before implementing procgen
;temporary hard-coded player and room with items for testing, before implementing procgen
(define room1 (room
(pos 0 0)
(dim 10 10)
(list (weapon "BIG SWORD" (pos 5 5) 4 'sword 5)
(armor "LEATHER CAP" (pos 5 9) 1 'helmet 2))))
(define plyr (player "YOU" room1 '() 'human 20 '() 50))
(define plyr (player "ME" room1 '() 'human 20 '() 50))
(set-room-contents! room1 (append (room-contents room1) (list plyr)))
(define (interpret in)
(let ([command (string-upcase in)])
@ -29,10 +29,13 @@
#:before-first "In this area, there is "
#:before-last ", and "
#:after-last ".")
(let ([what-str (string-join what)])
(let* ([what-str (string-join what)]
[obj (find-obj what-str room)])
(if (find-obj what-str room)
(~a "There is a " what-str " in the area.")
(~a "There is a " what-str " in the area."
(describe-obj obj))
(~a "The \"" what-str "\" you're looking for isn't in this area."))))))
(define (find-obj obj room)
(findf
(λ (arg) (string=? obj (obj-name arg)))
@ -40,3 +43,28 @@
(define (obj-names list)
(map obj-name list))
(define (describe-obj obj)
(let ([output ""])
(when (player? obj)
(append-str! output "\nIt's you."))
(when (item? obj)
(append-str! output (~a "\nIt has a size of: " (item-size obj) "."))
(when (equipment? obj)
(append-str! output (~a "\nIt is a piece of equipment of type: " (equipment-type obj) "."))
(when (weapon? obj)
(append-str! output (~a "\nIt deals " (weapon-damage obj) " damage.")))
(when (armor? obj)
(append-str! output (~a "\nIt has a damage resistance of: " (armor-resistance obj) ".")))))
(when (creature? obj)
(append-str! output (~a "\nIts species is: " (creature-species obj) "."))
(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."))))
output))
(define-syntax-rule (append-str! str1 str2)
(set! str1 (~a str1 str2)))

View file

@ -12,8 +12,12 @@
(struct weapon equipment (damage))
(struct armor equipment (resistance))
(struct entity obj (inventory))
(struct creature entity (species health equipment))
(struct entity obj ((inventory #:mutable)))
(struct creature entity (species
(health #:mutable)
(equipment #:mutable)))
(struct player creature (capacity))
(struct room (pos size contents))
(struct room (pos
size
(contents #:mutable)))