Permalink
Browse files

Unsafe setting of *current-room*.

  • Loading branch information...
1 parent 3cdd61c commit 5a206a4572dbc0176eb3c03c0e4c91eb5a35e21a @technomancy committed Feb 7, 2009
Showing with 9 additions and 16 deletions.
  1. +1 −2 src/mire.clj
  2. +4 −12 src/mire/commands.clj
  3. +4 −2 src/mire/rooms.clj
View
@@ -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)]
View
@@ -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.")))
@@ -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
@@ -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)))
View
@@ -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.