Advertisement
PowerCell46

Darkest dungeons JS

Dec 7th, 2022
985
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function dungeonestDark(array) {
  2.     let health = 100;
  3.     let coins = 0;
  4.  
  5.     let string = array[0];
  6.     let roomArray = string.split("|");
  7.     let counter = 0;
  8.     let theGameIsOver = false;
  9.  
  10.     for (let index = 0; index < Number(roomArray.length); index++) {
  11.         let currentThing = roomArray[index];
  12.         currentThing = currentThing.split(" ");
  13.         let potionOrMonster = currentThing[0];
  14.         let number = Number(currentThing[1]);
  15.         counter++;
  16.  
  17.         switch (potionOrMonster) {
  18.  
  19.             case "potion":
  20.                 health += number;
  21.                 if (health > 100) {
  22.                     let holder = health - 100;
  23.                     number = number - holder;
  24.                     health = 100;
  25.                 }
  26.                 console.log(`You healed for ${number} hp.`);
  27.                 console.log(`Current health: ${health} hp.`);
  28.                 break;
  29.  
  30.             case "chest":
  31.                 coins += number;
  32.                 console.log(`You found ${number} coins.`);
  33.                 break;
  34.  
  35.             default:
  36.                 health -= number;
  37.                 if (health > 0) {
  38.                     console.log(`You slayed ${potionOrMonster}.`);
  39.                 } else {
  40.                     console.log(`You died! Killed by ${potionOrMonster}.`);
  41.                     console.log(`Best room: ${counter}`);
  42.                     theGameIsOver = true;
  43.                     break;
  44.                 }
  45.         }
  46.         if (theGameIsOver === true) {
  47.             break;
  48.         }
  49.     }
  50.  
  51.     if (theGameIsOver === false) {
  52.         console.log(`You've made it!`);
  53.        console.log(`Coins: ${coins}`);
  54.        console.log(`Health: ${health}`);
  55.    }
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement