From 551f17484232e778be90b3e3800a629a8adb14ac Mon Sep 17 00:00:00 2001 From: Pradnyesh Sawant Date: Thu, 30 Jul 2015 17:00:33 +0530 Subject: [PATCH] handle-card-click! should be triggered only for non-matched cards --- src/cljs/react_cljs_blogpost/core.cljs | 33 ++++++++++++++------------ 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/src/cljs/react_cljs_blogpost/core.cljs b/src/cljs/react_cljs_blogpost/core.cljs index a619117..2f28633 100644 --- a/src/cljs/react_cljs_blogpost/core.cljs +++ b/src/cljs/react_cljs_blogpost/core.cljs @@ -42,21 +42,24 @@ (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)))] + (when-not (@card-state :matched) + ;; pair of cards was revealed, now let's go for another pair step + (when (= (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 + (when (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)) + (when (= (matched-cards-count) board-size) + (swap! state assoc :started false))))] [:div.card {:onClick handle-card-click!