Spaces:
Running
Running
Update index.html
Browse files- index.html +27 -3
index.html
CHANGED
@@ -21,15 +21,23 @@
|
|
21 |
<button id="startAdventure">Start Adventure</button>
|
22 |
<button id="attack">Attack</button>
|
23 |
<button id="castSpell">Cast Spell</button>
|
|
|
24 |
<div id="output"></div>
|
25 |
|
26 |
<script>
|
27 |
let character = {};
|
|
|
|
|
|
|
|
|
|
|
|
|
28 |
|
29 |
document.getElementById("createCharacter").addEventListener("click", createCharacter);
|
30 |
document.getElementById("startAdventure").addEventListener("click", startAdventure);
|
31 |
document.getElementById("attack").addEventListener("click", attack);
|
32 |
document.getElementById("castSpell").addEventListener("click", castSpell);
|
|
|
33 |
|
34 |
function createCharacter() {
|
35 |
character = {
|
@@ -39,13 +47,14 @@
|
|
39 |
health: 100,
|
40 |
magic: 50,
|
41 |
strength: 10,
|
42 |
-
intelligence: 5
|
|
|
43 |
};
|
44 |
display(`Character Created: ${character.name}, the ${character.class}`);
|
45 |
}
|
46 |
|
47 |
function startAdventure() {
|
48 |
-
const encounters = ["a wild beast", "a mysterious traveler", "a hidden treasure"];
|
49 |
const encounter = encounters[Math.floor(Math.random() * encounters.length)];
|
50 |
display(`You encounter ${encounter} on your adventure.`);
|
51 |
}
|
@@ -66,12 +75,27 @@
|
|
66 |
return;
|
67 |
}
|
68 |
|
69 |
-
const spells = ["Fireball", "Healing Light", "Shadow Strike"];
|
70 |
const spell = spells[Math.floor(Math.random() * spells.length)];
|
71 |
display(`You cast ${spell}! It uses 10 magic points.`);
|
72 |
character.magic -= 10;
|
73 |
}
|
74 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
75 |
function display(message) {
|
76 |
document.getElementById("output").textContent += message + "\n";
|
77 |
}
|
|
|
21 |
<button id="startAdventure">Start Adventure</button>
|
22 |
<button id="attack">Attack</button>
|
23 |
<button id="castSpell">Cast Spell</button>
|
24 |
+
<button id="useItem">Use Item</button>
|
25 |
<div id="output"></div>
|
26 |
|
27 |
<script>
|
28 |
let character = {};
|
29 |
+
let inventory = ["health potion", "magic potion", "mysterious key"];
|
30 |
+
let monsters = [
|
31 |
+
{ name: "Goblin", health: 30, strength: 5 },
|
32 |
+
{ name: "Orc", health: 50, strength: 10 },
|
33 |
+
{ name: "Dragon", health: 100, strength: 20 }
|
34 |
+
];
|
35 |
|
36 |
document.getElementById("createCharacter").addEventListener("click", createCharacter);
|
37 |
document.getElementById("startAdventure").addEventListener("click", startAdventure);
|
38 |
document.getElementById("attack").addEventListener("click", attack);
|
39 |
document.getElementById("castSpell").addEventListener("click", castSpell);
|
40 |
+
document.getElementById("useItem").addEventListener("click", useItem);
|
41 |
|
42 |
function createCharacter() {
|
43 |
character = {
|
|
|
47 |
health: 100,
|
48 |
magic: 50,
|
49 |
strength: 10,
|
50 |
+
intelligence: 5,
|
51 |
+
inventory: [...inventory]
|
52 |
};
|
53 |
display(`Character Created: ${character.name}, the ${character.class}`);
|
54 |
}
|
55 |
|
56 |
function startAdventure() {
|
57 |
+
const encounters = ["a wild beast", "a mysterious traveler", "a hidden treasure", ...monsters.map(m => `a ${m.name}`)];
|
58 |
const encounter = encounters[Math.floor(Math.random() * encounters.length)];
|
59 |
display(`You encounter ${encounter} on your adventure.`);
|
60 |
}
|
|
|
75 |
return;
|
76 |
}
|
77 |
|
78 |
+
const spells = ["Fireball", "Healing Light", "Shadow Strike", "Ice Bolt", "Thunder Wave"];
|
79 |
const spell = spells[Math.floor(Math.random() * spells.length)];
|
80 |
display(`You cast ${spell}! It uses 10 magic points.`);
|
81 |
character.magic -= 10;
|
82 |
}
|
83 |
|
84 |
+
function useItem() {
|
85 |
+
if (!character.name) {
|
86 |
+
display("You need to create a character first!");
|
87 |
+
return;
|
88 |
+
}
|
89 |
+
|
90 |
+
if (character.inventory.length === 0) {
|
91 |
+
display("Your inventory is empty!");
|
92 |
+
return;
|
93 |
+
}
|
94 |
+
|
95 |
+
const item = character.inventory.pop();
|
96 |
+
display(`You use a ${item}.`);
|
97 |
+
}
|
98 |
+
|
99 |
function display(message) {
|
100 |
document.getElementById("output").textContent += message + "\n";
|
101 |
}
|