Advertisement
bebo231312312321

Untitled

Apr 1st, 2023
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function heroesofCodeAndLogic(input) {
  2.     let hero = {}
  3.     let heroLine = input.splice(0, input.shift()).map(line => {
  4.         let [name, hp, mp] = line.split(" ").map(x => isNaN(x) ? x : Number(x))
  5.         if (!hero.hasOwnProperty(name)) hero[name] = { hp, mp }
  6.     })
  7.     let comandLine = input.splice(0, input.indexOf("End")).forEach(element => {
  8.         let [comand, a, b, c] = element.split(" - ").map(x => isNaN(x) ? x : Number(x))
  9.     switch(comand){
  10.         case "Heal" : heal(a,b); break;
  11.         case "Recharge" : recharge(a,b); break;
  12.         case "TakeDamage" : damage(a,b,c); break;
  13.         case "CastSpell" :spell(a,b,c); break;
  14.     }
  15.     });
  16.     function heal(a,b){let reffil = Math.min(100 - hero[a].hp, b)
  17.     hero[a].hp+=reffil
  18.     console.log(`${a} healed for ${reffil} HP!`)
  19.     }
  20.     function recharge(a,b){let reffil = Math.min(200 - hero[a].mp, b)
  21.         hero[a].mp+=reffil
  22.         console.log(`${a} recharged for ${reffil} MP!`)}
  23.     function damage(a,b,c){hero[a].hp -= b
  24.         if(hero[a].hp >0){
  25.             console.log(`${a} was hit for ${b} HP by ${c} and now has ${ hero[a].hp} HP left!`)
  26.         }else{
  27.             console.log(`${a} has been killed by ${c}!`)
  28.             delete hero[a]
  29.         }
  30.     }
  31.     function spell(a,b,c){if(hero[a].mp >= b){
  32.         hero[a].mp-=b
  33.         console.log(`${a} has successfully cast ${c} and now has ${hero[a].mp} MP!`)
  34.     }else{ console.log(`${a} does not have enough MP to cast ${c}!`)}};
  35. for (let key in hero){console.log(`${key}\n  HP: ${hero[key].hp}\n  MP: ${hero[key].mp}`)}
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement