Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function heroesofCodeandLogic (input){
- let heroNum = Number(input.shift())
- let heroes = input.splice(0,heroNum)
- let commandLine = input.splice(0, input.indexOf("End"))
- let herosData= {}
- heroes.forEach(element => {
- let [hero, hp, mp] = element.split(" ")
- hp=Number(hp)
- mp = Number(mp)
- if(!herosData.hasOwnProperty(hero)){
- herosData[hero] = {hp, mp}
- }
- });
- commandLine.forEach(line=>{
- let commandsData = line.split(" - ")
- command = commandsData[0]
- // console.log(commandsData)
- switch(command){
- case "Heal":
- let [com,nameHero, hpHero] = commandsData
- hpHero = Number(hpHero)
- let refill = Math.min((100 - herosData[nameHero]["hp"]), hpHero)
- herosData[nameHero]["hp"]+=refill
- console.log(`${nameHero} healed for ${refill} HP!`)
- break
- case "Recharge":
- let [comand,name, mpHero] = commandsData
- mpHero = Number(mpHero)
- let recharge = Math.min((200 - herosData[name]["mp"]), mpHero)
- herosData[name]["mp"]+=recharge
- console.log(`${name} recharged for ${recharge} MP!`)
- break;
- case "TakeDamage":
- let [ commands, heroName, health,attaker] = commandsData
- herosData[heroName]["hp"]-= health
- if(herosData[heroName]["hp"]<=0){
- console.log(`${heroName} has been killed by ${attaker}!`)
- delete herosData[heroName]
- }else{
- console.log(`${heroName} was hit for ${health} HP by ${attaker} and now has ${herosData[heroName]["hp"]} HP left!`)
- }
- break;
- case "CastSpell":
- let [comL, heroes, mana,spells] = commandsData
- if(herosData[heroes]["mp"]>= mana){
- herosData[heroes]["mp"]-=mana
- console.log(`${heroes} has successfully cast ${spells} and now has ${herosData[heroes]["mp"]} MP!`)
- }else{
- console.log(`${heroes} does not have enough MP to cast ${spells}!`)
- }
- break;
- }
- })
- for(let el in herosData){
- console.log(`${el}`)
- console.log(`HP: ${herosData[el]["hp"]}`)
- console.log(`MP: ${herosData[el]["mp"]}`)
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement