Skip to content

Commit 297d317

Browse files
committed
#29 - Javascript
1 parent 0dd2f86 commit 297d317

File tree

1 file changed

+58
-0
lines changed

1 file changed

+58
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
// Incorrecto
2+
3+
class Entity {
4+
constructor(name, attackDamage, health) {
5+
this.name = name
6+
this.attackDamage = attackDamage
7+
this.health = health
8+
}
9+
move() {
10+
console.log(`${this.name} moved`)
11+
}
12+
attack(targetEntity) {
13+
console.log(`${this.name} attacked ${targetEntity.name} for ${this.attackDamage} damage`)
14+
targetEntity.takeDamage(this.attackDamage)
15+
}
16+
takeDamage(amount) {
17+
this.health -= amount
18+
console.log(`${this.name} has ${this.health} remaining`)
19+
}
20+
}
21+
22+
class Character extends Entity {
23+
24+
}
25+
26+
class Wall extends Entity {
27+
constructor(name, health) {
28+
super(name, 0, health)
29+
}
30+
move() {
31+
return null
32+
}
33+
attack() {
34+
return null
35+
}
36+
}
37+
38+
class Turret extends Entity {
39+
constructor(name, attackDamage) {
40+
super(name, attackDamage, -1)
41+
}
42+
move() {
43+
return null
44+
}
45+
takeDamage() {
46+
return null
47+
}
48+
}
49+
50+
const turret = new Turret('Turret', 5)
51+
const character = new Character('Character', 3, 100)
52+
const wall = new Wall('Wall', 100)
53+
54+
turret.attack(character)
55+
character.move()
56+
character.attack(wall)
57+
58+
//Correcto

0 commit comments

Comments
 (0)