nikolayneykov

Untitled

Mar 1st, 2019
156
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.             if (health <= 0) {
  23.                 console.log(`You died! Killed by ${monsterName}.\nBest room: ${i + 1}`);
  24.                 break;
  25.             }
  26.             console.log(`You slayed ${monsterName}.`);
  27.         }
  28.     }
  29.  
  30.     if (health > 0) {
  31.         console.log(`You've made it!\nCoins: ${coins}\nHealth: ${health}`);
  32.    }
  33. }
Advertisement
Add Comment
Please, Sign In to add comment