Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Unsafe setting of *current-room*.

  • Loading branch information...
commit 5a206a4572dbc0176eb3c03c0e4c91eb5a35e21a 1 parent 3cdd61c
@technomancy authored
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
3  src/mire.clj
@@ -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
16 src/mire/commands.clj
@@ -7,7 +7,7 @@
(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
@@ -15,8 +15,8 @@
[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
6 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))
Please sign in to comment.
Something went wrong with that request. Please try again.