interpreter skeleton, structs for game objects
This commit is contained in:
parent
3b622ce3c6
commit
2a98666d6d
13
interpret.rkt
Normal file
13
interpret.rkt
Normal 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)]))))
|
||||
|
7
main.rkt
7
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
|
||||
|
|
10
structs.rkt
Normal file
10
structs.rkt
Normal 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))
|
||||
|
Loading…
Reference in a new issue