forgot to mention take verb was implemented last commit. pulled out into its own file now

This commit is contained in:
kiefac 2024-05-23 20:22:22 -04:00
parent 2e055721c5
commit d24aad6aaa
2 changed files with 29 additions and 24 deletions

View file

@ -1,6 +1,7 @@
#lang racket/gui #lang racket/gui
(require "structs.rkt" (require "structs.rkt"
"look.rkt" "look.rkt"
"take.rkt"
"utils.rkt") "utils.rkt")
(provide interpret) (provide interpret)
@ -30,26 +31,3 @@
[("LOOK") (look args room1)] [("LOOK") (look args room1)]
[("TAKE") (take args room1 plyr)] [("TAKE") (take args room1 plyr)]
[else (~a "I don't understand the verb " verb ".")]))))) [else (~a "I don't understand the verb " verb ".")])))))
(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.")))))

27
take.rkt Normal file
View file

@ -0,0 +1,27 @@
#lang racket/gui
(require "utils.rkt"
"structs.rkt")
(provide take)
(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.")))))