From f0aeda1c7f11d0b3de7acecb52a068390fbf7347 Mon Sep 17 00:00:00 2001
From: elioat
Date: Sun, 7 Jul 2024 14:16:34 -0400
Subject: *
---
js/puzzle-dungeon/game.js | 17 ++++++++++++++++-
js/puzzle-dungeon/index.html | 9 ++++++++-
2 files changed, 24 insertions(+), 2 deletions(-)
(limited to 'js')
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 @@
(0, 0)
+ Par:
Inventory: []