-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMonster.js
More file actions
94 lines (86 loc) · 2.54 KB
/
Copy pathMonster.js
File metadata and controls
94 lines (86 loc) · 2.54 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
//create a function that creates a random monster from the json file
function createRandomMonster(){
let randomMonster = monsterKeys[Math.floor(Math.random() * monsterKeys.length)];
return monsterList[randomMonster];
}
class Monster{
constructor(name, hp, attackDamage, armor){ // location is a Location object
this.name = name;
this.hp = hp;
this.attackDamage = attackDamage;
this.armor = armor;
}
attack(target){ // returns the attack damage
target.takeDamage(this.getAttackDamage());
}
takeDamage(damage){ // takes damage and reduces health - armor
if(damage > this.getArmor()){
this.hp -= (damage-this.getArmor());
console.log(this.name + " took " + (damage-this.getArmor()) + " damage!");
}
else{
this.hp -= (damage-1);
console.log(this.name + " took no damage!");
}
console.log(this.name + " has " + this.hp + " health left!")
}
isAlive(){ // returns true if health is greater than 0
return this.hp > 0;
}
//setter and getter
setName(name){
this.name = name;
}
getName(){
return this.name;
}
setHp(hp){
this.hp = hp;
}
getHp(){
return this.hp;
}
setAttackDamage(attackDamage){
this.attackDamage = attackDamage;
}
getAttackDamage(){
return this.attackDamage;
}
setArmor(armor){
this.armor = armor;
}
getArmor(){
return this.armor;
}
//set x and set y location
setX(x){
this.location.x = x;
}
getX(){
return this.location.x;
}
setY(y){
this.location.y = y;
}
getY(){
return this.location.y;
}
}
const monsterList = {
"Mike": new Monster("Mike", 42, 7, 12),
"Pikachu": new Monster("Pikachu", 85, 25, 16),
"Squirtle": new Monster("Squirtle", 60, 12, 2),
"Charmander": new Monster("Charmander", 60, 4, 2),
"Bulbasaur": new Monster("Bulbasaur", 60, 6, 3),
"Eevee": new Monster("Eevee", 60, 7, 1 ),
"Snorlax": new Monster("Snorlax", 60, 5, 0),
"Mew": new Monster("Mew", 60, 7, 2),
"Mewtwo": new Monster("Mewtwo", 60, 10, 5),
"Gengar": new Monster("Gengar", 60, 10, 3),
"Gyarados": new Monster("Gyarados", 60, 15, 3),
"Dragonite": new Monster("Dragonite", 60, 15, 4),
"Moltres": new Monster("Moltres", 60, 12, 3),
"Zapdos": new Monster("Zapdos", 60, 13, 2),
"Articuno": new Monster("Articuno", 60, 8, 4),
}
const monsterKeys = Object.keys(monsterList);