From d24aad6aaab066fb5dc159dc6283484c93a8e0ff Mon Sep 17 00:00:00 2001 From: kiefac Date: Thu, 23 May 2024 20:22:22 -0400 Subject: [PATCH] forgot to mention take verb was implemented last commit. pulled out into its own file now --- interpret.rkt | 26 ++------------------------ take.rkt | 27 +++++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 24 deletions(-) create mode 100644 take.rkt diff --git a/interpret.rkt b/interpret.rkt index e7f28e3..9295276 100644 --- a/interpret.rkt +++ b/interpret.rkt @@ -1,6 +1,7 @@ #lang racket/gui (require "structs.rkt" "look.rkt" + "take.rkt" "utils.rkt") (provide interpret) @@ -29,27 +30,4 @@ (case verb [("LOOK") (look args room1)] [("TAKE") (take args room1 plyr)] - [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."))))) \ No newline at end of file + [else (~a "I don't understand the verb " verb ".")]))))) \ No newline at end of file diff --git a/take.rkt b/take.rkt new file mode 100644 index 0000000..3027da5 --- /dev/null +++ b/take.rkt @@ -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."))))) \ No newline at end of file