Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- dungeonestDark = ([dungeon]) => {
- dungeon = dungeon.split('|').map(room => {
- let [ type, value ] = room.split(' ');
- return { type, value: Number(value) };
- });
- let health = 100, coins = 0;
- for(let i=0; i<dungeon.length; i++) {
- let { type, value } = dungeon[i];
- if(type === 'potion') {
- let newHealth = (health + value > 100 ? 100 : health + value);
- console.log(`You healed for ${newHealth-health} hp.`);
- health = newHealth;
- console.log(`Current health: ${health} hp.`);
- } else if(type === 'chest') {
- console.log(`You found ${value} coins.`);
- coins += value;
- } else { // monster
- health -= value;
- if(health > 0) console.log(`You slayed ${type}.`);
- else return console.log(`You died! Killed by ${type}.\nBest room: ${i+1}`);
- }
- }
- console.log(`You've made it!\nCoins: ${coins}\nHealth: ${health}`);
- }
Advertisement
Add Comment
Please, Sign In to add comment