Spaces:
Running
Running
File size: 6,597 Bytes
d9c0229 80693d2 4cca48c 80693d2 9ad3072 80693d2 4cca48c 80693d2 9ad3072 4cca48c 9ad3072 4cca48c 80693d2 9ad3072 80693d2 9ad3072 4cca48c 9ad3072 80693d2 4cca48c 80693d2 4cca48c 80693d2 4cca48c 80693d2 4cca48c 80693d2 4cca48c 80693d2 4cca48c 80693d2 4cca48c 9ad3072 4cca48c 9ad3072 4cca48c 9ad3072 4cca48c 9ad3072 80693d2 d9c0229 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 |
<!DOCTYPE html>
<html>
<head>
<title>Dungeons & Dragons</title>
<style>
body {
font-family: Arial, sans-serif;
}
#output, #characterSheet {
white-space: pre-wrap;
background-color: #f0f0f0;
padding: 10px;
margin-top: 10px;
border-radius: 5px;
}
</style>
</head>
<body>
<h1>Dungeons & Dragons: Adventure Awaits</h1>
<button id="createCharacter">Create Character</button>
<button id="startAdventure">Start Adventure</button>
<button id="attack">Attack</button>
<button id="castSpell">Cast Spell</button>
<button id="useItem">Use Item</button>
<div id="output"></div>
<div id="characterSheet"></div>
<script>
let character = {};
let inventory = ["health potion", "magic potion", "mysterious key"];
let monsters = [
{ name: "Goblin", health: 30, strength: 5, armor: 2, magicResistance: 1, treasure: 10 },
{ name: "Orc", health: 50, strength: 10, armor: 5, magicResistance: 2, treasure: 20 },
{ name: "Dragon", health: 100, strength: 20, armor: 10, magicResistance: 5, treasure: 50 }
];
let currentMonster = null;
document.getElementById("createCharacter").addEventListener("click", createCharacter);
document.getElementById("startAdventure").addEventListener("click", startAdventure);
document.getElementById("attack").addEventListener("click", attack);
document.getElementById("castSpell").addEventListener("click", castSpell);
document.getElementById("useItem").addEventListener("click", useItem);
function createCharacter() {
character = {
name: "Hero",
class: "Warrior",
level: 1,
health: 100,
magic: 50,
strength: 10,
intelligence: 5,
armor: 5,
magicResistance: 3,
gold: 0,
inventory: [...inventory]
};
updateCharacterSheet();
display(`Character Created: ${character.name}, the ${character.class}`);
}
function startAdventure() {
currentMonster = monsters[Math.floor(Math.random() * monsters.length)];
display(`You encounter a ${currentMonster.name} on your adventure.`);
}
function attack() {
if (!character.name) {
display("You need to create a character first!");
return;
}
if (!currentMonster) {
display("There is no monster to attack!");
return;
}
let damage = Math.floor(Math.random() * character.strength) - currentMonster.armor;
damage = damage < 0 ? 0 : damage;
currentMonster.health -= damage;
display(`You attack the ${currentMonster.name} dealing ${damage} damage.`);
if (currentMonster.health <= 0) {
character.gold += currentMonster.treasure;
display(`You defeated the ${currentMonster.name} and found ${currentMonster.treasure} gold!`);
currentMonster = null;
} else {
monsterAttack();
}
updateCharacterSheet();
}
function castSpell() {
if (!character.name) {
display("You need to create a character first!");
return;
}
if (!currentMonster) {
display("There is no monster to cast a spell on!");
return;
}
if (character.magic < 10) {
display("Not enough magic points to cast a spell.");
return;
}
const spells = [
{ name: "Fireball", damage: 20, cost: 10 },
{ name: "Healing Light", healing: 15, cost: 10 },
{ name: "Shadow Strike", damage: 15, cost: 10 }
];
const spell = spells[Math.floor(Math.random() * spells.length)];
character.magic -= spell.cost;
if (spell.damage) {
let damage = spell.damage - currentMonster.magicResistance;
damage = damage < 0 ? 0 : damage;
currentMonster.health -= damage;
display(`You cast ${spell.name} dealing ${damage} damage to the ${currentMonster.name}.`);
} else if (spell.healing) {
character.health += spell.healing;
display(`You cast ${spell.name} and heal yourself for ${spell.healing} health.`);
}
if (currentMonster.health <= 0) {
character.gold += currentMonster.treasure;
display(`You defeated the ${currentMonster.name} and found ${currentMonster.treasure} gold!`);
currentMonster = null;
} else {
monsterAttack();
}
updateCharacterSheet();
}
function useItem() {
if (!character.name) {
display("You need to create a character first!");
return;
}
if (character.inventory.length === 0) {
display("Your inventory is empty!");
return;
}
const item = character.inventory.pop();
switch (item) {
case "health potion":
character.health += 20;
display(`You use a ${item} and restore 20 health.`);
break;
case "magic potion":
character.magic += 20;
display(`You use a ${item} and restore 20 magic points.`);
break;
case "mysterious key":
// Implement effect of mysterious key
display(`You use a ${item}, but nothing happens.`);
break;
default:
display(`You use a ${item}.`);
break;
}
updateCharacterSheet();
}
function monsterAttack() {
let damage = Math.floor(Math.random() * currentMonster.strength) - character.armor;
damage = damage < 0 ? 0 : damage;
character.health -= damage;
display(`The ${currentMonster.name} attacks you dealing ${damage} damage.`);
}
function updateCharacterSheet() {
let sheet = `Name: ${character.name}\nClass: ${character.class}\nLevel: ${character.level}\nHealth: ${character.health}\nMagic: ${character.magic}\nStrength: ${character.strength}\nIntelligence: ${character.intelligence}\nArmor: ${character.armor}\nMagic Resistance: ${character.magicResistance}\nGold: ${character.gold}`;
document.getElementById("characterSheet").textContent = sheet;
}
function display(message) {
document.getElementById("output").textContent += message + "\n";
}
</script>
</body>
</html>
|