Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function solve(input){
- const n=Number(input.shift());
- let AllCharacters ={};
- for (let i = 0; i < n; i++) {
- const [name,HP,bullets]= input.shift().split(' ');
- AllCharacters[name]={HP:Number(HP),bullets:Number(bullets)};
- }
- let CmdCommand=input.shift();
- while(CmdCommand !='Ride Off Into Sunset'){
- let CmdCurrent=CmdCommand.split(' - ');
- let name=CmdCurrent[1];
- switch (CmdCurrent[0]){
- case 'FireShot':
- if(AllCharacters[CmdCurrent[1]].bullets >0){
- AllCharacters[CmdCurrent[1]].bullets -=1;
- console.log(`${name} has successfully hit ${CmdCurrent[2]} and now has ${AllCharacters[name].bullets} bullets!`)
- }
- else{
- console.log(`${name} doesn't have enough bullets to shoot at ${CmdCurrent[2]}!`)
- }
- break;
- case 'TakeHit':
- const damage=Number(CmdCurrent[2]);
- const attacker=CmdCurrent[3];
- AllCharacters[name].HP -=damage;
- if(AllCharacters[name].HP >0){
- console.log(`${name} took a hit for ${damage} HP from ${attacker} and now has ${AllCharacters[name].HP} HP!`)
- }
- else{
- console.log(`${name} was gunned down by ${attacker}!`)
- }
- break;
- case 'Reload':
- if(AllCharacters[name].bullets <6){
- const Reloaded=6-AllCharacters[name].bullets;
- AllCharacters[name].bullets=6;
- console.log(`${name} reloaded ${Reloaded} bullets!`);
- }
- else{
- console.log(`${name}'s pistol is fully loaded!`)
- }
- break;
- case 'PatchUp':
- let amount=Number(CmdCurrent[2]);
- let recoveredhp=0;
- if(AllCharacters[name].HP==100){
- console.log(`${name} is in full health!`);
- }
- else{
- if( AllCharacters[name].HP + amount >100){
- AllCharacters[name].HP=100;
- recoveredhp=100-AllCharacters[name].HP;
- console.log(`${name} patched up and recovered ${recoveredhp} HP!`)
- }
- else{
- AllCharacters[name].HP +=amount;
- recoveredhp=amount;
- console.log(`${name} patched up and recovered ${recoveredhp} HP!`)
- }
- }
- break;
- }
- CmdCommand=input.shift();
- }
- let NewCharacters= Object.entries(AllCharacters)
- for (const character of NewCharacters) {
- if(character[1].HP>0){
- console.log(`${character[0]}`);
- console.log(`HP: ${character[1].HP}`);
- console.log(`Bullets: ${character[1].bullets}`);
- }
- }
- }
- solve
- (["2",
- "Jesse 100 4",
- "Walt 100 5",
- "FireShot - Jesse - Bandit",
- "TakeHit - Walt - 30 - Bandit",
- "PatchUp - Walt - 20" ,
- "Reload - Jesse",
- "Ride Off Into Sunset"])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement