Browse Source

Reimplement new-game

We also remove new-player as new-game obsoletes it
Thomas Dy 8 years ago
parent
commit
8bb0d20ec8
2 changed files with 10 additions and 7 deletions
  1. 9 6
      src/bombnet/game.clj
  2. 1 1
      test/bombnet/game_test.clj

+ 9 - 6
src/bombnet/game.clj

@@ -27,8 +27,6 @@
 (defn get-cell [board entity]
   (let [[x y] (get-pos entity)] (get-in board [y x])))
 
-(defn new-player [id] {:id id :pos [1 1] :color "red"})
-
 (defn move-player
   ([p x y] (assoc p :pos [x y]))
   ([p dir]
@@ -39,10 +37,15 @@
        "left" (move-player p (- x 1) y)
        "right" (move-player p (+ x 1) y)))))
 
-(defn new-game []
-  {:board (new-board 21 17)
-   :players []
-   :bombs []})
+(defn new-game [players]
+  (let [w 21 h 17
+        colors ["red" "blue" "green" "yellow"]
+        positions [[1 1] [1 (- h 2)] [(- w 2) 1] [(- w 2) (- h 2)]]
+        positioned-players (mapv #(assoc % :pos %2 :color %3) players positions colors)]
+    {:board (new-board 21 17)
+     :players positioned-players
+     :bombs []
+     :explosion #{}}))
 
 (defn with-action [typ]
   (fn [p] (= typ (get-in p [:action :type]))))

+ 1 - 1
test/bombnet/game_test.clj

@@ -16,7 +16,7 @@
 
 (deftest player-test
   (testing "Player can move"
-    (let [p (new-player "p1")
+    (let [p {:pos [1 1]}
           check (fn [p pos]
                   (is (= (:pos p) pos)))]
       (check (move-player p 3 3) [3 3])