Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function dungeonestDark(parameters) {
- let rooms = parameters[0].split('|');
- let health = 100;
- let coins = 0;
- for (let i = 0; i < rooms.length; i++) {
- let room = rooms[i].split(' ');
- let roomContent = room[0];
- let roomValue = Number(room[1]);
- if (roomContent === 'potion') {
- let healthGain = Math.min(roomValue, 100 - health);
- health += healthGain;
- console.log(`You healed for ${healthGain} hp.\nCurrent health: ${health} hp.`);
- } else if (roomContent === 'chest') {
- coins += roomValue;
- console.log(`You found ${roomValue} coins.`)
- } else {
- let monsterName = roomContent;
- let monsterDamage = roomValue;
- health -= monsterDamage;
- if (health <= 0) {
- console.log(`You died! Killed by ${monsterName}.\nBest room: ${i+1}`)
- break;
- }
- console.log(`You slayed ${monsterName}.`);
- }
- }
- if (health > 0) {
- console.log(`You've made it!\nCoins: ${coins}\nHealth: ${health}`)
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement