-
Notifications
You must be signed in to change notification settings - Fork 6.5k
/
Copy pathviking.js
executable file
·59 lines (55 loc) · 1.2 KB
/
viking.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
// Soldier
class Soldier {
constructor(health,strength){
this.health=health;
this.strength=strength;
}
attack(){
return this.strength;
}
receiveDamage(damage){
this.health-=damage;
}
}
// Viking
class Viking extends Soldier {
constructor(name,health,strength){
super(name,health,strength)
this.name=name;
this.health=health;
this.strength=strength;
}
attack(){
return this.strength;
}
receiveDamage(damage){
this.health-=damage;
if(this.health > 0){
return `${this.name} has received ${damage} points of damage`;
}else{
return `${this.name} has died in act of combat`;
}
}
battleCry(){
return "Odin Owns You All!"
}
}
// Saxon
class Saxon extends Soldier{
constructor(health,strength){
super(health,strength)
}
attack(){
return this.strength;
}
receiveDamage(damage){
this.health-=damage;
if(this.health > 0){
return `A Saxon has received ${damage} points of damage`;
}else{
return `A Saxon has died in combat`
}
}
}
// War
class War {}