Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function solve(input) {
- let rooms = input.shift().split('|');
- let health = 100;
- let bitcoins = 0;
- let currHealth = 0;
- let tempHealth = 0;
- let notDead = true;
- for (let i = 0; i < rooms.Length; i++)
- {
- let currBitcoins = 0;
- let command = rooms[i];
- let splitted = command.split();
- if (splitted[0] === "potion")
- {
- currHealth = health;
- tempHealth = health;
- currHealth += splitted[1];
- if (currHealth <= 100)
- {
- health += splitted[1];
- console.log(`You healed for ${splitted[1]} hp.`);
- console.log(`Current health: ${health} hp.`);
- }
- else if (currHealth > 100)
- {
- let diff = 100 - tempHealth;
- health = 100;
- console.log(`You healed for ${diff} hp.`);
- console.log(`Current health: ${health} hp.`);
- }
- }
- else if (splitted[0] == "chest")
- {
- bitcoins += splitted[1];
- currBitcoins += splitted[1];
- console.log(`You found ${currBitcoins} bitcoins.`);
- }
- else
- {
- let attack = splitted[1];
- health -= attack;
- if (health <= 0)
- {
- console.log(`You died! Killed by {splitted[0]}.`);
- console.log(`Best room: ${i+1}`);
- notDead = false;
- break;
- }
- else if (health > 0) {
- console.log(`You slayed ${splitted[0]}`)
- }
- }
- }
- if (notDead)
- {
- console.log(`'You've made it!'`);
- console.log(`Bitcoins: ${bitcoins}`);
- console.log(`Health: ${health}`);
- }
- }
- solve(['rat 10|bat 20|potion 10|rat 10|chest 100|boss 70|chest 1000'])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement