Skip to content

Commit

Permalink
code formatting using cursive
Browse files Browse the repository at this point in the history
  • Loading branch information
lprakashv committed Feb 17, 2021
1 parent 57c46a9 commit c56d44a
Show file tree
Hide file tree
Showing 6 changed files with 181 additions and 181 deletions.
10 changes: 5 additions & 5 deletions src/cljs/reframe_codenames/core.cljs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
(ns reframe-codenames.core
(:require
[reagent.dom :as rdom]
[re-frame.core :as re-frame]
[reframe-codenames.events :as events]
[reframe-codenames.views :as views]
[reframe-codenames.config :as config]))
[reagent.dom :as rdom]
[re-frame.core :as re-frame]
[reframe-codenames.events :as events]
[reframe-codenames.views :as views]
[reframe-codenames.config :as config]))


(defn dev-setup []
Expand Down
32 changes: 16 additions & 16 deletions src/cljs/reframe_codenames/db.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -408,28 +408,28 @@
(take n)))

(defn- take-colored-words []
(let [w (take-rand-n words 25 [])
red (take-rand-n w 9 [])
blue (take-rand-n w 8 red)
grey (take-rand-n w 7 (concat red blue))
(let [w (take-rand-n words 25 [])
red (take-rand-n w 9 [])
blue (take-rand-n w 8 red)
grey (take-rand-n w 7 (concat red blue))
black (take-rand-n w 1 (concat red blue grey))]
{:all w :red red :blue blue :grey grey :black black}))

(defn- game-tiles []
(let [categorized-words (take-colored-words)
all-words (:all categorized-words)
red-words-set (set (:red categorized-words))
blue-words-set (set (:blue categorized-words))
black-words-set (set (:black categorized-words))
index (atom -1)]
all-words (:all categorized-words)
red-words-set (set (:red categorized-words))
blue-words-set (set (:blue categorized-words))
black-words-set (set (:black categorized-words))
index (atom -1)]
(map
(fn [word]
(let [color (cond (contains? red-words-set word) :red
(contains? blue-words-set word) :blue
(contains? black-words-set word) :black
:else :grey)]
{:color color :word word :index (swap! index inc) :open? false}))
all-words)))
(fn [word]
(let [color (cond (contains? red-words-set word) :red
(contains? blue-words-set word) :blue
(contains? black-words-set word) :black
:else :grey)]
{:color color :word word :index (swap! index inc) :open? false}))
all-words)))

(defn default-db []
{:name "re-frame"
Expand Down
122 changes: 61 additions & 61 deletions src/cljs/reframe_codenames/events.cljs
Original file line number Diff line number Diff line change
@@ -1,77 +1,77 @@
(ns reframe-codenames.events
(:require
[re-frame.core :as re-frame]
[reframe-codenames.db :as db]
[reframe-codenames.utils :as utils]
[day8.re-frame.tracing :refer [fn-traced]]))
[re-frame.core :as re-frame]
[reframe-codenames.db :as db]
[reframe-codenames.utils :as utils]
[day8.re-frame.tracing :refer [fn-traced]]))

(re-frame/reg-event-db
::initialize-db
(fn-traced [_ _]
(db/default-db)))
::initialize-db
(fn-traced [_ _]
(db/default-db)))

(re-frame/reg-event-db
::toggle-turn
(fn-traced [d _]
(let [new-turn (utils/opp-color (:turn d))]
(merge d
{:turn new-turn
:message (utils/get-messsage-for-type :turn-message new-turn)
:turn-over? false
:hint ""
:limit 0}))))
::toggle-turn
(fn-traced [d _]
(let [new-turn (utils/opp-color (:turn d))]
(merge d
{:turn new-turn
:message (utils/get-message-for-type :turn-message new-turn)
:turn-over? false
:hint ""
:limit 0}))))

(re-frame/reg-event-db
::toggle-spy-master
(fn-traced [d _]
(let [{:keys [spy-master? hint limit turn]} d
valid-hint? (and
(> limit 0)
(not (clojure.string/blank? hint)))]
(cond
(or (not spy-master?) valid-hint?) (-> d
(assoc :spy-master? (not spy-master?))
(assoc :message (utils/get-messsage-for-type :turn-message turn)))
:else (-> d
(assoc :message (utils/get-messsage-for-type :spy-master-exit-error)))))))
::toggle-spy-master
(fn-traced [d _]
(let [{:keys [spy-master? hint limit turn]} d
valid-hint? (and
(> limit 0)
(not (clojure.string/blank? hint)))]
(cond
(or (not spy-master?) valid-hint?) (-> d
(assoc :spy-master? (not spy-master?))
(assoc :message (utils/get-message-for-type :turn-message turn)))
:else (-> d
(assoc :message (utils/get-message-for-type :spy-master-exit-error)))))))

