Skip to content
This repository has been archived by the owner on Oct 21, 2021. It is now read-only.

Commit

Permalink
Unsafe setting of *current-room*.
Browse files Browse the repository at this point in the history
  • Loading branch information
technomancy committed Feb 7, 2009
1 parent 3cdd61c commit 5a206a4
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 16 deletions.
3 changes: 1 addition & 2 deletions src/mire.clj
Expand Up @@ -9,8 +9,7 @@

(defn- mire-handle-client [in out]
(binding [*in* (reader in)
*out* (writer out)
*current-room* (rooms :start)]
*out* (writer out)]
(println (look))
(print prompt) (flush)
(loop [input (read-line)]
Expand Down
16 changes: 4 additions & 12 deletions src/mire/commands.clj
Expand Up @@ -7,16 +7,16 @@
(defn look "Get a description of the surrounding environs and its contents."
[]
(str (:desc *current-room*)
"\nExits: " (keys (:exits room))
"\nExits: " (keys (:exits *current-room*))
".\n"))

(defn move
"\"♬ We gotta get out of this place... ♪\" Give a direction."
[direction]
(let [target-name ((:exits *current-room*) (keyword direction))
target (rooms target-name)]
(if target-name
(do (set! *current-room* target)
(if target
(do (set-current-room target)
(look))
"You can't go that way.")))

Expand All @@ -29,9 +29,6 @@
"west" (fn [] (move :west)),
"look" look})

(def unknown-responses ["What you say?" "Speak up!" "I don't get it."
"Please rephrase that." "Your words confuse me."])

;; Command handling

(defn execute
Expand All @@ -40,9 +37,4 @@
(let [input-words (re-split #"\s+" input)
command (first input-words)
args (rest input-words)]
(try
(apply (commands command) args)
(catch java.lang.NullPointerException _
(pick-rand unknown-responses))
(catch java.lang.IllegalArgumentException _
"You can't do that."))))
(apply (commands command) args)))
6 changes: 4 additions & 2 deletions src/mire/rooms.clj
@@ -1,11 +1,13 @@
(ns mire.rooms
(:use [clojure.contrib str-utils]))

(declare *current-room*)

(def rooms
{:start {:desc "You find yourself in a round room with a pillar in the middle."
:exits {:north :closet}}
:closet {:desc "You are in a cramped closet."
:exits {:south :start}}})

(def *current-room* (rooms :start))

(defn set-current-room [target]
(def *current-room* target))

0 comments on commit 5a206a4

Please sign in to comment.