Advertisement
EntropyStarRover

Dungeon

May 30th, 2019
200
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 arrRooms=input.split("|");
  7.     let currRoom="";
  8.  
  9.    
  10.    
  11.      for (let i=0; i<arrRooms.length;i++){
  12.          currRoom=arrRooms[i];
  13.        
  14.          let first=currRoom.substring(0, currRoom.indexOf(" "));
  15.          let second=Number(currRoom.substring(currRoom.indexOf(" ")+1));
  16.    
  17.  
  18.          if (first=="potion"){
  19.             health+=second;
  20.             if (health>100){
  21.                 health=100;
  22.             }
  23.             console.log(`You healed for ${second} hp.`);
  24.             console.log(`Current health: ${health} hp.`)
  25.          } else if(first=="chest") {
  26.              coins+=second;
  27.              console.log(`You found ${second} coins.`);
  28.  
  29.          } else {
  30.              health-=second;
  31.              if (health>0){
  32.                  console.log(`You slayed ${first}.`);
  33.              } else {
  34.                  console.log(`You died! Killed by ${first}.`);
  35.                  console.log(`Best room: ${i+1}`);
  36.                  return;
  37.              }
  38.          }
  39.      
  40.      
  41.  
  42.     }
  43.     console.log(`You've made it!`);
  44.    console.log(`Coins: ${coins}`);
  45.    console.log(`Health: ${health}`);
  46.  
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement