nikolayneykov

Untitled

Feb 28th, 2019
152
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function printDungeon(params) {
  2.     let rooms = params[0].split('|');
  3.     let health = 100;
  4.     let coins = 0;
  5.  
  6.     for (let i = 0; i < rooms.length; i++) {
  7.         let room = rooms[i].split(' ');
  8.         let roomContent = room[0];
  9.         let roomValue = Number(room[1]);
  10.  
  11.         if (roomContent === 'potion') {
  12.             let healthGain = Math.min(roomValue, 100 - health);
  13.             health += healthGain;
  14.             console.log(`You healed for ${healthGain} hp.\nCurrent health: ${health} hp.`);
  15.         } else if (roomContent === 'chest') {
  16.             coins += roomValue;
  17.             console.log(`You found ${roomValue} coins.`);
  18.         } else {
  19.             let monsterName = roomContent;
  20.             let monsterDamage = roomValue;
  21.             health -= monsterDamage;
  22.            
  23.             if (health <= 0) {
  24.                 console.log(`You died! Killed by ${monsterName}.\nBest room: ${i + 1}`);
  25.                 break;
  26.             }
  27.  
  28.             console.log(`You slayed ${monsterName}.`);
  29.         }
  30.     }
  31.  
  32.     if (health > 0) {
  33.         console.log(`You've made it!\nCoins: ${coins}\nHealth: ${health}`);
  34.    }
  35. }
Advertisement
Add Comment
Please, Sign In to add comment