added leveling function to the math wizard game

This commit is contained in:
Patryk Hegenberg 2023-01-12 16:48:18 +01:00
parent 762458c88d
commit 65887a9ed5
2 changed files with 13 additions and 9 deletions

View file

@ -368,7 +368,7 @@
character: "@",
name: statsOfPlayer['username'].replace('"',''),
// the player's stats
stats: { hp: 10, xp: Number(statsOfPlayer['xp']), gold: Number(statsOfPlayer['coins']) },
stats: { hp: 10, xp: 0, gold: 0 },
// the ROT.js scheduler calls this method when it is time
// for the player to act
act: () => {
@ -418,7 +418,6 @@
// check if we've hit the monster
const hitMonster = monsterAt(x, y);
if (hitMonster) {
//combat(p, hitMonster);
setTimeout(function () {
Game.engine.unlock();
}, 250);
@ -601,7 +600,13 @@
let msg = [];
const randomValue = (min, max) =>
Math.floor(Math.random() * (max - min)) + min;
let [num1, num2] = [randomValue(1, 10), randomValue(1, 10)];
let num1, num2;
if (statsOfPlayer['level'] > 10) {
[num1, num2] = [randomValue(1, 10), randomValue(1, 10)];
} else {
num1 = statsOfPlayer['level'];
num2 = randomValue(1, 10);
}
const answerValue = eval(`${num1} * ${num2}`);
document.getElementById("question").innerHTML = `${num1} * ${num2} = ? `;
const clicked = await setupButtons(answerValue);
@ -744,16 +749,15 @@
function setEndScreenValues(xp, gold) {
$$(".xp-stat").forEach((el) => (el.textContent = Math.floor(xp)));
$$(".gold-stat").forEach((el) => (el.textContent = gold));
statsOfPlayer["coins"] = gold;
statsOfPlayer["coins"] += gold;
statsOfPlayer["username"] = Game.player.name.trim().replace('"','');
statsOfPlayer["lesson_count"] = Number(statsOfPlayer["lesson_count"]);
if (xp > 150) {
statsOfPlayer["level"] = Number(statsOfPlayer["level"]) + 1;
xp -= 150;
statsOfPlayer["xp"] = xp;
statsOfPlayer["xp"] += xp;
} else {
statsOfPlayer["level"] = Number(statsOfPlayer["level"]);
statsOfPlayer["xp"] = xp;
statsOfPlayer["xp"] += xp;
}
var json = JSON.stringify(statsOfPlayer);
var xhr = new XMLHttpRequest();

View file

@ -110,7 +110,7 @@
<p>Du hast das Spiel gewonnen.</p>
<p>Du hast <span class="gold-stat"></span> Gold und <span class="xp-stat"></span> XP erhalten.</p>
</div>
<button class="nes-btn is-success action">Ok</button>
<button onclick="javascript:window.location.href='/profile'" class="nes-btn is-success action">Ok</button>
</div>
<!-- lose screen -->
@ -122,7 +122,7 @@
<p>Du bist tot.</p>
<p>Du hast <span class="gold-stat"></span> Gold und <span class="xp-stat"></span> XP erhalten.</p>
</div>
<button class="nes-btn is-success action">Ok</button>
<button onclick="javascript:window.location.href='/profile'" class="nes-btn is-success action">Ok</button>
</div>
<!--Combat screen-->