From 6c32c3df33b8edead0d34415e8fb9d8dbcf430dc Mon Sep 17 00:00:00 2001 From: Quentin <59255702+quentin-rey@users.noreply.github.com> Date: Fri, 15 Mar 2024 17:04:29 +0100 Subject: [PATCH] Update script.js Camel Case names, don't show negative health but 0 instead, dislay health red if 0 --- script.js | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/script.js b/script.js index 5343ae8..feb52f2 100644 --- a/script.js +++ b/script.js @@ -4,7 +4,7 @@ let gold = 50; let currentWeapon = 0; let fighting; let monsterHealth; -let inventory = ["stick"]; +let inventory = ["Stick"]; const button1 = document.querySelector('#button1'); const button2 = document.querySelector("#button2"); @@ -17,24 +17,24 @@ const monsterStats = document.querySelector("#monsterStats"); const monsterName = document.querySelector("#monsterName"); const monsterHealthText = document.querySelector("#monsterHealth"); const weapons = [ - { name: 'stick', power: 5 }, - { name: 'dagger', power: 30 }, - { name: 'claw hammer', power: 50 }, - { name: 'sword', power: 100 } + { name: 'Stick', power: 5 }, + { name: 'Dagger', power: 30 }, + { name: 'Claw hammer', power: 50 }, + { name: 'Sword', power: 100 } ]; const monsters = [ { - name: "slime", + name: "Slime", level: 2, health: 15 }, { - name: "fanged beast", + name: "Fanged beast", level: 8, health: 60 }, { - name: "dragon", + name: "Dragon", level: 20, health: 300 } @@ -42,19 +42,19 @@ const monsters = [ const locations = [ { name: "town square", - "button text": ["Go to store", "Go to cave", "Fight dragon"], + "button text": ["Go to Store", "Go to Cave", "Fight Dragon"], "button functions": [goStore, goCave, fightDragon], text: "You are in the town square. You see a sign that says \"Store\"." }, { name: "store", - "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to town square"], + "button text": ["Buy 10 health (10 gold)", "Buy weapon (30 gold)", "Go to Town Square"], "button functions": [buyHealth, buyWeapon, goTown], text: "You enter the store." }, { name: "cave", - "button text": ["Fight slime", "Fight fanged beast", "Go to town square"], + "button text": ["Fight Slime", "Fight Fanged Beast", "Go to Town Square"], "button functions": [fightSlime, fightBeast, goTown], text: "You enter the cave. You see some monsters." }, @@ -66,7 +66,7 @@ const locations = [ }, { name: "kill monster", - "button text": ["Go to town square", "Go to town square", "Go to town square"], + "button text": ["Go to Town Square", "Go to Town Square", "Go to Town Square"], "button functions": [goTown, goTown, easterEgg], text: 'The monster screams "Arg!" as it dies. You gain experience points and find gold.' }, @@ -84,7 +84,7 @@ const locations = [ }, { name: "easter egg", - "button text": ["2", "8", "Go to town square?"], + "button text": ["2", "8", "Go to Town Square?"], "button functions": [pickTwo, pickEight, goTown], text: "You find a secret game. Pick a number above. Ten numbers will be randomly chosen between 0 and 10. If the number you choose matches one of the random numbers, you win!" } @@ -233,6 +233,9 @@ function defeatMonster() { } function lose() { + healthText.style.color = "red"; + health = 0; + healthText.innerText = health; update(locations[5]); } @@ -241,6 +244,7 @@ function winGame() { } function restart() { + healthText.style.color = "inherit"; xp = 0; health = 100; gold = 50;