From 0055c8ef85a5c457d06ed8e798f1c37968261bfe Mon Sep 17 00:00:00 2001 From: Patryk Hegenberg Date: Sun, 22 Jan 2023 18:50:14 +0100 Subject: [PATCH] modified gamecode, styling of some parts of the website, cleaned up unneeded files and code, added remember me function --- controllers/login.php | 4 +- scripts/game.js | 86 +++++++--------- scripts/web.js | 30 ------ styles/style.css | 26 +++++ views/game.view.php | 2 +- views/index.view.php | 10 +- views/learn.view.php | 208 ++++++++++++++++++-------------------- views/login.view.php | 2 +- views/partials/footer.php | 1 - views/partials/nav.php | 2 +- views/profile.view.php | 2 +- 11 files changed, 176 insertions(+), 197 deletions(-) delete mode 100644 scripts/web.js diff --git a/controllers/login.php b/controllers/login.php index 30782db..1640468 100644 --- a/controllers/login.php +++ b/controllers/login.php @@ -8,5 +8,7 @@ $db = new Database($config['database'], $username, $password); if (isset($_POST["submit"])) { $db->login([$_POST["username"], $_POST["password"]]); } - +if (isset($_POST["remember"])) { + setcookie("user", $_POST["username"], time() + (86400 * 30), "/"); +} require "views/login.view.php"; diff --git a/scripts/game.js b/scripts/game.js index d05d5fa..576c364 100644 --- a/scripts/game.js +++ b/scripts/game.js @@ -1,7 +1,7 @@ (function (w) { var playerStats = document.getElementById("playerStats").innerHTML; - function convertData(stats) { + const convertData = (stats) => { var player = {}; stats = stats.replace("'", "").replace("{","").replace("}",""); stats = stats.split(","); @@ -25,8 +25,8 @@ *** resources *** *****************/ - // This tileset is from kenney.nl - // It's the "microrogue" tileset + // This tileset is from 0x72 + // It's the "16x16 DungeonTileset" tileset const tileSet = document.createElement("img"); tileSet.src = "./../images/16x16DungeonTileset.png"; @@ -60,8 +60,6 @@ height: 40, }; - //const usePointer = true; - //const useArrows = true; const touchOffsetY = -20; // move the center by this much const scaleMonitor = 3; // scale computer screens by this much const turnLengthMS = 200; // shortest time between turns @@ -128,7 +126,7 @@ playerAllowedToMove: true, }; - function init(game) { + const init = (game) => { game.map = {}; game.items = {}; game.display = new ROT.Display(tileOptions); @@ -147,7 +145,7 @@ count = 1; } - function nextStage(game, stage, stats) { + const nextStage = (game, stage, stats) => { game.map = {}; game.items = {}; game.display = new ROT.Display(tileOptions); @@ -172,7 +170,7 @@ game.engine.start();; } - function destroy(game) { + const destroy = (game) => { removeListeners(game); if (game.engine) { @@ -246,13 +244,13 @@ } } - function takeFreeCell(freeCells) { + const takeFreeCell = (freeCells) => { const index = Math.floor(ROT.RNG.getUniform() * freeCells.length); const key = freeCells.splice(index, 1)[0]; return key; } - function posFromKey(key) { + const posFromKey = (key) => { const parts = key.split(","); const x = parseInt(parts[0]); const y = parseInt(parts[1]); @@ -334,7 +332,7 @@ *** the player *** ******************/ - function makePlayer(x, y) { + const makePlayer = (x, y) => { return { _x: x, _y: y, @@ -350,16 +348,11 @@ }, }; } - - function checkItem(entity) { + const checkItem = (entity) => { const key = entity._x + "," + entity._y; if (key == Game.door) { - if(count < 5) { - nextStage(Game, ++count, Game.player.stats); - } else { - win(); - } - } else if (key == Game.stairs) { + (count < 5 ? nextStage(Game, ++count, Game.player.stats) : win()); + } else if (key == Game.stairs && Game.monsters.length == 0) { nextStage(Game, ++count, Game.player.stats); }else if (Game.items[key] == "g") { Game.player.stats.gold += 1; @@ -370,13 +363,12 @@ } drawTile(Game, key); } - - function movePlayer(dir) { + const movePlayer = (dir) => { const p = Game.player; return movePlayerTo(p._x + dir[0], p._y + dir[1]); } - function movePlayerTo(x, y) { + const movePlayerTo = (x, y) => { const p = Game.player; const newKey = x + "," + y; @@ -453,14 +445,14 @@ const map = Game.map; const display = Game.display; - const passableCallback = function (x, y) { + const passableCallback = (x, y) => { return walkable.indexOf(map[x + "," + y]) != -1; }; const astar = new ROT.Path.AStar(p._x, p._y, passableCallback, { topology: 4, }); const path = []; - const pathCallback = function (x, y) { + const pathCallback = (x, y) => { path.push([x, y]); }; astar.compute(m._x, m._y, pathCallback); @@ -489,7 +481,7 @@ } } - function playerAt(x, y) { + const playerAt = (x, y) => { return Game.player && Game.player._x == x && Game.player._y == y ? Game.player : null; @@ -520,12 +512,8 @@ /****************************** *** combat/win/lose events *** ******************************/ - function checkSolution(solution, answer) { - if (solution == answer) { - return true; - } else { - return false; - } + const checkSolution = (solution, answer) => { + return solution == answer; } async function setupButtons(answerValue) { @@ -544,8 +532,7 @@ } if (random1 < 1) { random1 = 1 + randomValue(0,2); - } - if (random2 < 1) { + } else if (random2 < 1) { random2 = 1 + randomValue(0, 2); } if (randomVar === 1) { @@ -613,7 +600,7 @@ Game.engine.unlock(); } - function win() { + const win = () => { Game.engine.lock(); Game.player.stats.xp += 10; for (let i = 0; i < 5; i++) { @@ -626,7 +613,7 @@ showScreen("win"); } - function lose() { + const lose = () => { Game.engine.lock(); const p = Game.player; p.character = "T"; @@ -650,7 +637,7 @@ const $$ = document.querySelectorAll.bind(document); NodeList.prototype.forEach = Array.prototype.forEach; - function resetCanvas(el) { + const resetCanvas = (el) => { $("#canvas").innerHTML = ""; $("#canvas").appendChild(el); window.onkeydown = keyHandler; @@ -658,7 +645,7 @@ showScreen("game"); } - function rescale(x, y, game) { + const rescale = (x, y, game) => { const c = $("canvas"); const scale = scaleMonitor; const offset = game.touchScreen ? touchOffsetY : 0; @@ -689,7 +676,7 @@ } } - function removeListeners(game) { + const removeListeners = (game) => { if (game.engine) { game.lastArrow = null; clearInterval(game.arrowInterval); @@ -703,7 +690,7 @@ } } - function showScreen(which, ev) { + const showScreen = (which, ev) => { ev && ev.preventDefault(); const el = $("#" + which); const actionbutton = $("#" + which + ">.action"); @@ -720,11 +707,13 @@ } } - function setEndScreenValues(xp, gold) { + const setEndScreenValues = (xp, gold) => { $$(".xp-stat").forEach((el) => (el.textContent = Math.floor(xp))); $$(".gold-stat").forEach((el) => (el.textContent = gold)); + statsOfPlayer["coins"] += gold; statsOfPlayer["username"] = Game.player.name.trim().replace('"',''); + if ((statsOfPlayer['xp'] + xp) > 150) { statsOfPlayer["level"] = Number(statsOfPlayer["level"]) + 1; statsOfPlayer["xp"] += xp; @@ -733,6 +722,7 @@ statsOfPlayer["level"] = Number(statsOfPlayer["level"]); statsOfPlayer["xp"] += xp; } + var json = JSON.stringify(statsOfPlayer); var xhr = new XMLHttpRequest(); xhr.open("POST", "/updateData", true); @@ -742,11 +732,10 @@ console.log(this.responseText); } } - console.log(json); xhr.send(json); } - function renderStats(stats) { + const renderStats = (stats) => { const st = $("#hud"); st.innerHTML = ""; for (let s in stats) { @@ -754,7 +743,7 @@ } } - function battleMessage(messages) { + const battleMessage = (messages) => { const components = messages.reduce(function (msgs, m) { return msgs .concat( @@ -768,7 +757,7 @@ return el("span", {}, components); } - function toast(message) { + const toast = (message) => { const m = $("#message"); if ( Game.scheduler._current == Game.player || @@ -785,7 +774,7 @@ } } - function hideToast(instant) { + const hideToast = (instant) => { const m = $("#message"); if (instant) { m.classList.remove("show"); @@ -801,7 +790,7 @@ } } - function el(tag, attrs, children) { + const el = (tag, attrs, children) => { const node = document.createElement(tag); for (a in attrs) { node[a] = attrs[a]; @@ -816,12 +805,12 @@ return node; } - function attach(node, el) { + const attach = (node, el) => { node.appendChild(el); return el; } - function rmel(node) { + const rmel = (node) => { node.parentNode.removeChild(node); } @@ -831,7 +820,6 @@ function keyHandler(ev) { const code = ev.keyCode; - console.log(code); if (code == 187 || code == 189) { ev.preventDefault(); return; diff --git a/scripts/web.js b/scripts/web.js deleted file mode 100644 index aeb7b63..0000000 --- a/scripts/web.js +++ /dev/null @@ -1,30 +0,0 @@ -!(function () { - const e = document, - t = e.documentElement, - n = e.body, - i = e.getElementById("lights-toggle"), - s = (window.sr = ScrollReveal()); - function a() { - let e = i.parentNode.querySelector(".label-text"); - i.checked - //? (n.classList.remove("lights-off"), e && (e.innerHTML = "dark")) - ? (n.classList.add("lights-off"), e && (e.innerHTML = "light")) - : (n.classList.add("lights-off"), e && (e.innerHTML = "light")); - } - t.classList.remove("no-js"), - t.classList.add("js"), - window.addEventListener("load", function () { - n.classList.add("is-loaded"); - }), - n.classList.contains("has-animations") && - window.addEventListener("load", function () { - s.reveal(".feature", { - duration: 600, - distance: "20px", - easing: "cubic-bezier(0.215, 0.61, 0.355, 1)", - origin: "right", - viewFactor: 0.2, - }); - }), - i && (window.addEventListener("load", a), i.addEventListener("change", a)); -})(); diff --git a/styles/style.css b/styles/style.css index 2ff2084..fbbc2a4 100644 --- a/styles/style.css +++ b/styles/style.css @@ -497,6 +497,32 @@ main { text-align: center; background-color: #3f2a34; } + +.learn { + height: 1000px; + display: flex; + flex-wrap: wrap; + gap: 5px; + justify-content: space-between; + text-align: center; + align-items: flex-start; + background-color: #3f2a34; + border-radius: 5px; + box-shadow: #3f2a34; +} +.learnContainer { + display: flex; + justify-content: center; + align-items: center; + flex-direction: column; + margin: 0 auto; + margin-top: 20px; + height: 150px; + background-color: #2e1e26; + padding: 20px; + border-radius: 5px; + box-shadow: 0 0 4px #433e4c +} .profile { height: 1200px; display: flex; diff --git a/views/game.view.php b/views/game.view.php index 6f3423e..6243135 100644 --- a/views/game.view.php +++ b/views/game.view.php @@ -87,7 +87,7 @@ irmirx
  • Parts of the Gamelogic and Design by - chr15m + chr15m
  • diff --git a/views/index.view.php b/views/index.view.php index c52cd72..3e2036a 100644 --- a/views/index.view.php +++ b/views/index.view.php @@ -29,7 +29,7 @@
    - Feature 01 + Feature 01

    Immer neue Level

    @@ -40,7 +40,7 @@
    - Feature 02 + Feature 02

    Angepasste Schwierigkeit

    @@ -51,7 +51,7 @@
    - Feature 03 + Feature 03

    Fokus auf das was zählt

    @@ -62,7 +62,7 @@
    - Feature 04 + Feature 04

    Lernfortschritt immer im Blick

    @@ -91,4 +91,4 @@ - \ No newline at end of file + diff --git a/views/learn.view.php b/views/learn.view.php index 28f3091..55b14f0 100644 --- a/views/learn.view.php +++ b/views/learn.view.php @@ -1,113 +1,107 @@ -
    -
    -
    -
    -
    - - -
    -
    -
    1 x 1
    - - - -
    -
    - - -
    -
    -
    1 x 2
    - - - -
    -
    - - -
    -
    -
    1 x 3
    - - - -
    -
    - - -
    -
    -
    1 x 4
    - - - -
    -
    - - -
    -
    -
    1 x 5
    - - - -
    -
    - - -
    -
    -
    1 x 6
    - - - -
    -
    - - -
    -
    -
    1 x 7
    - - - -
    -
    - - -
    -
    -
    1 x 8
    - - - -
    -
    - - -
    -
    -
    1 x 9
    - - - -
    -
    - - -
    -
    -
    1 x 10
    - - - -
    -
    +
    +
    + +
    +
    + + +
    +
    +
    1 x 2
    + + + +
    +
    + + +
    +
    +
    1 x 3
    + + + +
    +
    + + +
    +
    +
    1 x 4
    + + + +
    +
    + + +
    +
    +
    1 x 5
    + + + +
    +
    + + +
    +
    +
    1 x 6
    + + + +
    +
    + + +
    + +
    1 x 7
    + + + +
    + + +
    +
    +
    1 x 8
    + + + +
    -
    - \ No newline at end of file + + +
    +
    +
    1 x 9
    + + + +
    +
    + + +
    +
    +
    1 x 10
    + + + +
    +
    + +
    +
    + diff --git a/views/login.view.php b/views/login.view.php index 74e7d27..1038810 100644 --- a/views/login.view.php +++ b/views/login.view.php @@ -19,7 +19,7 @@
    diff --git a/views/partials/footer.php b/views/partials/footer.php index 7a4d2ff..7efa402 100644 --- a/views/partials/footer.php +++ b/views/partials/footer.php @@ -12,6 +12,5 @@
    - diff --git a/views/partials/nav.php b/views/partials/nav.php index 2a71c19..542c063 100644 --- a/views/partials/nav.php +++ b/views/partials/nav.php @@ -1,6 +1,6 @@
    -