Advertisement
bebo231312312321

Untitled

Mar 23rd, 2023
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function heroesofCodeandLogic (input){
  2. let heroNum = Number(input.shift())
  3. let heroes = input.splice(0,heroNum)
  4. let commandLine = input.splice(0, input.indexOf("End"))
  5. let herosData= {}
  6. heroes.forEach(element => {
  7.     let [hero, hp, mp] = element.split(" ")
  8.  hp=Number(hp)
  9.  mp = Number(mp)
  10.     if(!herosData.hasOwnProperty(hero)){
  11.         herosData[hero] = {hp, mp}
  12.     }
  13. });
  14. commandLine.forEach(line=>{
  15.     let commandsData = line.split(" - ")
  16.     command = commandsData[0]
  17.    // console.log(commandsData)
  18.     switch(command){
  19.  
  20.         case "Heal":
  21.             let [com,nameHero, hpHero] = commandsData
  22.             hpHero = Number(hpHero)
  23.           let  refill = Math.min((100 - herosData[nameHero]["hp"]), hpHero)
  24.             herosData[nameHero]["hp"]+=refill
  25.             console.log(`${nameHero} healed for ${refill} HP!`)
  26.             break
  27.         case "Recharge":
  28.            let  [comand,name, mpHero] = commandsData
  29.           mpHero = Number(mpHero)
  30.             let recharge = Math.min((200 - herosData[name]["mp"]), mpHero)
  31.             herosData[name]["mp"]+=recharge
  32.             console.log(`${name} recharged for ${recharge} MP!`)
  33.             break;
  34.         case "TakeDamage":
  35.         let [ commands, heroName, health,attaker] = commandsData
  36.         herosData[heroName]["hp"]-= health
  37.             if(herosData[heroName]["hp"]<=0){
  38.                 console.log(`${heroName} has been killed by ${attaker}!`)
  39.                 delete herosData[heroName]
  40.             }else{
  41.                 console.log(`${heroName} was hit for ${health} HP by ${attaker} and now has ${herosData[heroName]["hp"]} HP left!`)
  42.             }
  43.             break;
  44.         case "CastSpell":
  45.             let [comL, heroes, mana,spells] = commandsData
  46.             if(herosData[heroes]["mp"]>= mana){
  47.                 herosData[heroes]["mp"]-=mana
  48.                 console.log(`${heroes} has successfully cast ${spells} and now has ${herosData[heroes]["mp"]} MP!`)
  49.             }else{
  50.                 console.log(`${heroes} does not have enough MP to cast ${spells}!`)
  51.             }
  52.             break;
  53.     }
  54. })
  55. for(let el in herosData){
  56.    console.log(`${el}`)
  57.  console.log(`HP: ${herosData[el]["hp"]}`)
  58.  console.log(`MP: ${herosData[el]["mp"]}`)
  59. }
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement