aboutsummaryrefslogtreecommitdiffstats
path: root/src/tic_tac_toe/core.cljs
diff options
context:
space:
mode:
Diffstat (limited to 'src/tic_tac_toe/core.cljs')
-rw-r--r--src/tic_tac_toe/core.cljs34
1 files changed, 20 insertions, 14 deletions
diff --git a/src/tic_tac_toe/core.cljs b/src/tic_tac_toe/core.cljs
index 89d4ba8..44c7feb 100644
--- a/src/tic_tac_toe/core.cljs
+++ b/src/tic_tac_toe/core.cljs
@@ -6,35 +6,41 @@
(atom {:board (logic/new-board logic/board-size)}))
(defn naught [i j]
- [:circle {:id "naught"
- :r 0.45
- :cx (+ 0.5 i)
- :cy (+ 0.5 j)}])
+ [:g
+ [:rect {:id "back"
+ :x (+ 0.05 i)
+ :y (+ 0.05 j)}]
+ [:circle {:id "naught"
+ :cx (+ 0.5 i)
+ :cy (+ 0.5 j)}]])
(defn cross [i j]
- [:g {:stroke "black"
- :stroke-width 0.08
- :stroke-linecap "round"}
- [:line {:x1 i :y1 j :x2 (+ i 1) :y2 (+ j 1)}]
- [:line {:x1 i :y1 (+ j 1) :x2 (+ i 1) :y2 j}]])
+ [:g
+ [:rect {:id "back"
+ :x (+ 0.05 i)
+ :y (+ 0.05 j)}]
+ [:g {:id "cross"}
+ (let [offset 0.25]
+ [:line {:x1 (+ i offset) :y1 (+ j offset) :x2 (+ i (- 1 offset)) :y2 (+ j (- 1 offset))}])
+ (let [offset 0.25]
+ [:line {:x1 (+ i offset) :y1 (+ j (- 1 offset)) :x2 (+ i (- 1 offset)) :y2 (+ j offset)}])]])
(defn blank [i j]
[:rect {:id "blank"
- :width 0.9
- :height 0.9
:x (+ 0.05 i)
- :y (+ 0.05 j)}])
+ :y (+ 0.05 j)
+ :on-click #(swap! app-state assoc-in [:board j i] 1)}])
(defn tictactoe []
[:div
[:h1 "Welcome to Tic Tac Toe"]
(into
- [:svg {:view-box "0 0 3 3"
+ [:svg {:view-box (str "0 0 " logic/board-size " " logic/board-size)
:width 500 :height 500}]
(for [i (range logic/board-size)
j (range logic/board-size)]
(case (get-in @app-state [:board j i])
- 0 [cross i j]
+ 0 [blank i j]
1 [cross i j]
2 [naught i j])))])