Created
May 14, 2015 19:01
-
-
Save pjazdzewski1990/382cd3aaa7d3360f21cc to your computer and use it in GitHub Desktop.
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
(defn card [card-state] | |
(letfn [(handle-card-click! [event] | |
; pair of cards was revealed, now let's go for another pair step | |
(if (= (revealed-cards-count) 2) | |
(hide-nonmatch!)) | |
;reveal next card in step | |
(reveal-card! card-state) | |
;if 2 of cards are revealed, we have to check parity | |
(if (and (= (revealed-cards-count) 2) | |
(= (:last-symbol @state) | |
(:symbol @card-state))) | |
(mark-match! (:symbol @card-state))) | |
;let's remember last symbol to make comparison in subsequent steps | |
(swap! state assoc :last-symbol (:symbol @card-state)))] | |
[:div.card | |
{:onClick handle-card-click! | |
:key (.random js/Math) | |
:class (if (@card-state :matched) | |
"card-matched" | |
"card")} | |
[:span.card-value | |
{:class (if (@card-state :visible) | |
"card-value" | |
"card-value-hidden")} | |
(:symbol @card-state)]])) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment