basic look verb implemented, structs updated
This commit is contained in:
parent
2a98666d6d
commit
cab6404cbc
|
@ -1,13 +1,42 @@
|
||||||
#lang racket/gui
|
#lang racket/gui
|
||||||
|
(require "structs.rkt")
|
||||||
(provide interpret)
|
(provide interpret)
|
||||||
|
|
||||||
; expects all strings to be uppercase
|
;temporary hard-coded room with items for testing, before implementing procgen
|
||||||
(define (interpret command)
|
(define room1 (room
|
||||||
(if (or (string=? command "TYPE HERE...") (string=? command ""))
|
(pos 0 0)
|
||||||
"You need to type something in the box."
|
(dim 10 10)
|
||||||
(let* ([tokens (string-split command)]
|
(list (weapon "BIG SWORD" (pos 5 5) 4 'sword 5)
|
||||||
[verb (first tokens)]
|
(armor "LEATHER CAP" (pos 5 9) 1 'helmet 2))))
|
||||||
[args (rest tokens)])
|
|
||||||
(case verb
|
|
||||||
[else (~a "I don't understand the verb " verb)]))))
|
|
||||||
|
|
||||||
|
(define plyr (player "YOU" room1 '() 'human 20 '() 50))
|
||||||
|
|
||||||
|
(define (interpret in)
|
||||||
|
(let ([command (string-upcase in)])
|
||||||
|
(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
|
||||||
|
[("LOOK") (look args)]
|
||||||
|
[else (~a "I don't understand the verb " verb ".")])))))
|
||||||
|
|
||||||
|
(define (look what)
|
||||||
|
(let ([room (obj-pos plyr)])
|
||||||
|
(if (empty? what)
|
||||||
|
(string-join (obj-names (room-contents room)) ", "
|
||||||
|
#:before-first "In this area, there is "
|
||||||
|
#:before-last ", and "
|
||||||
|
#:after-last ".")
|
||||||
|
(let ([what-str (string-join what)])
|
||||||
|
(if (find-obj what-str room)
|
||||||
|
(~a "There is a " what-str " in the area.")
|
||||||
|
(~a "The \"" what-str "\" you're looking for isn't in this area."))))))
|
||||||
|
(define (find-obj obj room)
|
||||||
|
(findf
|
||||||
|
(λ (arg) (string=? obj (obj-name arg)))
|
||||||
|
(room-contents room)))
|
||||||
|
|
||||||
|
(define (obj-names list)
|
||||||
|
(map obj-name list))
|
13
structs.rkt
13
structs.rkt
|
@ -1,10 +1,19 @@
|
||||||
#lang racket/gui
|
#lang racket/gui
|
||||||
(provide (all-defined-out))
|
(provide (all-defined-out))
|
||||||
|
|
||||||
(struct item (name size))
|
(struct pos (x y))
|
||||||
|
;for clarity - an x/y pair that represents a dimension instead of a position
|
||||||
|
(struct dim pos ())
|
||||||
|
|
||||||
|
(struct obj (name pos))
|
||||||
|
|
||||||
|
(struct item obj (size))
|
||||||
(struct equipment item (type))
|
(struct equipment item (type))
|
||||||
(struct weapon equipment (damage))
|
(struct weapon equipment (damage))
|
||||||
(struct armor equipment (resistance))
|
(struct armor equipment (resistance))
|
||||||
|
|
||||||
(struct entity (name species equipment inventory))
|
(struct entity obj (inventory))
|
||||||
|
(struct creature entity (species health equipment))
|
||||||
|
(struct player creature (capacity))
|
||||||
|
|
||||||
|
(struct room (pos size contents))
|
||||||
|
|
Loading…
Reference in a new issue