Sure, here's a basic implementation of finding weapons in structures. Each structure has a chance to contain a weapon:
<!DOCTYPE html>
<html>
<head>
<title>Simple Adventure Game</title>
<script>
function startGame() {
var creatures = ["Dragon", "Goblin", "Beholder"];
var structures = ["Castle", "Dungeon", "Forest"];
var weapons = ["Sword", "Axe", "Bow", "Spear", "Magic Wand"];
var playerHealth = 100;
var creatureHealth = 100;
var inventory = {
"Health Potion": 5,
"Weapon": "None"
};
while(playerHealth > 0) {
var creature = creatures[Math.floor(Math.random()*creatures.length)];
var structure = structures[Math.floor(Math.random()*structures.length)];
var damage = Math.floor(Math.random()*20);
alert("You are currently in a " + structure + ".");
// Chance to find a weapon in a structure
if(Math.random() < 0.5) {
var weapon = weapons[Math.floor(Math.random()*weapons.length)];
inventory["Weapon"] = weapon;
alert("You found a " + weapon + " in the " + structure + "!");
}
if(confirm("A wild " + creature + " appeared! It deals " + damage + " damage. Do you want to fight back?")) {
creatureHealth -= damage;
if(creatureHealth <= 0) {
alert("You defeated the " + creature + "!");
creatureHealth = 100;
} else {
alert("The " + creature + "'s health: " + creatureHealth + "/100");
}
} else {
playerHealth -= damage;
if(inventory["Health Potion"] > 0 && confirm("Your health: " + playerHealth + "/100. Do you want to use a Health Potion?")) {
playerHealth += 20; // Each potion restores 20 health
inventory["Health Potion"]--;
}
alert("Your health: " + playerHealth + "/100, " + inventory["Health Potion"] + " Health Potions, and your weapon is a " + inventory["Weapon"] + ".");
}
}
alert("Game Over!");
}
</script>
</head>
<body>
<button onclick="startGame()">Start Game</button>
</body>
</html>
In this version, each structure the player visits has a 50% chance to contain a weapon. If a weapon is found, it replaces the player's current weapon. The player is informed of their current weapon along with their health and potion count.