From 2a98666d6d20ae5eac626b60dd8f6c647921eb75 Mon Sep 17 00:00:00 2001 From: kiefac Date: Tue, 21 May 2024 13:19:59 -0400 Subject: [PATCH] interpreter skeleton, structs for game objects --- interpret.rkt | 13 +++++++++++++ main.rkt | 7 +++++-- structs.rkt | 10 ++++++++++ 3 files changed, 28 insertions(+), 2 deletions(-) create mode 100644 interpret.rkt create mode 100644 structs.rkt diff --git a/interpret.rkt b/interpret.rkt new file mode 100644 index 0000000..3a83d3b --- /dev/null +++ b/interpret.rkt @@ -0,0 +1,13 @@ +#lang racket/gui +(provide interpret) + +; expects all strings to be uppercase +(define (interpret command) + (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 + [else (~a "I don't understand the verb " verb)])))) + diff --git a/main.rkt b/main.rkt index a150a52..dad7d7b 100644 --- a/main.rkt +++ b/main.rkt @@ -9,14 +9,17 @@ #lang racket/gui (require racket/gui/easy racket/gui/easy/operator) +(require "interpret.rkt") (define mono (send the-font-list find-or-create-font 12 'modern 'normal 'normal)) -(define/obs @log "Test field\n") +(define/obs @log "You awake in a dark room.\n") (define/obs @input "Type here...") (define (text-entered event content) (when (eqv? event 'return) - (:= @log (~a (obs-peek @log) content "\n")))) + (:= @input "") + (let ([input (string-upcase content)]) + (:= @log (~a (obs-peek @log) "> " input "\n" (interpret input) "\n"))))) (render (window diff --git a/structs.rkt b/structs.rkt new file mode 100644 index 0000000..9bbca62 --- /dev/null +++ b/structs.rkt @@ -0,0 +1,10 @@ +#lang racket/gui +(provide (all-defined-out)) + +(struct item (name size)) +(struct equipment item (type)) +(struct weapon equipment (damage)) +(struct armor equipment (resistance)) + +(struct entity (name species equipment inventory)) +