diff options
Diffstat (limited to 'js')
-rw-r--r-- | js/puzzle-dungeon/game.js | 17 | ||||
-rw-r--r-- | js/puzzle-dungeon/index.html | 9 |
2 files changed, 24 insertions, 2 deletions
diff --git a/js/puzzle-dungeon/game.js b/js/puzzle-dungeon/game.js index a41d90c..449f03f 100644 --- a/js/puzzle-dungeon/game.js +++ b/js/puzzle-dungeon/game.js @@ -6,6 +6,7 @@ export let player = { power: 10, level: 0, steps: 0, + par: 0, flashing: false }; let targetPosition = { x: 0, y: 0 }; @@ -22,6 +23,18 @@ function createGrid(rows, cols) { return grid; } +export let levelPar; +function generatePar(level) { + let par; + if (level < 6) { + par = 7; + } else { + par = Math.floor(Math.random() * 7) + 1; + } + document.getElementById('par').textContent = `Par: ${player.par} of ${par}`; + return par; +} + function generateCollectables(grid, numCollectables) { const collectableTypes = ['potion', 'shield', 'battery']; const collectableColors = { @@ -103,6 +116,7 @@ export function drawGrid(grid) { export function initializeGame() { grid = createGrid(10, 10); // Reset grid + levelPar = generatePar(player.level); generateCollectables(grid, 10); // Adjust the number as needed generateDamagingSpaces(grid, Math.floor(Math.random() * 7) + 1); // Random number of damaging spaces, no more than 7 generateTargetBlock(grid); // Add target block @@ -169,7 +183,8 @@ function checkForDamageOrTarget() { } export function alertGameOver() { - alert('You have lost the game!'); + const gameStatsString = `Level: ${player.level}, Health: ${player.health}, Power: ${player.power}`; + alert('You have lost the game!' + '\n' + gameStatsString); initializeGame(); } diff --git a/js/puzzle-dungeon/index.html b/js/puzzle-dungeon/index.html index ee6bff4..2caa203 100644 --- a/js/puzzle-dungeon/index.html +++ b/js/puzzle-dungeon/index.html @@ -41,6 +41,7 @@ <span id="playerPosition">(0, 0)</span> </p> <canvas id="gameCanvas"></canvas> + <p id="par">Par:</p> <p id="playerInventory">Inventory: []</p> <form id="commandForm"> <textarea id="commands" rows="10" cols="30"></textarea><br> @@ -48,11 +49,17 @@ </form> <script type="module"> import { parseCommands } from './parser.js'; - import { initializeGame, resizeCanvas } from './game.js'; + import { initializeGame, resizeCanvas, player, alertGameOver, levelPar } from './game.js'; document.getElementById('commandForm').addEventListener('submit', function(event) { event.preventDefault(); + player.par = player.par + 1; + console.log(`Player command count, ${player.par}, ${levelPar}`); const commands = document.getElementById('commands').value; + if (player.par === levelPar) { + alertGameOver(); + return; + } parseCommands(commands); }); |