From 8ac636186cf5f704264e7473864c54b3edaf4049 Mon Sep 17 00:00:00 2001 From: Julien Dessaux Date: Mon, 21 Nov 2022 21:39:17 +0100 Subject: Added basic games handling --- controllers/games/gameId.js | 17 +++++++++++++ controllers/games/root.js | 13 ++++++++++ controllers/play.js | 9 ------- database/001_games.sql | 12 +++++++++ database/db.js | 1 + database/games.js | 29 +++++++++++++++++++++ main.js | 4 +-- middlewares/sessions.js | 2 +- routes/games.js | 15 +++++++++++ routes/play.js | 35 ------------------------- static/index.css | 62 ++++++++++++++++++++++++++++++--------------- views/game.ejs | 36 ++++++++++++++++++++++++++ views/games.ejs | 17 +++++++++++++ views/play.ejs | 36 -------------------------- 14 files changed, 184 insertions(+), 104 deletions(-) create mode 100644 controllers/games/gameId.js create mode 100644 controllers/games/root.js delete mode 100644 controllers/play.js create mode 100644 database/001_games.sql create mode 100644 database/games.js create mode 100644 routes/games.js delete mode 100644 routes/play.js create mode 100644 views/game.ejs create mode 100644 views/games.ejs delete mode 100644 views/play.ejs diff --git a/controllers/games/gameId.js b/controllers/games/gameId.js new file mode 100644 index 0000000..c87a857 --- /dev/null +++ b/controllers/games/gameId.js @@ -0,0 +1,17 @@ +import { getGame } from "../../database/games.js"; + +function makePageData(user, cwdata) { + return { + title: "Jouer", + user: user, + CWDATA: cwdata, + }; +} + +export function gameId_get(req, res) { + const game = getGame(req.params.gameId); + // TODO redirect if null + let cwdata = game; // TODO reformat this object + console.log(cwdata); + return res.render("game", makePageData(req.session.user, cwdata)); +} diff --git a/controllers/games/root.js b/controllers/games/root.js new file mode 100644 index 0000000..ece7b74 --- /dev/null +++ b/controllers/games/root.js @@ -0,0 +1,13 @@ +import { listGames } from "../../database/games.js"; + +export function root_get(req, res) { + const data = { + title: "Liste des parties", + user: req.session.user, + games: listGames(req.session.user.id), + }; + for (let i=0; i { - const cwdata = { - board: [ - [ "", "", "", "", "","", "", "", "", "", "", "", "", "", "" ], - [ "", "", "", "", "","", "", "", "", "", "", "", "", "", "" ], - [ "", "", "", "", "","", "", "", "", "", "", "", "", "", "" ], - [ "", "", "", "", "","", "", "", "", "", "", "", "", "", "" ], - [ "", "", "", "", "","", "", "", "", "", "", "", "", "", "" ], - [ "", "", "", "", "","", "", "", "", "", "", "", "", "", "" ], - [ "", "", "", "", "","", "", "", "", "", "", "", "", "", "" ], - [ "", "", "", "", "","", "", "", "", "", "", "", "", "", "" ], - [ "", "", "", "", "","", "", "", "", "", "", "", "", "", "" ], - [ "", "", "", "", "","", "", "", "", "", "", "", "", "", "" ], - [ "", "", "", "", "","", "", "", "", "", "", "", "", "", "" ], - [ "", "", "", "", "","", "", "", "", "", "", "", "", "", "" ], - [ "", "", "", "", "","", "", "", "", "", "", "", "", "", "" ], - [ "", "", "", "", "","", "", "", "", "", "", "", "", "", "" ], - [ "", "", "", "", "","", "", "", "", "", "", "", "", "", "" ] - ], - letters: [ "A", "B", "C", "D", "E", "F", "JOKER" ] - }; - return res.render("play", makePlayController(req, cwdata)); -}); - -export default router; diff --git a/static/index.css b/static/index.css index f5ef0b9..afb1c33 100644 --- a/static/index.css +++ b/static/index.css @@ -8,7 +8,7 @@ aside { } body { - background: #126623; + background: #358a46; display: grid; grid-template-rows: auto 1fr auto; font-family: -apple-system, BlinkMacSystemFont, @@ -50,11 +50,12 @@ header nav ul li { text-decoration: none; } header nav ul li a { - color: #b58900; + color: black; display: block; text-decoration: none; } header nav ul li.nav-menu-title { + background: #126623; float: left; text-transform: uppercase; font-weight: 700; @@ -68,50 +69,69 @@ form input { } main { - margin-left: auto; - margin-right: auto; + background: #126623; + padding-left: 1em; + padding-right: 1em; } -td { - background: #47b75e; - border: 1px solid #d4fcdb; - min-width: 27px; - height: 27px; - text-align: center; +#games { + border-collapse: collapse; +} +#games tr:nth-child(even){background-color: #f2f2f2;} +#games tr:hover {background-color: #ddd;} +#games td, #games th { + border: 1px solid #ddd; + padding: 8px; +} +#games th { + padding-top: 12px; + padding-bottom: 12px; + text-align: left; + background-color: #04AA6D; + color: white; } -#board { - border-collapse: collapse; - font-weight: bold; +#remaining_letters { max-width: 405px; } +#rack-area { + max-width: 405px; +} #rack { display:inline-block; font-weight: bold; } - -#remaining_letters { +#board { + border-collapse: collapse; + font-weight: bold; max-width: 405px; } +#board tr td, #rack tr td { + background: #47b75e; + border: 1px solid #d4fcdb; + min-width: 27px; + height: 27px; + text-align: center; +} -.tw { +#board tr td.tw { background:#E60000; } -.dw { +#board tr td.dw { background:#F86969; } -.tl { +#board tr td.tl { background:#3675FA; } -.dl { +#board tr td.dl { background:#22ACD8; } -.start { +#board tr td.start { background:#ff5500; } -.letter { +#board tr td.letter, #rack tr td.letter { background:#f3e797; } .placed { diff --git a/views/game.ejs b/views/game.ejs new file mode 100644 index 0000000..e1fab41 --- /dev/null +++ b/views/game.ejs @@ -0,0 +1,36 @@ +<%- include("header") %> +

À vous de jouer

+ + + + + + + + + + + + + + + + +
+

+ + +
+

+

+

+player one name: 0
+player two name: 0 +

+

+ + +<%- include("footer") %> diff --git a/views/games.ejs b/views/games.ejs new file mode 100644 index 0000000..3189be8 --- /dev/null +++ b/views/games.ejs @@ -0,0 +1,17 @@ +<%- include("header") %> +<% if (Object.keys(games).length === 0) { %> +

Aucune partie en cours

+<% } else { %> +

Liste des parties en cours

+ + + <% games.forEach((game) => { %> + + + + + + <% }) %> +
PartieJoueur 1Joueur 2
<%= game.data.title %><%= game.data.player1.name %><%= game.data.player2.name %>
+<% } %> +<%- include("footer") %> diff --git a/views/play.ejs b/views/play.ejs deleted file mode 100644 index bc98c94..0000000 --- a/views/play.ejs +++ /dev/null @@ -1,36 +0,0 @@ -<%- include("header") %> -

À vous de jouer

- - - - - - - - - - - - - - - - -
-

- - -
-

-

-

-player one name: 0
-player two name: 0 -

-

- - -<%- include("footer") %> -- cgit v1.2.3