-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
60 lines (57 loc) · 1.74 KB
/
script.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
60
class Card{
constructor(name, cost){
this.name = name;
this.cost = cost;
}
}
class Unit extends Card{
constructor(name, cost, power, res){
super(name, cost);
this.power = power;
this.res = res;
}
attack(target){
if(target instanceof Unit){
target.res -= this.power;
console.log(`${this.name} attacked ${target.name} and dealt ${this.power} damage!`);
}
else {
throw new Error("Target must be a unit!");
}
}
showStats(){
console.log(`Name: ${this.name} || Power: ${this.power} || Resilience: ${this.res}`)
}
}
class Effect extends Card{
constructor(name, cost, stat, magnitude){
super(name, cost);
this.stat = stat;
this.magnitude = magnitude;
}
play(target){
if(target instanceof Unit){
console.log(`${this.name} was cast on ${target.name}!`);
if(this.stat === "res"){
target.res += this.magnitude;
}
else {
target.power += this.magnitude;
}
}
else {
throw new Error("Target must be a unit!");
}
}
}
const redBeltNinja = new Unit("Red Belt Ninja", 3, 3, 4);
const hardAlgorithm = new Effect("Hard Algorithm", 2, "res", 3);
hardAlgorithm.play(redBeltNinja);
const blackBeltNinja = new Unit("Black Belt Ninja", 4, 5, 4);
const unhandledPromiseRejection = new Effect("Unhandled Promise Rejection", 1, "res", -2);
unhandledPromiseRejection.play(redBeltNinja);
const pairProgramming = new Effect("Pair Programming", 3, "power", 2);
pairProgramming.play(redBeltNinja);
redBeltNinja.attack(blackBeltNinja);
redBeltNinja.showStats();
blackBeltNinja.showStats();