Browse Source

Use assoc-in when the updated value is known beforehand

master
parent
commit
6dc2c02ad4
2 changed files with 3 additions and 6 deletions
  1. +1
    -1
      src/ttfe/board.cljs
  2. +2
    -5
      src/ttfe/core.cljs

+ 1
- 1
src/ttfe/board.cljs View File

@@ -16,7 +16,7 @@
(defn add-tile [board]
(let [[rand-row rand-col] (rand-nth (-find-empty-tiles board))
new-tile-value (rand-nth '(2 2 2 2 2 2 2 2 2 4))]
(update-in board [rand-row rand-col] (fn [_] new-tile-value))))
(assoc-in board [rand-row rand-col] new-tile-value)))

(defn new-board []
(add-tile [[nil nil nil nil]


+ 2
- 5
src/ttfe/core.cljs View File

@@ -67,9 +67,7 @@
(let [board (:board state)
moved-board (move-fn board)]
(if (not= board moved-board)
(update-in state [:board]
(fn [b]
(add-tile moved-board)))
(assoc-in state [:board] (add-tile moved-board))
state))))
(when (and (contains? (set (flatten (:board @app-state))) 2048)
(not (:already-won @app-state)))
@@ -90,8 +88,7 @@
(.on input-manager
"keepPlaying"
(fn []
(swap! app-state (fn [state]
(update-in state [:paused] (fn [_] false))))
(swap! app-state (fn [state] (assoc-in state [:paused] false)))
(let [msg-cont (. js/document (querySelector ".game-message"))]
(.remove (.-classList msg-cont) "game-won")
(.remove (.-classList msg-cont) "game-over"))))


Loading…
Cancel
Save