2024-05-21 17:19:59 +00:00
|
|
|
#lang racket/gui
|
2024-05-24 00:19:00 +00:00
|
|
|
(require "structs.rkt"
|
|
|
|
"look.rkt"
|
|
|
|
"utils.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-24 00:19:00 +00:00
|
|
|
(define room1 (room "A DARK ROOM"
|
|
|
|
(pos 0 0)
|
|
|
|
(list (armor "LEATHER CAP" (pos 5 9) 1 'helmet 2))
|
|
|
|
(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)
|
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
|
2024-05-24 00:19:00 +00:00
|
|
|
[("LOOK") (look args room1)]
|
|
|
|
[("TAKE") (take args room1 plyr)]
|
2024-05-21 18:43:13 +00:00
|
|
|
[else (~a "I don't understand the verb " verb ".")])))))
|
|
|
|
|
2024-05-24 00:19:00 +00:00
|
|
|
(define (take args where who)
|
|
|
|
(if (empty? args)
|
|
|
|
"You need to say what to take."
|
|
|
|
(let* ([args-str (string-join args)]
|
|
|
|
[split-str (string-split args-str " FROM ")]
|
|
|
|
[what-str (first split-str)]
|
|
|
|
[from-str (if (= 1 (length split-str))
|
|
|
|
'()
|
|
|
|
(last split-str))]
|
|
|
|
[from (if (empty? from-str)
|
|
|
|
where
|
|
|
|
(find-object-by-name from-str where))]
|
|
|
|
[what (find-object-by-name what-str from)])
|
|
|
|
(when (empty? from-str)
|
|
|
|
(set! from-str (object-name where)))
|
|
|
|
(if what
|
|
|
|
(if (creature? what)
|
|
|
|
"You can't take a living thing."
|
|
|
|
(if (entity? what)
|
|
|
|
"You can't take something with an inventory."
|
|
|
|
(move-obj! what from who)))
|
|
|
|
(~a "There isn't a \"" what-str "\" in this area.")))))
|