forgot to mention take verb was implemented last commit. pulled out into its own file now
This commit is contained in:
parent
2e055721c5
commit
d24aad6aaa
|
@ -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
27
take.rkt
Normal 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.")))))
|
Loading…
Reference in a new issue