look verb object description
This commit is contained in:
parent
1264f30a8a
commit
36b3ac4a48
|
@ -2,14 +2,14 @@
|
||||||
(require "structs.rkt")
|
(require "structs.rkt")
|
||||||
(provide interpret)
|
(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
|
(define room1 (room
|
||||||
(pos 0 0)
|
(pos 0 0)
|
||||||
(dim 10 10)
|
(dim 10 10)
|
||||||
(list (weapon "BIG SWORD" (pos 5 5) 4 'sword 5)
|
(list (weapon "BIG SWORD" (pos 5 5) 4 'sword 5)
|
||||||
(armor "LEATHER CAP" (pos 5 9) 1 'helmet 2))))
|
(armor "LEATHER CAP" (pos 5 9) 1 'helmet 2))))
|
||||||
|
(define plyr (player "ME" room1 '() 'human 20 '() 50))
|
||||||
(define plyr (player "YOU" room1 '() 'human 20 '() 50))
|
(set-room-contents! room1 (append (room-contents room1) (list plyr)))
|
||||||
|
|
||||||
(define (interpret in)
|
(define (interpret in)
|
||||||
(let ([command (string-upcase in)])
|
(let ([command (string-upcase in)])
|
||||||
|
@ -29,14 +29,42 @@
|
||||||
#:before-first "In this area, there is "
|
#:before-first "In this area, there is "
|
||||||
#:before-last ", and "
|
#:before-last ", and "
|
||||||
#:after-last ".")
|
#: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)
|
(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."))))))
|
(~a "The \"" what-str "\" you're looking for isn't in this area."))))))
|
||||||
|
|
||||||
(define (find-obj obj room)
|
(define (find-obj obj room)
|
||||||
(findf
|
(findf
|
||||||
(λ (arg) (string=? obj (obj-name arg)))
|
(λ (arg) (string=? obj (obj-name arg)))
|
||||||
(room-contents room)))
|
(room-contents room)))
|
||||||
|
|
||||||
(define (obj-names list)
|
(define (obj-names list)
|
||||||
(map obj-name 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)))
|
10
structs.rkt
10
structs.rkt
|
@ -12,8 +12,12 @@
|
||||||
(struct weapon equipment (damage))
|
(struct weapon equipment (damage))
|
||||||
(struct armor equipment (resistance))
|
(struct armor equipment (resistance))
|
||||||
|
|
||||||
(struct entity obj (inventory))
|
(struct entity obj ((inventory #:mutable)))
|
||||||
(struct creature entity (species health equipment))
|
(struct creature entity (species
|
||||||
|
(health #:mutable)
|
||||||
|
(equipment #:mutable)))
|
||||||
(struct player creature (capacity))
|
(struct player creature (capacity))
|
||||||
|
|
||||||
(struct room (pos size contents))
|
(struct room (pos
|
||||||
|
size
|
||||||
|
(contents #:mutable)))
|
||||||
|
|
Loading…
Reference in a new issue