Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // function that prints a random number from 1 - 50:
- function getRndNumber(min, max) {
- return Math.floor(Math.random() * (max - min + 1)+ min);
- }
- const randomNum = getRndNumber(1, 50);
- console.log(randomNum);
- // function that drills a random material out from the ground:
- const material = ["Diamond", "Platinum", "Gold", "Emerald", "Ruby", "Silver"];
- function RndMaterial(arr) {
- const RndMaterial = Math.floor(Math.random() * arr.length);
- return arr[RndMaterial];
- }
- const randomMat = RndMaterial(material);
- console.log(randomMat)
- // function that calculates the area of a rectangle:
- function Areaofrectangle(length, width) {
- return (length * width);
- }
- const length = 50
- const width = 30
- const area = length * width
- console.log(area);
- // function to apply a speed boost
- function applySpeedBoost(currentSpeed, boostMultiplier) {
- return currentSpeed * boostMultiplier;
- }
- const playerSpeed = 20;
- const boostMultiplier = 50;
- const boostedSpeed = applySpeedBoost(playerSpeed, boostMultiplier);
- console.log(boostedSpeed)
- // function to simulate health regeneration
- function regenerateHealth(currentHealth, regenerationRate, timeInSeconds) {
- const regeneratedHealth = currentHealth + regenerationRate * timeInSeconds;
- return Math.min(regeneratedHealth, 100); // Cap health at 100
- }
- const playerHealth = 80;
- const regenerationRate = 2;
- const timeElapsed = 5;
- const newHealth = regenerateHealth(playerHealth, regenerationRate, timeElapsed);
- console.log(`New health: ${newHealth}`);
- // function to calculate experience points (XP)
- function calculateXP(level, baseXP, multiplier) {
- return baseXP * Math.pow(level, multiplier);
- }
- const playerLevel = 5;
- const baseXP = 100;
- const xpMultiplier = 1.5;
- const earnedXP = calculateXP(playerLevel, baseXP, xpMultiplier);
- console.log(earnedXP);
- // inventory system integration:
- const playerInventory = {
- credits: 52,
- coins: 7,
- keys: 4,
- weapons: ["sword", "bow & arrow"],
- };
- // function that adds an item to the inventory of the player:
- function addtoInventory(item, quantity) {
- if (playerInventory[item]) {
- playerInventory[item] += quantity;
- } else {
- playerInventory[item] = quantity;
- }
- }
- addtoInventory("credits", 75);
- addtoInventory("coins", 25);
- console.log(playerInventory);
- // function that simulates loot drops in RPG games:
- function getRndLoot() {
- const lootTable = [
- {item: "health potion", chance: 0.2},
- {item: "speed potion", chance: 1.2},
- {item: "rare coin", chance: 1.1},
- ];
- const randomNum = Math.random();
- var selectedItem = null;
- for(const loot of lootTable) {
- if(randomNum < loot.chance) {
- selectedItem = loot.item;
- break;
- }
- }
- return selectedItem || `no loot`;
- }
- const droppedItem = getRndLoot();
- console.log(droppedItem)
- // function that tracks quests completed by players:
- const completedQuests = [];
- function completeQuest(questName) {
- if(!completedQuests.includes(questName)) {
- completedQuests.push(questName);
- }
- }
- completeQuest("Find Darkost in the Armageddon");
- completeQuest("Retrieve the crown from the forgotten dungeon");
- console.log(`Completed quests: ${completedQuests.join(', ')}`);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement