Browse Source

Implement main update function

Thomas Dy 8 years ago
parent
commit
fde73b05fb
2 changed files with 28 additions and 2 deletions
  1. 21 2
      src/bombnet/core.clj
  2. 7 0
      src/bombnet/game.clj

+ 21 - 2
src/bombnet/core.clj

@@ -1,7 +1,26 @@
 (ns bombnet.core
-  (:gen-class))
+  (:gen-class)
+  (:require [bombnet.game :refer :all]))
+
+(defn print-state [state]
+  (let [{:keys [board players bombs explosion]} state
+        coords (fn [{[x y] :pos}] [y x])
+        coords2 (fn [[x y]] [y x])
+        draw-players (fn [board] (reduce #(assoc-in % (coords %2) "@") board players))
+        draw-bombs (fn [board] (reduce #(assoc-in % (coords %2) "Q") board bombs))
+        draw-explosion (fn [board] (reduce #(assoc-in % (coords2 %2) "X") board explosion))
+        board2 (-> board
+                   draw-explosion
+                   draw-bombs
+                   draw-players)
+        string (reduce #(str % "\n" (reduce str %2)) "" board2)]
+    (println string)))
 
 (defn -main
   "I don't do a whole lot ... yet."
   [& args]
-  (println "Hello, World!"))
+  (-> (new-game [{:id 1 :name "Thomas"}])
+      (queue-action 1 {:type "bomb" :timer 1})
+      update-state
+      update-state
+      print-state))

+ 7 - 0
src/bombnet/game.clj

@@ -192,3 +192,10 @@
                mapv-if
                #(= id (:id %))
                #(assoc % :action action))))
+
+(defn update-state [state]
+  (-> state
+      perform-bomb-tick
+      perform-bomb-placement
+      perform-movement
+      explode-bombs))