scoring view
This commit is contained in:
parent
62ec327502
commit
ab57a15c12
2 changed files with 45 additions and 19 deletions
|
|
@ -3,5 +3,6 @@ CREATE TABLE IF NOT EXISTS game (
|
|||
code text UNIQUE,
|
||||
display_session text NOT NULL,
|
||||
control_session text,
|
||||
current_player integer,
|
||||
active boolean not null
|
||||
);
|
||||
|
|
|
|||
|
|
@ -35,14 +35,12 @@
|
|||
player-order (if random-order?
|
||||
(shuffle (range 0 (count players)))
|
||||
(range 0 (count players)))]
|
||||
(println players)
|
||||
(println player-order)
|
||||
(println (interleave players player-order))
|
||||
|
||||
(jdbc/execute! ds (sql/format {:insert-into :game
|
||||
:values [{:id id
|
||||
:code code
|
||||
:display_session id
|
||||
:current_player 0
|
||||
:active false}]
|
||||
:on-conflict :id
|
||||
:do-update-set [:code :display_session :active]}))
|
||||
|
|
@ -72,8 +70,6 @@
|
|||
:from :player
|
||||
:where [:= :game_code (:game/code game)]})))]
|
||||
|
||||
(println id)
|
||||
(pprint/pprint game)
|
||||
(ui/page
|
||||
{}
|
||||
[:div
|
||||
|
|
@ -98,30 +94,60 @@
|
|||
[:th {:scope "row"} (:player/name p)]
|
||||
[:td (:player/score p)]]))]]])))
|
||||
|
||||
(defn checkbox [n]
|
||||
[:label
|
||||
[:input {:type "checkbox", :name n}]
|
||||
n])
|
||||
|
||||
(def pig-position
|
||||
["jowler"
|
||||
"trotter"
|
||||
"snouter"
|
||||
"black dot"
|
||||
"no dot"
|
||||
"razorback"])
|
||||
|
||||
(defn control-view [{:keys [session params path-params]
|
||||
:example/keys [ds]
|
||||
:as _ctx}]
|
||||
|
||||
(let [code (:code path-params)
|
||||
players (sort-by :player/play_order (jdbc/execute! ds (sql/format {:select :* :from :player :where [:= :game_code code]})))]
|
||||
players (into []
|
||||
(sort-by
|
||||
:player/play_order
|
||||
(jdbc/execute! ds (sql/format {:select :*
|
||||
:from :player
|
||||
:where [:= :game_code code]}))))
|
||||
game (jdbc/execute-one! ds (sql/format {:select :*
|
||||
:from :game
|
||||
:where [:= :code code]}))
|
||||
current-player (:game/current_player game)]
|
||||
(ui/page {}
|
||||
[:div [:nav
|
||||
[:ul [:li [:strong "Score the pigs"]]]
|
||||
[:ul [:li [:strong (str "Score the pigs - " code)]]]
|
||||
[:ul [:li (biff/form {:id "reset"
|
||||
:hx-get "/reset"}
|
||||
[:button.secondary "Reset"])]]]
|
||||
[:h5 (str "Game " code)]
|
||||
[:table
|
||||
[:thead
|
||||
[:tr
|
||||
[:th {:scope "col"} "Player"]
|
||||
[:th {:scope "col"} "Score"]]]
|
||||
[:h4 "Playing next:" (-> (get players current-player) :player/name)]
|
||||
|
||||
(into [:tbody]
|
||||
(for [p players]
|
||||
[:tr
|
||||
[:th {:scope "row"} (:player/name p)]
|
||||
[:td (:player/score p)]]))]])))
|
||||
(biff/form {:id ::score-form}
|
||||
[:table
|
||||
[:thead
|
||||
[:tr
|
||||
[:th {:scope "col"} "Pig 1"]
|
||||
[:th {:scope "col"} "Pig 2"]]]
|
||||
|
||||
[:tbody
|
||||
(for [p1 pig-position
|
||||
;; p2 pig-position
|
||||
]
|
||||
[:tr
|
||||
[:td
|
||||
(checkbox p1)]
|
||||
|
||||
[:td (checkbox p1)]])]]
|
||||
[:button {:type "submit"} "Score pigs"]
|
||||
[:button.contrast {:type "submit"} "Pigs are touching! (Lose all points)"])])))
|
||||
|
||||
(defn connect
|
||||
[{:keys [session params]
|
||||
|
|
@ -130,7 +156,6 @@
|
|||
(let [code (:game-code params)
|
||||
game (delay (jdbc/execute-one! ds (sql/format {:select :* :from :game
|
||||
:where [:= :code code]})))]
|
||||
(println params)
|
||||
(if (and code @game)
|
||||
{:status 200
|
||||
:session session
|
||||
|
|
|
|||
Loading…
Reference in a new issue