interpreter skeleton, structs for game objects

This commit is contained in:
kiefac 2024-05-21 13:19:59 -04:00
parent 3b622ce3c6
commit 2a98666d6d
3 changed files with 28 additions and 2 deletions

13
interpret.rkt Normal file
View file

@ -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)]))))

View file

@ -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

10
structs.rkt Normal file
View file

@ -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))