diff options
author | elioat <elioat@tilde.institute> | 2024-07-07 16:38:51 -0400 |
---|---|---|
committer | elioat <elioat@tilde.institute> | 2024-07-07 16:38:51 -0400 |
commit | aac1aa11ebd304373ac9a6c0fb6bd129e7b2920c (patch) | |
tree | 476d933f76569fd3aa2abac56a290fb05afeeb3f /js/puzzle-dungeon | |
parent | 3ebea70dbc42b0a48f55a86d6416942f7ae18b28 (diff) | |
download | tour-aac1aa11ebd304373ac9a6c0fb6bd129e7b2920c.tar.gz |
*
Diffstat (limited to 'js/puzzle-dungeon')
-rw-r--r-- | js/puzzle-dungeon/game.js | 23 |
1 files changed, 14 insertions, 9 deletions
diff --git a/js/puzzle-dungeon/game.js b/js/puzzle-dungeon/game.js index 8b53da9..179ea4e 100644 --- a/js/puzzle-dungeon/game.js +++ b/js/puzzle-dungeon/game.js @@ -130,10 +130,10 @@ export function drawGrid(grid) { export function initializeGame() { grid = createGrid(10, 10); // reset grid levelPar = generatePar(player.level); - generateCollectables(grid, 10); // how many collectables? - generateDamagingSpaces(grid, Math.floor(Math.random() * 7) + 1); // random number of damaging spaces, no more than 7 + generateCollectables(grid, Math.floor(Math.random() * 7) + 1); // how many collectables? + generateDamagingSpaces(grid, Math.floor(Math.random() * 22) + 1); // random number of damaging spaces, no more than 22 generateTargetBlock(grid); - generateTraps(grid, Math.floor(Math.random() * 3) + 1); // random number of traps, no more than 3 + generateTraps(grid, Math.floor(Math.random() * 10) + 1); // random number of traps, no more than 10 if (player.level === 0) { player.inventory = []; @@ -200,17 +200,22 @@ function checkForDamageOrTarget() { flashPlayer(); } } else if (cell && cell.type === 'trap') { - const item = player.inventory.pop(); - if (item) { - console.log(`Stepped on trap, removed ${item} from inventory`); + const itemIndex = Math.floor(Math.random() * player.inventory.length); + player.inventory.splice(itemIndex, 1); + console.log(`Stepped on a trap and lost an item`); + player.health -= Math.floor(Math.random() * 5) + 1; + console.log(`Stepped on a trap and took damage, health is now ${player.health}`); + if (player.health <= 0) { + alertGameOver(); + return; } else { - player.power -= Math.floor(Math.random() * 3) + 1; - console.log('Stepped on trap, drained some power'); + alert('Ouch! You hit a trap.'); + flashPlayer(); } } else if (x === targetPosition.x && y === targetPosition.y) { player.level += 1; console.log(`Reached target block, level is now ${player.level}`); - initializeGame(); // Generate new level and reset player position + initializeGame(); // generate a new level and reset player position to 0,0 } } |