Statki
+Wybierz tryb gry
+PvP
+Graj przeciwko innemu graczowi
+Vs. AI
+Graj przeciwko komputerowi
diff --git a/index.js b/index.js index a20fe7f..58bf8e8 100644 --- a/index.js +++ b/index.js @@ -34,22 +34,15 @@ app.get("/", (req, res) => { res.render('index'); }); -app.get("/pvp", (req, res) => { - res.render('pvp/index'); +app.get("/*", (req, res) => { + res.redirect("/?path=" + req.originalUrl); }); -app.get("/pvp/join", (req, res) => { - res.render('pvp/join'); -}); - -app.get("/pvp/create", (req, res) => { - res.render('pvp/create'); -}); - - io.on('connection', (socket) => { const session = socket.request.session; + + socket.on('chat message', (msg) => { console.log('message: ' + msg); }); diff --git a/package.json b/package.json index af654e4..5fa506b 100644 --- a/package.json +++ b/package.json @@ -5,7 +5,8 @@ "main": "index.js", "type": "module", "scripts": { - "test": "echo \"Error: no test specified\" && exit 1" + "test": "echo \"Error: no test specified\" && exit 1", + "start": "node ." }, "repository": { "type": "git", diff --git a/public/assets/css/board.css b/public/assets/css/board.css index 551dda4..c91be99 100644 --- a/public/assets/css/board.css +++ b/public/assets/css/board.css @@ -93,6 +93,7 @@ h1,h2,h3,h4,h5,h6 { display: flex; justify-content: center; text-align: center; + transition: 0.15s opacity; } .shapes h2, .shapes h3 { diff --git a/public/assets/css/main.css b/public/assets/css/main.css new file mode 100644 index 0000000..769df43 --- /dev/null +++ b/public/assets/css/main.css @@ -0,0 +1,133 @@ +.container { + display: none; +} + +/* index */ +#mainMenuView .modes { + display: flex; + gap: 2rem; +} + +#mainMenuView .modes div { + height: 10rem; + width: 10rem; + background: black; + border: solid 1px white; + border-radius: 15px; + user-select: none; + cursor: pointer; + transition: all 0.3s; +} + +#mainMenuView .modes div:hover { + background: white; + color: black; +} + +/* PvP/index */ +#pvpMenuView .modes { + display: flex; + gap: 2rem; +} + +#pvpMenuView .modes div { + height: 10rem; + width: 10rem; + background: black; + border: solid 1px white; + border-radius: 15px; + user-select: none; + cursor: pointer; + transition: all 0.3s; +} + +#pvpMenuView .modes div:hover { + background: white; + color: black; +} + +/* PvP/create */ +#pvpCreateView .modes { + display: flex; + gap: 2rem; +} + +#pvpCreateView .modes div { + height: 17rem; + width: 15rem; + background: black; + border: solid 1px white; + border-radius: 15px; + user-select: none; + padding: 1rem 3rem; + display: flex; + flex-direction: column; + gap: 0.5rem; +} + +#pvpCreateView input, #pvpCreateView button { + background: black; + color: white; + border-radius: 15px; + border: 1px solid white; + font-size: 1.5rem; + text-align: center; + padding: 0.5rem 2rem; + outline: none; + transition: opacity 0.2s; +} + +#pvpCreateView button { + cursor: pointer; + font-size: 1rem; + transition: all 0.3s; +} + +#pvpCreateView button:hover { + background: white; + color: black; +} + +/* PvP/join */ +#pvpJoinView .modes { + display: flex; + gap: 2rem; +} + +#pvpJoinView .modes div { + height: 7rem; + width: 15rem; + background: black; + border: solid 1px white; + border-radius: 15px; + user-select: none; + padding: 2rem 3rem; +} + +#pvpJoinView form { + display: flex; + flex-direction: column; + gap: 2rem; +} + +#pvpJoinView form input { + background: black; + color: white; + border-radius: 15px; + border: 1px solid white; + font-size: 1.5rem; + text-align: center; + padding: 0.5rem 2rem; + outline: none; +} + +#pvpJoinView form input[type=submit] { + cursor: pointer; + font-size: 1rem; + transition: all 0.3s; +} + +#pvpJoinView form input[type=submit]:hover { + background: white; + color: black; +} \ No newline at end of file diff --git a/public/assets/js/matchmaking.js b/public/assets/js/matchmaking.js deleted file mode 100644 index e69de29..0000000 diff --git a/public/assets/js/socket.js b/public/assets/js/socket.js new file mode 100644 index 0000000..6442a00 --- /dev/null +++ b/public/assets/js/socket.js @@ -0,0 +1,2 @@ +const socket = io(); + diff --git a/public/assets/js/spa_lib.js b/public/assets/js/spa_lib.js new file mode 100644 index 0000000..251d1e8 --- /dev/null +++ b/public/assets/js/spa_lib.js @@ -0,0 +1,44 @@ +var activeView; + +function switchView(viewContainerId, useReplaceState=false) { + $(`.container`).css("opacity", 0); + setTimeout(() => { + $(`.container`).css("display", "none"); + $(`.container#${viewContainerId}`).css({"display": "flex", "opacity": "1"}); + let path = $(`.container#${viewContainerId}`).data("path"); + let title = $(`.container#${viewContainerId}`).data("title"); + if (useReplaceState) { + history.replaceState(null, "", path ? path : "/"); + } else { + history.pushState(null, title ? title : "Statki", path ? path : "/"); + } + + activeView = viewContainerId; + }, 150); +} + +const initialURLParams = new URLSearchParams(window.location.search); +const initialPath = initialURLParams.get('path'); + +window.addEventListener("load", () => { + if (initialPath != null) { + let elem = document.querySelector(`.container[data-path="${initialPath}"]`); + + if (elem != null) { + switchView(elem.id, true); + activeView = elem.id; + + } + } else { + switchView("mainMenuView"); + activeView = "mainMenuView"; + } +}); + +addEventListener("popstate", (event) => { + event.preventDefault(); + let elem = document.querySelector(`.container[data-path="${window.location.pathname}"]`); + if (elem != null) { + switchView(elem.id, true); + } +}); \ No newline at end of file diff --git a/views/game.handlebars b/views/game.handlebars deleted file mode 100644 index 2fcc63b..0000000 --- a/views/game.handlebars +++ /dev/null @@ -1,47 +0,0 @@ - - -
- - - - -Graj przeciwko innemu graczowi
-Graj przeciwko komputerowi
-Graj przeciwko innemu graczowi
+Graj przeciwko komputerowi
Stwórz własny pokój
+Dołącz do czyjegoś pokoju poprzez kod
+Stwórz własny pokój
-Dołącz do czyjegoś pokoju poprzez kod
-