Advertisement
viligen

HeroesClasses

May 28th, 2022
1,074
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function solve() {
  2.    
  3.     class Fighter {
  4.         constructor(name) {
  5.             this.name = name;
  6.             this.health = 100;
  7.             this.stamina = 100;
  8.         }
  9.         fight() {
  10.             this.stamina--;
  11.             console.log(`${this.name} slashes at the foe!`);
  12.         }
  13.     }
  14.     class Mage {
  15.         constructor(name) {
  16.             this.name = name;
  17.             this.health = 100;
  18.             this.mana = 100;
  19.         }
  20.         cast(spell) {
  21.             this.mana--;
  22.             console.log(`${this.name} cast ${spell}`);
  23.         }
  24.     }
  25.     const Obj = {
  26.         mage: (name)=> new Mage(name),
  27.         fighter: (name) => new Fighter(name),
  28.     };
  29.  
  30.     return Obj;
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement