2024-05-21 17:19:59 +00:00
|
|
|
#lang racket/gui
|
2024-05-21 18:43:13 +00:00
|
|
|
(require "structs.rkt")
|
2024-05-21 17:19:59 +00:00
|
|
|
(provide interpret)
|
|
|
|
|
2024-05-23 19:22:05 +00:00
|
|
|
;temporary hard-coded player and room with items for testing, before implementing procgen
|
2024-05-21 18:43:13 +00:00
|
|
|
(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))))
|
2024-05-23 21:11:42 +00:00
|
|
|
(define plyr (player "YOU" room1 '() 'human 20 '() 50))
|
2024-05-23 19:22:05 +00:00
|
|
|
(set-room-contents! room1 (append (room-contents room1) (list plyr)))
|
2024-05-21 18:43:13 +00:00
|
|
|
|
|
|
|
(define (interpret in)
|
|
|
|
(let ([command (string-upcase in)])
|
|
|
|
(if (or (string=? command "TYPE HERE...") (string=? command ""))
|
|
|
|
"You need to type something in the box."
|
|
|
|
(let* ([tokens (string-split command)]
|
|
|
|
[verb (first tokens)]
|
|
|
|
[args (rest tokens)])
|
|
|
|
(case verb
|
|
|
|
[("LOOK") (look args)]
|
|
|
|
[else (~a "I don't understand the verb " verb ".")])))))
|
|
|
|
|
|
|
|
(define (look what)
|
|
|
|
(let ([room (obj-pos plyr)])
|
|
|
|
(if (empty? what)
|
|
|
|
(string-join (obj-names (room-contents room)) ", "
|
2024-05-23 21:11:42 +00:00
|
|
|
#:before-first "In this area, there is: "
|
2024-05-21 18:43:13 +00:00
|
|
|
#:before-last ", and "
|
|
|
|
#:after-last ".")
|
2024-05-23 19:22:05 +00:00
|
|
|
(let* ([what-str (string-join what)]
|
|
|
|
[obj (find-obj what-str room)])
|
2024-05-21 18:43:13 +00:00
|
|
|
(if (find-obj what-str room)
|
2024-05-23 19:22:05 +00:00
|
|
|
(~a "There is a " what-str " in the area."
|
|
|
|
(describe-obj obj))
|
2024-05-21 18:43:13 +00:00
|
|
|
(~a "The \"" what-str "\" you're looking for isn't in this area."))))))
|
2024-05-23 19:22:05 +00:00
|
|
|
|
2024-05-21 18:43:13 +00:00
|
|
|
(define (find-obj obj room)
|
|
|
|
(findf
|
|
|
|
(λ (arg) (string=? obj (obj-name arg)))
|
|
|
|
(room-contents room)))
|
|
|
|
|
|
|
|
(define (obj-names list)
|
2024-05-23 19:22:05 +00:00
|
|
|
(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)))
|