-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
54 lines (47 loc) · 1.28 KB
/
index.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
const trainer = {
name: "Aaron",
pokemon: [],
catch(pokemon) {
this.pokemon.push(pokemon);
console.log(`${this.name} successfully caught ${pokemon.name}!`);
}
};
const opponent = {
name: "Villain",
pokemon: [],
catch(pokemon) {
this.pokemon.push(pokemon);
console.log(`${this.name} successfully caught ${pokemon.name}!`);
}
};
function Pokemon(name, hp) {
this.name = name;
this.hp = hp;
this.tackle = function (target) {
console.log(`${this.name} used Tackle on ${target.name}!`);
target.hp -= 10;
if (target.hp <= 0) {
console.log(`${target.name} fainted!`);
} else {
console.log(`${target.name}: ${target.hp + 10} hp >>> ${target.hp} hp`);
}
};
}
const pikachu = new Pokemon("Pikachu", 50);
const squirtle = new Pokemon("Squirtle", 60);
trainer.catch(pikachu);
opponent.catch(squirtle);
console.log();
console.log(`${opponent.name} blocks ${trainer.name}'s way!`);
console.log(trainer["name"] + " is forced to battle " + opponent.name + "!");
while (pikachu.hp > 0 && squirtle.hp > 0) {
pikachu.hp > 0 && pikachu.tackle(squirtle);
console.log();
squirtle.hp > 0 && squirtle.tackle(pikachu);
console.log();
}
if (pikachu.hp <= 0) {
console.log(`${trainer.name} wins!`);
} else {
console.log(`${opponent.name} wins!`);
}