Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: remvee/memory
base: 3ea8f6ff02
...
head fork: remvee/memory
compare: 1fb2a6f95c
  • 2 commits
  • 3 files changed
  • 0 commit comments
  • 1 contributor
Showing with 32 additions and 11 deletions.
  1. +6 −1 public/index.html
  2. +8 −0 public/screen.css
  3. +18 −10 src/memory/core.cljs
View
7 public/index.html
@@ -6,7 +6,12 @@
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
</head>
<body>
- <div id="board"></div>
+ <div id="board" style="display:none">
+ </div>
+
+ <div id="cover" style="display:none">
+ <a href="#" id="play-link">Play!</a>
+ </div>
<script type="text/javascript" src="js/memory/goog/base.js"></script>
<script type="text/javascript" src="js/memory.js"></script>
View
8 public/screen.css
@@ -25,3 +25,11 @@ div.card div.face {
display: inline;
font-weight: bold;
}
+div#cover {
+ text-align: center;
+ margin: .5em;
+}
+div#cover a {
+ text-decoration: none;
+ font-weight: bold;
+}
View
28 src/memory/core.cljs
@@ -2,6 +2,7 @@
(:require [goog.dom :as gdom]
[goog.dom.classes :as gclasses]
[goog.events :as gevents]
+ [goog.style :as gstyle]
[clojure.browser.repl :as repl]))
(defn shuffle
@@ -45,10 +46,9 @@
"Render game over message."
[]
(doto (gdom/getElement "board")
- (gdom/removeChildren)
- (gdom/append (doto (gdom/createElement "h1")
- (gclasses/add "finished")
- (gdom/append "GAME OVER")))))
+ (gstyle/showElement false)
+ gdom/removeChildren)
+ (gstyle/showElement (gdom/getElement "cover") true))
(def worker (atom nil))
@@ -74,7 +74,7 @@
"Handle card click for a given pos."
[pos]
(when @worker
- (js/clearTimeout @worker)
+ (.clearTimeout js/window @worker)
(process-selection!))
(when (and (@cards pos)
(not (@current-selection pos))
@@ -82,7 +82,7 @@
(swap! current-selection conj pos)
(show-card! pos)
(when (= (count @current-selection) *number-of-group*)
- (reset! worker (js/setTimeout process-selection! 1000)))))
+ (reset! worker (.setTimeout js/window process-selection! 1000)))))
(defn create-card-element!
"Create dom element for a card and bind click listener."
@@ -98,7 +98,8 @@
(gdom/removeChildren board)
(dotimes [pos (count @cards)]
(let [elm (create-card-element! pos)]
- (gdom/append board elm)))))
+ (gdom/append board elm)))
+ (gstyle/showElement board true)))
(defn- floor
"Wrap js/Math.floor function."
@@ -119,12 +120,19 @@
border)
style (gdom/createElement "style")]
(gdom/append style (str "div.card{margin:" margin "px;width:" size "px;height:" size "px}"
- "div.card div.face{font-size:" (floor (* size 0.8)) "px}"))
+ "div#cover,div.card div.face{font-size:" (floor (* size 0.8)) "px}"))
(gdom/append document/body style)))
-(populate-cards!)
+(defn start-new-game!
+ "Start a new game of memory."
+ []
+ (gstyle/showElement (gdom/getElement "cover") false)
+ (populate-cards!)
+ (render-cards!))
+
(insert-style!)
-(render-cards!)
+(gstyle/showElement (gdom/getElement "cover") true)
+(gevents/listen (gdom/getElement "play-link") "click" start-new-game!)
(when (re-find #"\?debug" (. window/location -href))
(repl/connect "http://localhost:9000/repl"))

No commit comments for this range

Something went wrong with that request. Please try again.