Ivankooo1

DungeonDark

Sep 4th, 2019
391
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function dungeonDark(arr){
  2.     let dungen = arr[0].split('|');
  3.     let health = 100;
  4.     let coins = 0;
  5.     let counterRooms = 0;
  6.     let allCoins = 0;
  7.  
  8.     for(let i = 0; i < dungen.length;i++){
  9.         let currentRoom = dungen[i].split(' ');
  10.         let command = currentRoom[0];
  11.         let num = currentRoom[1];
  12.         counterRooms++;
  13.  
  14.         if(command === 'potion'){
  15.  
  16.           if(health < 100){
  17.             console.log(`You healed for ${100 - health} hp.`);
  18.             health += Number(num);
  19.  
  20.             if(health > 100){
  21.               health = 100;
  22.               console.log(`Current health: ${health} hp.`);
  23.             }else{
  24.               console.log(`Current health: ${health} hp.`);
  25.             }
  26.            
  27.  
  28.           }
  29.                  
  30.         }else if(command === 'chest'){
  31.           coins = Number(num);
  32.           allCoins += Number(num);
  33.           console.log(`You found ${coins} coins.`);
  34.    
  35.         }else{
  36.           health -= Number(num);
  37.           if(health > 0){
  38.             console.log(`You slayed ${command}.`);
  39.           }else{
  40.             console.log(`You died! Killed by ${command}.`);
  41.             console.log(`Best room: ${counterRooms}`);
  42.             break;
  43.           }
  44.          
  45.         }
  46.                
  47.     }
  48.     if(dungen.length === counterRooms){
  49.       console.log(`You've made it!`);
  50.      console.log(`Coins: ${allCoins}`);
  51.      console.log(`Health: ${health}`);
  52.    }
  53.  
  54.    
  55. }
  56.  
  57. dungeonDark(['rat 10|bat 20|potion 10|rat 10|chest 100|boss 70|chest 1000']);
Advertisement
Add Comment
Please, Sign In to add comment