This repository was archived by the owner on Oct 21, 2021. It is now read-only.
  
  
  
  
    
    
    
      
    
  
  
    
File tree Expand file tree Collapse file tree 5 files changed +21
-18
lines changed Expand file tree Collapse file tree 5 files changed +21
-18
lines changed Original file line number Diff line number Diff line change 1111
1212; ; Command functions
1313
14- (defn  look  " Get a description of the surrounding environs and its contents." 
14+ (defn  look 
15+   " Get a description of the surrounding environs and its contents." 
1516  []
1617  (str  (:desc  @*current-room*)
1718       " \n Exits: "   (keys  @(:exits  @*current-room*)) " \n " 
2324  [direction]
2425  (dosync 
2526   (let  [target-name ((:exits  @*current-room*) (keyword  direction))
26-          target (rooms  target-name)]
27+          target (@ rooms  target-name)]
2728     (if  target
2829       (do 
2930         (move-between-refs  *player-name*
6667  [item]
6768  (if  (@*inventory*  :detector )
6869    (if-let  [room (first  (filter  #((:items  %) (keyword  item))
69-                                  (vals  rooms)))]
70+                                  (vals  @ rooms)))]
7071      (str  item "  is in "   (:name  room))
7172      (str  item "  is not in any room."  ))
7273    " You need to be carrying the detector for that."  ))
Original file line number Diff line number Diff line change 11(ns  mire.rooms )
22
3- (def  rooms  {} )
3+ (def  rooms  ( ref  {}) )
44
55(defn  load-room  [rooms file]
66  (let  [room (read-string  (slurp  (.getAbsolutePath  file)))]
1616  " Given a dir, return a map with an entry corresponding to each file
1717  in it. Files should be maps containing room data."  
1818  [rooms dir]
19-   (reduce  load-room rooms (.listFiles  (java.io.File.  dir))))
19+   (dosync 
20+    (reduce  load-room rooms
21+            (.listFiles  (java.io.File.  dir)))))
2022
2123(defn  add-rooms 
2224  " Look through all the files in a dir for files describing rooms and add
2325  them to the mire.rooms/rooms map."  
2426  [dir]
25-   (alter-var-root   #' rooms load-rooms dir))
27+   (alter!    rooms load-rooms dir))
2628
2729(defn  room-contains? 
2830  [room thing]
Original file line number Diff line number Diff line change 2929    ; ; the one above so *in* and *out* will be bound to the socket
3030    (print  " \n What is your name? "  ) (flush )
3131    (binding  [*player-name* nil 
32-               *current-room* (ref  (rooms  :start ))
32+               *current-room* (ref  (@ rooms  :start ))
3333              *inventory* (ref  #{})]
3434      (dosync 
3535       (set!  *player-name* (get-unique-player-name  (read-line )))
Original file line number Diff line number Diff line change 1010
1111(defmacro  def-command-test  [name & body]
1212  `(deftest  ~name
13-      (binding  [*current-room* (ref  (:start  rooms))
13+      (binding  [*current-room* (ref  (:start  @ rooms))
1414               *inventory* (ref  #{})
1515               *player-name* " Tester"  ]
1616       ~@body)))
2121    (is  (=  " You can't do that!" 
2222           (execute  " discard a can of beans into the fridge"  ))))
2323  (is  (re-find  #"closet"  (execute  " north"  )))
24-   (is  (=  @*current-room* (:closet  rooms))))
24+   (is  (=  @*current-room* (:closet  @ rooms))))
2525
2626(def-command-test  test-move 
2727  (is  (re-find  #"hallway"  (execute  " south"  )))
2828  (is  (re-find  #"promenade"  (move  " east"  )))
2929  (is  (re-find  #"can't go that way"  (move  " south"  ))))
3030
3131(def-command-test  test-look 
32-   (binding  [*current-room* (ref  (:closet  rooms))]
32+   (binding  [*current-room* (ref  (:closet  @ rooms))]
3333    (doseq  [look-for [#"closet"  #"keys"  #"south" ]]
3434    (is  (re-find  look-for (look ))))))
3535
3939    (is  (re-find  #"keys"  (inventory )))))
4040
4141(def-command-test  test-grab 
42-   (binding  [*current-room* (ref  (:closet  rooms))]
42+   (binding  [*current-room* (ref  (:closet  @ rooms))]
4343    (is  (not  (=  " There isn't any keys here" 
4444                (grab  " keys"  ))))
4545    (is  (carrying?  :keys ))
Original file line number Diff line number Diff line change 33  (:use  [clojure.test]))
44
55(defn  room-fixture  [f]
6-   (binding  [rooms (load-rooms  {} " resources/rooms/"  )]
6+   (binding  [rooms (atom  ( load-rooms  {} " resources/rooms/" ) )]
77    (f )))
88
99(use-fixtures  :each  room-fixture)
1010
1111(deftest  test-set-rooms 
1212  (doseq  [name [:start  :closet  :hallway  :promenade ]]
13-     (is  (contains?  rooms name)))
14-   (is  (re-find  #"promenade"  (:desc  (:promenade  rooms))))
15-   (is  (=  :hallway  (:west  @(:exits  (:promenade  rooms)))))
16-   (is  (some  #{:bunny } @(:items  (:promenade  rooms))))
17-   (is  (empty?  @(:inhabitants  (:promenade  rooms)))))
13+     (is  (contains?  @ rooms name)))
14+   (is  (re-find  #"promenade"  (:desc  (:promenade  @ rooms))))
15+   (is  (=  :hallway  (:west  @(:exits  (:promenade  @ rooms)))))
16+   (is  (some  #{:bunny } @(:items  (:promenade  @ rooms))))
17+   (is  (empty?  @(:inhabitants  (:promenade  @ rooms)))))
1818
1919(deftest  test-room-contains? 
20-   (let  [closet (:closet  rooms)]
20+   (let  [closet (:closet  @ rooms)]
2121    (is  (not  (empty?  (filter  #(=  % :keys ) @(:items  closet)))))
2222    (is  (room-contains?  closet " keys"  ))
2323    (is  (not  (room-contains?  closet " monkey"  )))))
    
 
   
 
     
   
   
          
     
  
    
     
 
    
      
     
 
     
    You can’t perform that action at this time.
  
 
    
  
     
    
      
        
     
 
       
      
     
   
 
    
    
  
 
  
 
     
    
0 commit comments