-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: setup the board to start capturing extra metadata at tile level
Each tile in the board should hold metadata about it's state. This is so that we can use it for doing animations or showing something extra in the ui based on the state of the tile
- Loading branch information
Showing
5 changed files
with
168 additions
and
173 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,25 @@ | ||
(ns cljs-2048.game-events | ||
(:require | ||
[day8.re-frame.tracing :refer-macros [fn-traced]] | ||
[re-frame.core :as re-frame] | ||
[cljs-2048.local-storage :as ls])) | ||
|
||
(re-frame/reg-event-db | ||
::add-score | ||
(fn-traced | ||
(defn add-score | ||
[db [_ new-score]] | ||
(let [score (+ new-score (:score db)) | ||
high-score (max score (:high-score db))] | ||
(ls/set-high-score! high-score) ;; set high-score in local-storage | ||
(assoc db | ||
:score score | ||
:high-score high-score)))) | ||
:high-score high-score))) | ||
|
||
(defn gameover | ||
[db [_]] | ||
(assoc db :gameover true)) | ||
|
||
(re-frame/reg-event-db | ||
::add-score | ||
add-score) | ||
|
||
(re-frame/reg-event-db | ||
::gameover | ||
(fn-traced | ||
[db [_]] | ||
(assoc db :gameover true))) | ||
gameover) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.