diff --git a/interpret.rkt b/interpret.rkt index 5b82ca7..5ea08ab 100644 --- a/interpret.rkt +++ b/interpret.rkt @@ -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,14 +29,42 @@ #: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))) (room-contents room))) (define (obj-names list) - (map obj-name list)) \ No newline at end of file + (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))) \ No newline at end of file diff --git a/structs.rkt b/structs.rkt index 5208d72..98b670b 100644 --- a/structs.rkt +++ b/structs.rkt @@ -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)))