awacke1 commited on
Commit
4cca48c
·
1 Parent(s): 9ad3072

Update index.html

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