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