Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Made drop-item and pick-up and helper functions more parallel to make

understanding them easier for my poor benighted mind.
  • Loading branch information...
commit df4b28f17c1f6da651dac401ec990531ee0ae9f2 1 parent 0721cd7
Bruce Durling authored
Showing with 14 additions and 15 deletions.
  1. +5 −7 src/clork.clj
  2. +9 −8 test/clork_test.clj
View
12 src/clork.clj
@@ -31,19 +31,17 @@
(defn has-item? [container item-name]
(contains? (:items container) item-name))
-;; fix me: the has-item? check should be moved to pick up so that we
-;; can have the gods give players items
-(defn add-to-items [world player-name item-name]
- (let [room (current-room world player-name)]
- (if (has-item? room item-name) (update-in world [:players player-name :items] conj item-name)
- world)))
+(defn add-to-player [world player-name item-name]
+ (update-in world [:players player-name :items] conj item-name))
(defn remove-from-room [world room-name item-name]
(update-in world [:rooms room-name :items] disj item-name))
(defn pick-up [world player-name item-name]
(let [room-name (get-in world [:players player-name :location])]
- (remove-from-room (add-to-items world player-name item-name) room-name item-name)))
+ (if (has-item? (current-room world player-name) item-name)
+ (remove-from-room (add-to-player world player-name item-name) room-name item-name)
+ world)))
(defn remove-from-player [world player-name item-name]
(update-in world [:players player-name :items] disj item-name))
View
17 test/clork_test.clj
@@ -42,10 +42,10 @@
(is (has-item? (current-room *test-world* :player1) :water))
(is (not (has-item? (current-room *test-world* :player1) :penguin))))
-(deftest add-to-items-test
- (is (= #{:water} (get-items (add-to-items *test-world* :player1 :water) :player1)))
- (is (= #{:sword} (get-items (add-to-items *test-world* :player1 :sword) :player1)))
- (is (= #{} (get-items (add-to-items *test-world* :player1 :penguin) :player1))))
+(deftest add-to-player-test
+ (is (= #{:water} (get-items (add-to-player *test-world* :player1 :water) :player1)))
+ (is (= #{:sword} (get-items (add-to-player *test-world* :player1 :sword) :player1)))
+ (is (= #{:penguin} (get-items (add-to-player *test-world* :player1 :penguin) :player1))))
(deftest remove-from-room-test
(is (= #{:water :sword} (get-in (remove-from-room *test-world* :hall :penguin) [:rooms :hall :items])))
@@ -59,11 +59,12 @@
(is (= #{:water} (get-in (pick-up *test-world* :player1 :sword) [:rooms :hall :items])))
(is (= #{:sword} (get-in (pick-up *test-world* :player1 :water) [:rooms :hall :items]))))
-(deftest remove-from-items-test
- (is (= #{} (get-items (remove-from-items *test-world* :player2 :cloth) :player2))))
+(deftest remove-from-player-test
+ (is (= #{} (get-items (remove-from-player *test-world* :player2 :cloth) :player2))))
-(deftest add-item-to-room-test
- (is (= #{:cloth} (get-in (add-item-to-room *test-world* :kitchen :cloth) [:rooms :kitchen :items]))))
+(deftest add-to-room-test
+ (is (= #{:cloth} (get-in (add-to-room *test-world* :kitchen :cloth) [:rooms :kitchen :items])))
+ (is (= #{:penguin} (get-in (add-to-room *test-world* :kitchen :penguin) [:rooms :kitchen :items]))))
(deftest drop-item-test
(is (= #{} (get-items (drop-item *test-world* :player2 :cloth) :player2)))
Please sign in to comment.
Something went wrong with that request. Please try again.