(re-frame/reg-event-db
::open-tile
(fn-traced [d [_ i j]]
(let [index (+ (* i 5) j)
turn (:turn d)
{{{tile-color :color} index} :board} d]
(as-> d v
(assoc-in v [:board index :open?] true)
(update v :limit dec)
(assoc v :turn-over?
(or
(= (utils/opp-color turn) tile-color)
(zero? (:limit v))))
(if (:turn-over? v)
(merge v
{:message (utils/get-messsage-for-type :open-tile-turn-over)
:hint ""
:limit 0})
v)))))
::open-tile
(fn-traced [d [_ i j]]
(let [index (+ (* i 5) j)
turn (:turn d)
{{{tile-color :color} index} :board} d]
(as-> d v
(assoc-in v [:board index :open?] true)
(update v :limit dec)
(assoc v :turn-over?
(or
(= (utils/opp-color turn) tile-color)
(zero? (:limit v))))
(if (:turn-over? v)
(merge v
{:message (utils/get-message-for-type :open-tile-turn-over)
:hint ""
:limit 0})
v)))))

(re-frame/reg-event-db
::set-hint
(fn-traced [d [_ text]]
(-> d
(assoc :hint text))))
::set-hint
(fn-traced [d [_ text]]
(-> d
(assoc :hint text))))

(re-frame/reg-event-db
::set-limit
(fn-traced [d [_ limit]]
(-> d
(assoc :limit (int limit)))))
::set-limit
(fn-traced [d [_ limit]]
(-> d
(assoc :limit (int limit)))))

(re-frame/reg-event-db
::announce-winner
(fn-traced [d [_ winner]]
(-> d
(merge
{:game-over? true
:spy-master? true
:message (utils/get-messsage-for-type :winner-announcement winner)}))))
::announce-winner
(fn-traced [d [_ winner]]
(-> d
(merge
{:game-over? true
:spy-master? true
:message (utils/get-message-for-type :winner-announcement winner)}))))
56 changes: 28 additions & 28 deletions src/cljs/reframe_codenames/subs.cljs
Original file line number Diff line number Diff line change
@@ -1,50 +1,50 @@
(ns reframe-codenames.subs
(:require
[re-frame.core :as re-frame]))
[re-frame.core :as re-frame]))

; TODO - improve all the subs taking other subscribe as signal functions

(re-frame/reg-sub
::name
(fn [db]
(:name db)))
::name
(fn [db]
(:name db)))

(re-frame/reg-sub
::board
(fn [db]
(:board db)))
::board
(fn [db]
(:board db)))

(re-frame/reg-sub
::spy-master?
(fn [db]
(:spy-master? db)))
::spy-master?
(fn [db]
(:spy-master? db)))

(re-frame/reg-sub
::turn
(fn [db]
(:turn db)))
::turn
(fn [db]
(:turn db)))

(re-frame/reg-sub
::turn-over?
(fn [db]
(:turn-over? db)))
::turn-over?
(fn [db]
(:turn-over? db)))

(re-frame/reg-sub
::hint
(fn [db]
(:hint db)))
::hint
(fn [db]
(:hint db)))

(re-frame/reg-sub
::limit
(fn [db]
(:limit db)))
::limit
(fn [db]
(:limit db)))

(re-frame/reg-sub
::message
(fn [db]
(:message db)))
::message
(fn [db]
(:message db)))

(re-frame/reg-sub
::game-over?
(fn [db]
(:game-over? db)))
::game-over?
(fn [db]
(:game-over? db)))
8 changes: 4 additions & 4 deletions src/cljs/reframe_codenames/utils.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
(defn capitalize [s]
(clojure.string/capitalize (name s)))

(defn get-messsage-for-type
(defn get-message-for-type
([tpe]
(case tpe
:open-tile-turn-over {:status :info
Expand All @@ -30,7 +30,7 @@
(defn left-tiles-count-by-color [board-tiles color]
(->> board-tiles
(filter
#(and
(not (:open? %))
(= color (:color %))))
#(and
(not (:open? %))
(= color (:color %))))
(count)))
Loading

0 comments on commit c56d44a

Please sign in to comment.