Advertisement
EntropyStarRover

Dungeon 2

May 30th, 2019
196
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function dungeon(input){
  2.     let health=100;
  3.     let coins=0;
  4.     let rooms=0;
  5.  
  6.     let strInput=String(input);
  7.     let arrRooms=strInput.split("|");
  8.     let currRoom="";
  9.  
  10.    
  11.    
  12.      for (let i=0; i<arrRooms.length;i++){
  13.        let  currRoom=arrRooms[i];
  14.        
  15.          let first=currRoom.substring(0,currRoom.indexOf(" "));
  16.          let second=Number(currRoom.substring(currRoom.indexOf(" ")+1));
  17.    
  18.  
  19.          if (first=="potion"){
  20.             health+=second;
  21.            let healed=second;
  22.             if (health>100){
  23.               healed-=(health-100);
  24.                 health=100;
  25.             }
  26.             console.log(`You healed for ${healed} hp.`);
  27.             console.log(`Current health: ${health} hp.`)
  28.          } else if(first=="chest") {
  29.              coins+=second;
  30.              console.log(`You found ${second} coins.`);
  31.  
  32.          } else {
  33.              health-=second;
  34.              if (health>0){
  35.                  console.log(`You slayed ${first}.`);
  36.              } else {
  37.                  console.log(`You died! Killed by ${first}.`);
  38.                  console.log(`Best room: ${i+1}`);
  39.                  return;
  40.              }
  41.          }
  42.      
  43.      
  44.  
  45.     }
  46.     console.log(`You've made it!`);
  47.    console.log(`Coins: ${coins}`);
  48.    console.log(`Health: ${health}`);
  49.  
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement