Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function muOnline(inputArr) {
- let copyArr = inputArr[0].slice().split('|');
- let maxHealth = 100;
- let currentHealth = 100;
- let bitcoins = 0;
- let isDead = false;
- let roomCount = 1;
- for (let i = 0; i < copyArr.length; i++) {
- let currentRoom = copyArr[i].slice().split(' ');
- let action = currentRoom[0];
- let num = Number(currentRoom[1]);
- if (isDead) {
- break;
- }
- switch (action) {
- case 'potion':
- potion(num)
- break;
- case 'chest':
- chest(num)
- break;
- default:
- figth(action, num)
- break;
- }
- roomCount++
- }
- if (!isDead) {
- console.log(`You've made it!\nBitcoins: ${bitcoins}\nHealth: ${currentHealth}`);
- }
- function potion(health) {
- if (currentHealth + health <= 100) {
- currentHealth += health;
- console.log(`You healed for ${health} hp.`);
- } else {
- console.log(`You healed for ${maxHealth - currentHealth} hp.`);
- currentHealth = maxHealth;
- }
- console.log(`Current health: ${currentHealth} hp.`);
- }
- function chest(bitcoin) {
- bitcoins += bitcoin;
- console.log(`You found ${bitcoin} bitcoins.`);
- }
- function figth(monster, attack) {
- currentHealth -= attack;
- if (currentHealth <= 0) {
- isDead = true;
- console.log(`You died! Killed by ${monster}.`);
- console.log(`Best room: ${roomCount}`);
- } else {
- console.log(`You slayed ${monster}.`);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement