Repository navigation
Expand file tree
/
Copy pathcharacters.js
More file actions
141 lines (126 loc) · 3.59 KB
/
Copy pathcharacters.js
File metadata and controls
141 lines (126 loc) · 3.59 KB
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
class GameObject {
constructor(options) {
this.createdAt = options.createdAt;
this.dimensions = options.dimensions;
}
destroy() {
return `${this.name} was removed from the game.`;
}
}
class CharacterStats extends GameObject {
constructor(characterStatsOptions) {
super(characterStatsOptions);
this.hp = characterStatsOptions.hp;
this.maxHP = characterStatsOptions.maxHP;
this.name = characterStatsOptions.name;
}
takeDamage() {
return `${this.name} took damage.`;
}
}
class Humanoid extends CharacterStats {
constructor(humanoidOptions) {
super(humanoidOptions);
this.faction = humanoidOptions.faction;
this.weapons = humanoidOptions.weapons;
this.language = humanoidOptions.language;
}
greet() {
return `${this.name} offers a greeting in ${this.language}.`;
}
activateGameOver() {
gameOverScreen.classList.add('game-over-active');
}
decrementHpBar(opponent, opponentHPBar) {
opponentHPBar.style.width =
((opponent.hp / opponent.maxHP) * 100).toString() + '%';
}
displayMessage(opponent, attackName, adj) {
messages.textContent = `${
this.name
} ${adj} ${attackName}!!! ${opponent.takeDamage()}... HP: ${opponent.hp}`;
messageFlicker();
}
destroyMessage(opponent) {
messages.textContent = `${opponent.destroy()}... Boom, roasted.`;
}
}
// HERO
class Hero extends Humanoid {
constructor(heroAttributes) {
super(heroAttributes);
}
// Base attack
castSpell(villain) {
// remove 1 hp
villain.hp -= 1;
// remove hp from hp bar
this.decrementHpBar(villain, villainHPBar);
if (villain.hp > 1) {
// Display message (opponent, attack, adj)
this.displayMessage(villain, 'Paper Cut', 'casted');
} else if (villain.hp === 1) {
// Display destroy message
this.destroyMessage(villain);
// show game over screen if opponent health is at 0
} else if (villain.hp === 0) {
this.activateGameOver();
}
}
// Super attack
superAttack(villain) {
// remove 3 hp
villain.hp -= 3;
// remove hp from hp bar
this.decrementHpBar(villain, villainHPBar);
if (villain.hp >= 3) {
// Display message (opponent, attack, adj)
this.displayMessage(villain, 'a Party', 'Threw');
} else if (villain.hp === 0) {
// Display destroy message
this.destroyMessage(villain);
// show game over screen
this.activateGameOver();
} else {
messages.textContent = 'Use normal attack... super is too much';
}
}
}
class Villain extends Humanoid {
constructor(villainAttributes) {
super(villainAttributes);
}
baseAttack(hero) {
// remove 1 hp
hero.hp -= 1;
// remove hp from hp bar
this.decrementHpBar(hero, heroHPBar);
if (hero.hp > 1) {
// Display message (opponent, attack, adj)
this.displayMessage(hero, 'Paper Work', 'Endless');
} else if (hero.hp === 1) {
// Display destroy message
this.destroyMessage(hero);
} else if (hero.hp === 0) {
// show game over screen if opponent health is at 0
this.activateGameOver();
}
}
superAttack(hero) {
// remove 3 hp
hero.hp -= 3;
// remove hp from hp bar
this.decrementHpBar(hero, heroHPBar);
if (hero.hp >= 3) {
// Display message (opponent, attack, adj)
this.displayMessage(hero, 'Beurocratic Shade', 'Threw');
} else if (hero.hp === 0) {
// Display destroy message
this.destroyMessage(hero);
// show game over screen
this.activateGameOver();
} else {
messages.textContent = 'Use normal attack... super is too much';
}
}
}