-
Notifications
You must be signed in to change notification settings - Fork 0
/
vendor.js
44 lines (36 loc) · 1.28 KB
/
vendor.js
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
const monsterHealthBar = document.getElementById('monster-health');
const playerHealthBar = document.getElementById('player-health');
const bonusLifeEl = document.getElementById('bonus-life');
const attackBtn = document.getElementById('attack-btn');
const strongAttackBtn = document.getElementById('strong-attack-btn');
const healBtn = document.getElementById('heal-btn');
const logBtn = document.getElementById('log-btn');
function adjustHealthBars(maxLife) {
monsterHealthBar.max = maxLife;
monsterHealthBar.value = maxLife;
playerHealthBar.max = maxLife;
playerHealthBar.value = maxLife;
}
function dealMonsterDamage(damage) {
const dealtDamage = Math.random() * damage;
monsterHealthBar.value = +monsterHealthBar.value - dealtDamage;
return dealtDamage;
}
function dealPlayerDamage(damage) {
const dealtDamage = Math.random() * damage;
playerHealthBar.value = +playerHealthBar.value - dealtDamage;
return dealtDamage;
}
function increasePlayerHealth(healValue) {
playerHealthBar.value = +playerHealthBar.value + healValue;
}
function resetGame(value) {
playerHealthBar.value = value;
monsterHealthBar.value = value;
}
function removeBonusLife() {
bonusLifeEl.parentNode.removeChild(bonusLifeEl);
}
function setPlayerHealth(health) {
playerHealthBar.value = health;
}