-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
078d2f9
commit b10c967
Showing
3 changed files
with
128 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
class Entity { | ||
constructor(name) { | ||
this.name = name; | ||
} | ||
} | ||
|
||
const mover = { | ||
move() { | ||
console.log(`${this.name} moved`); | ||
}, | ||
}; | ||
|
||
const attacker = { | ||
attack(targetEntity) { | ||
console.log( | ||
`${this.name} attacked ${targetEntity.name} for ${this.attackDamage} damage` | ||
); | ||
targetEntity.takeDamage(this.attackDamage); | ||
}, | ||
}; | ||
|
||
const hasHealth = { | ||
takeDamage(amount) { | ||
this.health -= amount; | ||
console.log(`${this.name} has ${this.health} health remaining`); | ||
}, | ||
}; | ||
|
||
class Character extends Entity { | ||
constructor(name, attackDamage, health) { | ||
super(name); | ||
this.attackDamage = attackDamage; | ||
this.health = health; | ||
} | ||
} | ||
|
||
Object.assign(Character.prototype, mover); | ||
Object.assign(Character.prototype, attacker); | ||
Object.assign(Character.prototype, hasHealth); | ||
|
||
class Wall extends Entity { | ||
constructor(name, health) { | ||
super(name); | ||
this.health = health; | ||
} | ||
} | ||
|
||
Object.assign(Wall.prototype, hasHealth); | ||
|
||
class Turret extends Entity { | ||
constructor(name, attackDamage) { | ||
super(name); | ||
this.attackDamage = attackDamage; | ||
} | ||
} | ||
|
||
Object.assign(Turret.prototype, attacker); | ||
|
||
const turret = new Turret("Turret", 5); | ||
const character = new Character("Character", 3, 100); | ||
const wall = new Wall("Wall", 200); | ||
|
||
turret.attack(character); | ||
character.move(); | ||
character.attack(wall); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
class Entity { | ||
constructor(name, attackDamage, health) { | ||
this.name = name; | ||
this.attackDamage = attackDamage; | ||
this.health = health; | ||
} | ||
|
||
move() { | ||
console.log(`${this.name} moved`); | ||
} | ||
|
||
attack(targetEntity) { | ||
console.log( | ||
`${this.name} attacked ${targetEntity.name} for ${this.attackDamage} damage` | ||
); | ||
targetEntity.takeDamage(this.attackDamage); | ||
} | ||
|
||
takeDamage(amount) { | ||
this.health -= amount; | ||
console.log(`${this.name} has ${this.health} health remaining`); | ||
} | ||
} | ||
|
||
class Character extends Entity {} | ||
|
||
class Wall extends Entity { | ||
constructor(name, health) { | ||
super(name, 0, health); | ||
} | ||
|
||
move() { | ||
return null; | ||
} | ||
|
||
attack() { | ||
return null; | ||
} | ||
} | ||
|
||
class Turret extends Entity { | ||
constructor(name, attackDamage) { | ||
super(name, attackDamage, -1); | ||
} | ||
|
||
move() { | ||
return null; | ||
} | ||
|
||
takeDamage() { | ||
return null; | ||
} | ||
} | ||
|
||
const turret = new Turret("Turret", 5); | ||
const character = new Character("Character", 3, 100); | ||
const wall = new Wall("Wall", 200); | ||
|
||
turret.attack(character); | ||
character.move(); | ||
character.attack(wall); |