kstoyanov

01. Heroes

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