Browse Source

Implement bomb tick logic

Thomas Dy 8 years ago
parent
commit
a6ebb20862
2 changed files with 12 additions and 1 deletions
  1. 5 0
      src/bombnet/game.clj
  2. 7 1
      test/bombnet/game_test.clj

+ 5 - 0
src/bombnet/game.clj

@@ -180,3 +180,8 @@
              (assoc :bombs new-bombs))
          (union prev-explosion explosion)))
      (assoc state :explosion prev-explosion))))
+
+(defn perform-bomb-tick [state]
+  (let [{bombs :bombs} state
+        new-bombs (mapv #(update-in % [:counter] dec) bombs)]
+    (assoc state :bombs new-bombs)))

+ 7 - 1
test/bombnet/game_test.clj

@@ -147,4 +147,10 @@
       (is (not (get-in new-state [:players 0 :dead?])))
       (is (= [scared-bomb] (:bombs new-state)))
       (is (= #{[1 2] [2 1] [2 3] [3 4] [4 5]}
-             (:explosion new-state))))))
+             (:explosion new-state)))))
+  (testing "Ticking bombs"
+    (let [state {:board (new-board 7 7)
+                 :players []
+                 :bombs [{:pos [1 1] :counter 2}]}
+          new-state (perform-bomb-tick state)]
+      (is (= 1 (get-in new-state [:bombs 0 :counter]))))))