Skip to content

Instantly share code, notes, and snippets.

@pjazdzewski1990
Created May 14, 2015 19:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pjazdzewski1990/382cd3aaa7d3360f21cc to your computer and use it in GitHub Desktop.
Save pjazdzewski1990/382cd3aaa7d3360f21cc to your computer and use it in GitHub Desktop.
(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