You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
112 lines
2.7 KiB
Racket
112 lines
2.7 KiB
Racket
9 years ago
|
#lang racket
|
||
|
(require "txtadv.rkt")
|
||
9 years ago
|
|
||
|
;; Verbs ----------------------------------------
|
||
9 years ago
|
;; Declare all the verbs that can be used in the game.
|
||
|
;; Each verb has a canonical name, a `_' if it needs
|
||
|
;; an object (i.e., a transitive verb), a set of aliases,
|
||
|
;; and a printed form.
|
||
9 years ago
|
|
||
|
(define-verbs all-verbs
|
||
|
[north (= n) "go north"]
|
||
|
[south (= s) "go south"]
|
||
|
[east (= e) "go east"]
|
||
|
[west (= w) "go west"]
|
||
|
[up (=) "go up"]
|
||
|
[down (=) "go down"]
|
||
|
[in (= enter) "enter"]
|
||
|
[out (= leave) "leave"]
|
||
|
[get _ (= grab take) "take"]
|
||
|
[put _ (= drop leave) "drop"]
|
||
|
[open _ (= unlock) "open"]
|
||
|
[close _ (= lock) "close"]
|
||
|
[knock _]
|
||
|
[quit (= exit) "quit"]
|
||
|
[look (= show) "look"]
|
||
|
[inventory (=) "check inventory"]
|
||
|
[help]
|
||
|
[save]
|
||
|
[load])
|
||
|
|
||
|
;; Global actions ----------------------------------------
|
||
9 years ago
|
;; Handle verbs that work anywhere.
|
||
9 years ago
|
|
||
|
(define-everywhere everywhere-actions
|
||
|
([quit (begin (printf "Bye!\n") (exit))]
|
||
|
[look (show-current-place)]
|
||
|
[inventory (show-inventory)]
|
||
|
[save (save-game)]
|
||
|
[load (load-game)]
|
||
|
[help (show-help)]))
|
||
|
|
||
|
;; Objects ----------------------------------------
|
||
9 years ago
|
;; Each object handles a set of transitive verbs.
|
||
9 years ago
|
|
||
|
(define-thing cactus
|
||
|
[get "Ouch!"])
|
||
|
|
||
|
(define-thing door
|
||
|
[open (if (have-thing? key)
|
||
|
(begin
|
||
|
(set-thing-state! door 'open)
|
||
|
"The door is now unlocked and open.")
|
||
|
"The door is locked.")]
|
||
|
[close (begin
|
||
|
(set-thing-state! door #f)
|
||
|
"The door is now closed.")]
|
||
|
[knock "No one is home."])
|
||
|
|
||
|
(define-thing key
|
||
|
[get (if (have-thing? key)
|
||
|
"You already have the key."
|
||
|
(begin
|
||
|
(take-thing! key)
|
||
|
"You now have the key."))]
|
||
|
[put (if (have-thing? key)
|
||
|
(begin
|
||
|
(drop-thing! key)
|
||
|
"You have dropped the key.")
|
||
|
"You don't have the key.")])
|
||
|
|
||
|
(define-thing trophy
|
||
|
[get (begin
|
||
|
(take-thing! trophy)
|
||
|
"You win!")])
|
||
|
|
||
|
;; Places ----------------------------------------
|
||
9 years ago
|
;; Each place handles a set of non-transitive verbs.
|
||
9 years ago
|
|
||
|
(define-place meadow
|
||
|
"You're standing in a meadow. There is a house to the north."
|
||
|
[]
|
||
|
([north house-front]
|
||
|
[south desert]))
|
||
|
|
||
|
(define-place house-front
|
||
|
"You are standing in front of a house."
|
||
|
[door]
|
||
|
([in (if (eq? (thing-state door) 'open)
|
||
|
room
|
||
|
"The door is not open.")]
|
||
|
[south meadow]))
|
||
|
|
||
|
(define-place desert
|
||
|
"You're in a desert. There is nothing for miles around."
|
||
|
[cactus key]
|
||
|
([north meadow]
|
||
|
[south desert]
|
||
|
[east desert]
|
||
|
[west desert]))
|
||
|
|
||
|
(define-place room
|
||
|
"You're in the house."
|
||
|
[trophy]
|
||
|
([out house-front]))
|
||
|
|
||
|
|
||
9 years ago
|
;; Go! ---------------------------------------------------
|
||
|
|
||
|
(start-game meadow
|
||
|
all-verbs
|
||
|
everywhere-actions)
|