Skip to content
Browse files

First test for items

  • Loading branch information...
1 parent 49de928 commit 3381cb4e5366ec574e24b4fb4b76dc622e306c36 @tcrayford tcrayford committed Mar 30, 2010
Showing with 38 additions and 16 deletions.
  1. +27 −16 src/clork.clj
  2. +11 −0 src/world.clj
View
43 src/clork.clj
@@ -1,28 +1,31 @@
-(ns clork)
-
+(ns clork
+ (:use world)
+ (:use clojure.contrib.seq-utils))
;; represent a room
;; represent a set of rooms
;; represent monsters
;; (declare hall kitchen bag-of-gold sword)
-
-
;; (def cell {:exits [hall kitchen]
;; :items [bag-of-gold sword]})
;; (def hall {:exits [cell]
;; :items []})
-(def rooms {:hall {:description "A large vaulted hall"
- :exits {:n :kitchen
- :w :lounge}}
- :kitchen {:description "A kitchen with a roaring fire"
- :exits {:s :hall}}
- :lounge {:description "A lounge with a red chez longue"
- :exits {:e :hall}}})
+(def items
+ [ {:location :stone
+ :name "Sword"}
+ {:location :hall
+ :name "Clock"}])
-(defn look [rooms room]
- (:description (room rooms)))
+(defn look
+ ([] (look rooms))
+ ([rooms] (look rooms (:location @the-player)))
+ ([rooms room]
+ (:description (room rooms))))
+
+(defn items-for [location]
+ (map :name (filter #(= (:location %) location) items)))
(defn move [rooms from direction]
(direction (:exits (rooms from))))
@@ -31,10 +34,18 @@
(defn move-player [a-player rooms direction]
(let [new-room (move rooms (:location a-player) direction)]
- (if new-room (struct player new-room) a-player)))
+ (if new-room (struct player new-room) a-player) ))
+
(def the-player (atom (struct player :hall)))
-(defn west []
- (swap! the-player #(move-player % rooms :w))
+(defn move-and-print [direction]
+ (swap! the-player #(move-player % rooms direction))
(println (look rooms (:location @the-player))))
+
+
+ (map #(defn %1 [] (move-and-print %2))
+ ['north 'south 'east 'west]
+ [:n :s :e :w])
+
+
View
11 src/world.clj
@@ -0,0 +1,11 @@
+(ns world)
+
+(def rooms {:hall {:description "A large vaulted hall"
+ :exits {:n :kitchen
+ :w :lounge}}
+ :kitchen {:description "A kitchen with a roaring fire"
+ :exits {:s :hall}}
+ :lounge {:description "A lounge with a red chez longue"
+ :exits {:e :hall}}})
+
+{:location :hall}

0 comments on commit 3381cb4

Please sign in to comment.
Something went wrong with that request. Please try again.