added leveling function to the math wizard game
This commit is contained in:
parent
762458c88d
commit
65887a9ed5
2 changed files with 13 additions and 9 deletions
|
|
@ -368,7 +368,7 @@
|
||||||
character: "@",
|
character: "@",
|
||||||
name: statsOfPlayer['username'].replace('"',''),
|
name: statsOfPlayer['username'].replace('"',''),
|
||||||
// the player's stats
|
// 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
|
// the ROT.js scheduler calls this method when it is time
|
||||||
// for the player to act
|
// for the player to act
|
||||||
act: () => {
|
act: () => {
|
||||||
|
|
@ -418,7 +418,6 @@
|
||||||
// check if we've hit the monster
|
// check if we've hit the monster
|
||||||
const hitMonster = monsterAt(x, y);
|
const hitMonster = monsterAt(x, y);
|
||||||
if (hitMonster) {
|
if (hitMonster) {
|
||||||
//combat(p, hitMonster);
|
|
||||||
setTimeout(function () {
|
setTimeout(function () {
|
||||||
Game.engine.unlock();
|
Game.engine.unlock();
|
||||||
}, 250);
|
}, 250);
|
||||||
|
|
@ -601,7 +600,13 @@
|
||||||
let msg = [];
|
let msg = [];
|
||||||
const randomValue = (min, max) =>
|
const randomValue = (min, max) =>
|
||||||
Math.floor(Math.random() * (max - min)) + min;
|
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}`);
|
const answerValue = eval(`${num1} * ${num2}`);
|
||||||
document.getElementById("question").innerHTML = `${num1} * ${num2} = ? `;
|
document.getElementById("question").innerHTML = `${num1} * ${num2} = ? `;
|
||||||
const clicked = await setupButtons(answerValue);
|
const clicked = await setupButtons(answerValue);
|
||||||
|
|
@ -744,16 +749,15 @@
|
||||||
function setEndScreenValues(xp, gold) {
|
function setEndScreenValues(xp, gold) {
|
||||||
$$(".xp-stat").forEach((el) => (el.textContent = Math.floor(xp)));
|
$$(".xp-stat").forEach((el) => (el.textContent = Math.floor(xp)));
|
||||||
$$(".gold-stat").forEach((el) => (el.textContent = gold));
|
$$(".gold-stat").forEach((el) => (el.textContent = gold));
|
||||||
statsOfPlayer["coins"] = gold;
|
statsOfPlayer["coins"] += gold;
|
||||||
statsOfPlayer["username"] = Game.player.name.trim().replace('"','');
|
statsOfPlayer["username"] = Game.player.name.trim().replace('"','');
|
||||||
statsOfPlayer["lesson_count"] = Number(statsOfPlayer["lesson_count"]);
|
|
||||||
if (xp > 150) {
|
if (xp > 150) {
|
||||||
statsOfPlayer["level"] = Number(statsOfPlayer["level"]) + 1;
|
statsOfPlayer["level"] = Number(statsOfPlayer["level"]) + 1;
|
||||||
xp -= 150;
|
xp -= 150;
|
||||||
statsOfPlayer["xp"] = xp;
|
statsOfPlayer["xp"] += xp;
|
||||||
} else {
|
} else {
|
||||||
statsOfPlayer["level"] = Number(statsOfPlayer["level"]);
|
statsOfPlayer["level"] = Number(statsOfPlayer["level"]);
|
||||||
statsOfPlayer["xp"] = xp;
|
statsOfPlayer["xp"] += xp;
|
||||||
}
|
}
|
||||||
var json = JSON.stringify(statsOfPlayer);
|
var json = JSON.stringify(statsOfPlayer);
|
||||||
var xhr = new XMLHttpRequest();
|
var xhr = new XMLHttpRequest();
|
||||||
|
|
|
||||||
|
|
@ -110,7 +110,7 @@
|
||||||
<p>Du hast das Spiel gewonnen.</p>
|
<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>
|
<p>Du hast <span class="gold-stat"></span> Gold und <span class="xp-stat"></span> XP erhalten.</p>
|
||||||
</div>
|
</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>
|
</div>
|
||||||
|
|
||||||
<!-- lose screen -->
|
<!-- lose screen -->
|
||||||
|
|
@ -122,7 +122,7 @@
|
||||||
<p>Du bist tot.</p>
|
<p>Du bist tot.</p>
|
||||||
<p>Du hast <span class="gold-stat"></span> Gold und <span class="xp-stat"></span> XP erhalten.</p>
|
<p>Du hast <span class="gold-stat"></span> Gold und <span class="xp-stat"></span> XP erhalten.</p>
|
||||||
</div>
|
</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>
|
</div>
|
||||||
|
|
||||||
<!--Combat screen-->
|
<!--Combat screen-->
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue