Skip to content

Commit

Permalink
Mire: Multple players don't interfere with each other's rooms anymore
Browse files Browse the repository at this point in the history
  • Loading branch information
Andreas Pauley committed Dec 19, 2009
1 parent 68d55ae commit f541b80
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 16 deletions.
8 changes: 5 additions & 3 deletions PeepCode/Clojure/mire/src/mire.clj
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
(ns mire
(:use [mire commands])
(:use [mire commands rooms])
(:use [clojure.contrib server-socket duck-streams]))

(def port 3333)
Expand All @@ -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)]
Expand Down
20 changes: 10 additions & 10 deletions PeepCode/Clojure/mire/src/mire/commands.clj
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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.")})

Expand Down
6 changes: 3 additions & 3 deletions PeepCode/Clojure/mire/src/mire/rooms.clj
Original file line number Diff line number Diff line change
Expand Up @@ -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))

0 comments on commit f541b80

Please sign in to comment.