changed game logic to generate player always in first walkable field and door/stairs in last

This commit is contained in:
Patryk Hegenberg 2023-01-10 08:35:47 +01:00
parent 8fd71ae57a
commit aaf1ff0c79
2 changed files with 16 additions and 17 deletions

View file

@ -249,14 +249,14 @@
const key = takeFreeCell(freeCells); const key = takeFreeCell(freeCells);
if (!i) { if (!i) {
if(count < 5) { if(count < 5) {
game.stairs = key; game.stairs = freeCells[freeCells.length - 1];
game.items[key] = "s"; game.items[freeCells[freeCells.length - 1]] = "s";
} else { } else {
game.door = key; game.door = freeCells[freeCells.length - 1];
game.items[key] = "D"; game.items[freeCells[freeCells.length - 1]] = "D";
} }
} else { } else {
game.items[key] = ROT.RNG.getItem(["g"]); game.items[key] = "g";
} }
} }
} }
@ -343,10 +343,16 @@
// both the player and monster initial position is set // both the player and monster initial position is set
function createBeing(what, freeCells) { function createBeing(what, freeCells) {
if (what == makePlayer) {
const pos = posFromKey(freeCells[0]);
const being = what(pos[0], pos[1]);
return being;
} else {
const key = takeFreeCell(freeCells); const key = takeFreeCell(freeCells);
const pos = posFromKey(key); const pos = posFromKey(key);
const being = what(pos[0], pos[1]); const being = what(pos[0], pos[1]);
return being; return being;
}
} }
/****************** /******************
@ -534,7 +540,6 @@
******************************/ ******************************/
// this is how the player fights a monster // this is how the player fights a monster
function checkSolution(solution, answer) { function checkSolution(solution, answer) {
console.log("Click: " + solution + " Antwort: " + answer);
if (solution == answer) { if (solution == answer) {
return true; return true;
} else { } else {
@ -589,9 +594,6 @@
} }
async function combat(hitter, receiver) { async function combat(hitter, receiver) {
console.log("hitter: " + hitter.name);
console.log("receiver: " + receiver.name);
console.log(hitter.stats.hp);
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;
@ -601,13 +603,11 @@
const clicked = await setupButtons(answerValue); const clicked = await setupButtons(answerValue);
let fight = checkSolution(clicked, answerValue); let fight = checkSolution(clicked, answerValue);
if(fight) { if(fight) {
console.log(fight);
msg.push("You hit the monster"); msg.push("You hit the monster");
hitter.stats.hp -= 1; hitter.stats.hp -= 1;
sfx["hit"].play(); sfx["hit"].play();
//Game.player.stats.xp += 1; //Game.player.stats.xp += 1;
} else { } else {
console.log(false);
sfx["miss"].play(); sfx["miss"].play();
msg.push("The monster hit you."); msg.push("The monster hit you.");
Game.player.stats.hp -= 1; Game.player.stats.hp -= 1;
@ -838,7 +838,6 @@
} }
if (code == 70 && ev.altKey && ev.ctrlKey && ev.shiftKey) { if (code == 70 && ev.altKey && ev.ctrlKey && ev.shiftKey) {
document.body.requestFullscreen(); document.body.requestFullscreen();
console.log("Full screen pressed.");
return; return;
} }
if (code == 190) { if (code == 190) {

View file

@ -51,7 +51,7 @@
class="nes-radio is-dark" class="nes-radio is-dark"
name="menu-items" name="menu-items"
checked/> checked/>
<span>Instructions</span> <span>Anleitung</span>
</label> </label>
<br/> <br/>
<label> <label>
@ -63,7 +63,7 @@
</label> </label>
</div> </div>
</div> </div>
<button id="play" class="nes-btn is-success action">Play</button> <button id="play" class="nes-btn is-success action">Start</button>
</div> </div>
<!-- credits screen --> <!-- credits screen -->
@ -93,10 +93,10 @@
<!-- instructions screen --> <!-- instructions screen -->
<div id="instructions" class="screen modal"> <div id="instructions" class="screen modal">
<p>Instructions</p> <p>Anleitung</p>
<div class="nes-container is-rounded is-dark"> <div class="nes-container is-rounded is-dark">
<p>Du musst dich durch denn Dungeon kämpfen und denn Weg in den höchsten Raum finden. du kämpfst durch das Lösen von Matheaufgaben. <p>Kämpfe dich durch denn Dungeon und finde den Weg in den untersten Raum. Durch das Lösen der Matheaufgaben fügst deinen Gegnern Schaden zu.
Solltest du eine falsche Antwort geben erleidest du Schaden, ansonsten fügst du deinem Gegner Schaden zu.</p> Bei einer falschen Antwort erleidest du Schaden.</p>
<p>Benutze die Pfeiltasten um dich zu bewegen.</p> <p>Benutze die Pfeiltasten um dich zu bewegen.</p>
</div> </div>
<button class="nes-btn is-success action">Ok</button> <button class="nes-btn is-success action">Ok</button>