11// Incorrecto
22
3- class Entity {
3+ /* class Entity {
44 constructor(name, attackDamage, health) {
55 this.name = name
66 this.attackDamage = attackDamage
@@ -53,6 +53,70 @@ const wall = new Wall('Wall', 100)
5353
5454turret.attack(character)
5555character.move()
56- character . attack ( wall )
56+ character.attack(wall) */
57+
58+ //Correcto
59+
60+ class Entity {
61+ constructor ( name ) {
62+ this . name = name
63+ }
64+ }
65+
66+ const mover = {
67+ move ( ) {
68+ console . log ( `${ this . name } moved` )
69+ }
70+ }
71+
72+ const attacker = {
73+ attack ( targetEntity ) {
74+ console . log ( `${ this . name } attacked ${ targetEntity . name } for ${ this . attackDamage } damage` )
75+ targetEntity . takeDamage ( this . attackDamage )
76+ }
77+ }
78+
79+ const hasHealth = {
80+ takeDamage ( amount ) {
81+ this . health -= amount
82+ console . log ( `${ this . name } has ${ this . health } remaining` )
83+ }
84+ }
85+
86+ class Character extends Entity {
87+ constructor ( name , attackDamage , health ) {
88+ super ( name )
89+ this . attackDamage = attackDamage
90+ this . health = health
91+ }
92+ }
93+
94+ Object . assign ( Character . prototype , mover )
95+ Object . assign ( Character . prototype , attacker )
96+ Object . assign ( Character . prototype , hasHealth )
97+
98+ class Wall extends Entity {
99+ constructor ( name , health ) {
100+ super ( name )
101+ this . health = health
102+ }
103+ }
104+
105+ Object . assign ( Wall . prototype , hasHealth )
57106
58- //Correcto
107+ class Turret extends Entity {
108+ constructor ( name , attackDamage ) {
109+ super ( name )
110+ this . attackDamage = attackDamage
111+ }
112+ }
113+
114+ Object . assign ( Turret . prototype , attacker )
115+
116+ const turret = new Turret ( 'Turret' , 5 )
117+ const character = new Character ( 'Character' , 3 , 100 )
118+ const wall = new Wall ( 'Wall' , 100 )
119+
120+ turret . attack ( character )
121+ character . move ( )
122+ character . attack ( wall )
0 commit comments