Liliana797979

Dungeonest Dark - fundamentals

Jun 12th, 2021
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2.      
  3. function dungeonDark(arr){
  4.   let dungen = arr[0].split('|');
  5.   let health = 100;
  6.   let coins = 0;
  7.   let counterRooms = 0;
  8.   let allCoins = 0;
  9.  
  10.   for(let i = 0; i < dungen.length;i++){
  11.       let currentRoom = dungen[i].split(' ');
  12.       let command = currentRoom[0];
  13.       let num = Number(currentRoom[1]); // Може още тук да го направим число
  14.       counterRooms++;
  15.  
  16.       if(command === 'potion'){
  17. //Коригирана проверка за здравето
  18.         if (health + num > 100) {
  19.           num = 100 - health;
  20.           health = 100;
  21.         } else
  22.         {
  23.           health += num;
  24.         }
  25.         console.log(`You healed for ${num} hp.`);
  26.         console.log(`Current health: ${health} hp.`);
  27.  
  28.                
  29.       }else if(command === 'chest'){
  30.         coins = Number(num);
  31.         allCoins += Number(num);
  32.         console.log(`You found ${coins} coins.`);
  33.  
  34.       }else{
  35.         health -= Number(num);
  36.         if(health > 0){
  37.           console.log(`You slayed ${command}.`);
  38.         }else{
  39.           console.log(`You died! Killed by ${command}.`);
  40.           console.log(`Best room: ${counterRooms}`);
  41.           //Може направо да прекъснем програмата
  42.           return;
  43.         }
  44.        
  45.       }          
  46.   }
  47.   // Като използваме return проврката се обесмисля
  48.     console.log(`You've made it!`);
  49.    console.log(`Coins: ${allCoins}`);
  50.    console.log(`Health: ${health}`);
  51. }
Advertisement
Add Comment
Please, Sign In to add comment