Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Mire: Multple players don't interfere with each other's rooms anymore

  • Loading branch information...
commit cbd256f7c90ba915b618b225f01538fb8778f1e2 1 parent 56fd631
@apauley authored
View
8 PeepCode/Clojure/mire/src/mire.clj
@@ -1,5 +1,5 @@
(ns mire
- (:use [mire commands])
+ (:use [mire commands rooms])
(:use [clojure.contrib server-socket duck-streams]))
(def port 3333)
@@ -12,8 +12,10 @@
(defn- mire-handle-client [in out]
"Private function to handle client requests"
- (binding [*in* (reader in) ; Re-assign stdin and stdout
- *out* (writer out)]
+ ; Re-assign stdin and stdout
+ (binding [*in* (reader in)
+ *out* (writer out)
+ *current-room* (rooms :start)]
(println (look))
(print-prompt)
(loop [input (read-line)]
View
20 PeepCode/Clojure/mire/src/mire/commands.clj
@@ -2,6 +2,11 @@
(:use [mire rooms])
(:use [clojure.contrib str-utils]))
+(defn look []
+ "Get a description of the current room"
+ (str (:desc *current-room*)
+ "\nExits: " (keys (:exits *current-room*))))
+
(defn move
"We gotta get out of this place... Give a direction."
[direction]
@@ -12,17 +17,12 @@
(look))
"No way")))
-(defn look []
- "Get a description of the current room"
- (str (:desc *current-room*)
- "\nExits: " (keys (:exits *current-room*))))
-
(def commands {:move move,
- :north (fn [] (move :north))
- :east (fn [] (move :east))
- :south (fn [] (move :south))
- :west (fn [] (move :west))
- :look look
+ :north (fn [] (move :north)),
+ :east (fn [] (move :east)),
+ :south (fn [] (move :south)),
+ :west (fn [] (move :west)),
+ :look look,
:wtf (fn []
"Yeah sure, I'll do that right after you grow a brain.")})
View
6 PeepCode/Clojure/mire/src/mire/rooms.clj
@@ -6,7 +6,7 @@
:closet {:desc "You are in a cramped closet. You feel a slight breeze."
:exits {:south :start}}})
-(defn set-current-room [target]
- (def *current-room* target))
+(def *current-room*)
-(set-current-room (rooms :start))
+(defn set-current-room [target]
+ (set! *current-room* target))
Please sign in to comment.
Something went wrong with that request. Please try again.