Permalink
Browse files

This subproject now has its own repository:

  • Loading branch information...
1 parent 5cf0679 commit 5fbeceb8e6129d551323240ba8b7e7e595e34317 @apauley committed May 27, 2010
@@ -1,9 +0,0 @@
-#!/usr/bin/env clj
-
-(defn fac [n]
- "Returns the factorial of n"
- (if (= n 1)
- 1
- (* n (fac (- n 1)))))
-
-(println (fac 3))
@@ -1 +0,0 @@
-mire.el
@@ -1 +0,0 @@
-My re-implementation of mire.
@@ -1,3 +0,0 @@
-{:desc "You are in a cramped closet. Coats abound. You feel a slight breeze."
- :exits {:south :start}
- :items #{:keys}}
@@ -1,4 +0,0 @@
-{:desc "You are in a long, low-lit hallway that turns to the east."
- :items #{:detector}
- :exits {:north :start,
- :east :promenade}}
@@ -1,3 +0,0 @@
-{:desc "The promenade stretches out before you."
- :exits {:west :hallway}
- :items #{:bunny :turtle}}
@@ -1,3 +0,0 @@
-{:desc "You are in an old, dusty room."
- :exits {:north :closet,
- :south :hallway}}
@@ -1,36 +0,0 @@
-(ns mire
- (:use [mire commands rooms player util])
- (:use [clojure.contrib server-socket duck-streams]))
-
-(def port 3333)
-
-(defn- print-prompt []
- (println)
- (print-flush "> "))
-
-(defn- mire-handle-client [in out]
- "Private function to handle client requests"
-
- ; Re-assign stdin and stdout
- (binding [*in* (reader in)
- *out* (writer out)]
-
- (print-flush "\nWhat is your name? ")
- (binding [*player-name* (read-line)
- *current-room* (ref (rooms :start))
- *inventory* (ref #{})]
- (move-player-to @(current-room))
- (println (look))
- (print-prompt)
- (loop [input (read-line)]
- (println (execute input))
- (print-prompt)
- (recur (read-line))))))
-
-(set-rooms "../data/rooms")
-(def server (create-server port mire-handle-client))
-
-(comment
- (close-server server)
- (add-classpath "file:///Users/andreas/Projekte/Persoonlik/RandomHacks/PeepCode/Clojure/mire/src/")
-)
@@ -1,75 +0,0 @@
-(ns mire.commands
- (:use [mire rooms player util])
- (:use [clojure.contrib str-utils]))
-
-(defn look []
- "Get a description of the current room"
- (str "\n"
- (:desc @(current-room))
- "\nInhabitants: " @(current-inhabitants)
- "\nItems: " @(current-items)
- "\nExits: " (keys (:exits @(current-room)))))
-
-(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
- (do (move-player-to target)
- (look))
- "No way.")))
-
-(defn grab [thing]
- "Pick up something in the room"
- (if (current-room-contains? thing)
- (dosync
- (move-between-refs (keyword thing)
- (:items @(current-room))
- *inventory*)
- (str "You picked up the " thing "."))
- (str "There isn't any " thing " here.")))
-
-(defn discard [thing]
- "Drop something you carry"
- (if (carrying? thing)
- (dosync
- (move-between-refs (keyword thing)
- *inventory*
- (:items @(current-room)))
- (str "You dropped the " thing "."))
- (str "You are not carrying any " thing ".")))
-
-(defn inventory []
- "See what you are carrying"
- (str-join "\n " (conj @*inventory* "You are carrying:")))
-
-(defn detect [item]
- "If you have the detector, you can see which room an item is in."
- (if (@*inventory* :detector)
- (if-let [room (first (filter #((:items %) (keyword item))
- (vals rooms)))]
- (str item " is in " (:name room))
- (str item " is not in any room."))
- "You need to be carrying the detector for that."))
-
-(def commands
- {:move move,
- :north #(move :north),
- :east #(move :east),
- :south #(move :south),
- :west #(move :west),
- :look look,
- :grab grab,
- :discard discard,
- :inventory inventory,
- :detect detect,
- :wtf #(str "You need help.")})
-
-(defn execute
- "Execute a command passed from the client"
- [input]
- (let [input-words (re-split #"\s+" input)
- command (keyword (first input-words))
- args (rest input-words)]
- (apply (command commands (:wtf commands)) args)))
@@ -1,8 +0,0 @@
-(ns mire.player
- (:use clojure.contrib.seq-utils))
-
-(def *player-name*)
-(def *inventory*)
-
-(defn carrying? [thing]
- (includes? @*inventory* (keyword thing)))
@@ -1,45 +0,0 @@
-(ns mire.rooms
- (:use [mire player util]))
-
-(declare rooms)
-
-(defn load-room [rooms file]
- (let [room (read-string (slurp (.getAbsolutePath file)))]
- (conj rooms {(keyword (.getName file))
- {:desc (:desc room)
- :exits (:exits room)
- :items (ref (or (:items room) #{}))
- :inhabitants (ref #{})}})))
-
-(defn load-rooms [dir]
- (reduce load-room {} (.listFiles (java.io.File. dir))))
-
-(defn set-rooms [dir]
- (def rooms (load-rooms dir)))
-
-(def *current-room*)
-
-(defn current-room []
- "Returns the current room"
- *current-room*)
-
-(defn current-inhabitants []
- "Returns the inhabitants in the current room"
- (:inhabitants @(current-room)))
-
-(defn current-items []
- "Returns the items available in the current room"
- (:items @(current-room)))
-
-(defn room-contains? [room thing]
- (@(:items room) (keyword thing)))
-
-(defn current-room-contains? [thing]
- (room-contains? @(current-room) thing))
-
-(defn move-player-to [target]
- (dosync
- (move-between-refs *player-name*
- (:inhabitants @(current-room))
- (:inhabitants target))
- (ref-set *current-room* target)))
@@ -1,11 +0,0 @@
-(ns mire.util)
-
-(defn print-flush [text]
- (print text)
- (flush))
-
-(defn move-between-refs
- "Move one instance of obj between from and to. Must be called in a transaction."
- [obj from to]
- (alter from disj obj)
- (alter to conj obj))
View
@@ -1 +0,0 @@
-My attempts at implementing the tutorial examples.
View
@@ -0,0 +1,2 @@
+This subproject now has its own repository:
+ * http://github.com/apauley/mire-clojure-screencast

0 comments on commit 5fbeceb

Please sign in to comment.