UNPKG

summonerriftadventure-illuxion

Version:

Summoner's Rift Adventure is a JavaScript game where players embark on exciting adventures within the Summoner's Rift.

169 lines (141 loc) 4.82 kB
class Player { constructor(name, level, health, mana) { this.name = name; this.level = level; this.health = health; this.mana = mana; this.inventory = []; this.equippedItems = { weapon: null, armor: null, accessory: null }; this.statusEffects = []; } attack(target) { if (this.equippedItems.weapon) { let damage = this.equippedItems.weapon.damage; target.takeDamage(damage); } else { console.log("You have no weapon equipped!"); } } takeDamage(amount) { this.health -= amount; if (this.health <= 0) { console.log(`${this.name} has been defeated!`); } } useItem(item) { if (this.inventory.includes(item)) { item.applyEffect(this); this.removeFromInventory(item); } else { console.log("You don't have that item in your inventory!"); } } addToInventory(item) { this.inventory.push(item); } removeFromInventory(item) { const index = this.inventory.indexOf(item); if (index !== -1) { this.inventory.splice(index, 1); } } } class Item { constructor(name, description) { this.name = name; this.description = description; } applyEffect(target) { // To be implemented by subclasses } } class HealthPotion extends Item { constructor(name, description, healingAmount) { super(name, description); this.healingAmount = healingAmount; } applyEffect(target) { target.health += this.healingAmount; console.log(`${target.name} consumes ${this.name} and restores ${this.healingAmount} health!`); } } class ManaPotion extends Item { constructor(name, description, manaAmount) { super(name, description); this.manaAmount = manaAmount; } applyEffect(target) { target.mana += this.manaAmount; console.log(`${target.name} consumes ${this.name} and restores ${this.manaAmount} mana!`); } } const player1 = new Player("Alice", 1, 100, 50); const player2 = new Player("Bob", 1, 100, 50); const healthPotion = new HealthPotion("Health Potion", "Restores 50 health points.", 50); const manaPotion = new ManaPotion("Mana Potion", "Restores 50 mana points.", 50); player1.addToInventory(healthPotion); player2.addToInventory(manaPotion); player1.attack(player2); player2.useItem(manaPotion); function getRandomNumber(min, max) { return Math.floor(Math.random() * (max - min + 1)) + min; } function shuffleArray(array) { for (let i = array.length - 1; i > 0; i--) { const j = Math.floor(Math.random() * (i + 1)); [array[i], array[j]] = [array[j], array[i]]; } return array; } function generateRandomName() { const vowels = 'aeiou'; const consonants = 'bcdfghjklmnpqrstvwxyz'; const nameLength = getRandomNumber(3, 8); let name = ''; for (let i = 0; i < nameLength; i++) { name += i % 2 === 0 ? consonants.charAt(getRandomNumber(0, consonants.length - 1)) : vowels.charAt(getRandomNumber(0, vowels.length - 1)); } return name.charAt(0).toUpperCase() + name.slice(1); } function generateRandomItem() { const itemNames = ["Sword", "Shield", "Helmet", "Potion", "Scroll"]; const randomName = itemNames[getRandomNumber(0, itemNames.length - 1)]; const randomDescription = `A powerful ${randomName.toLowerCase()} that grants special abilities.`; return { name: randomName, description: randomDescription }; } const player3 = new Player(generateRandomName(), getRandomNumber(1, 10), getRandomNumber(50, 150), getRandomNumber(30, 100)); const player4 = new Player(generateRandomName(), getRandomNumber(1, 10), getRandomNumber(50, 150), getRandomNumber(30, 100)); const randomHealthPotion = new HealthPotion("Health Potion", "Restores 50 health points.", 50); const randomManaPotion = new ManaPotion("Mana Potion", "Restores 50 mana points.", 50); const randomItem = generateRandomItem(); player3.addToInventory(randomHealthPotion); player3.addToInventory(randomManaPotion); player4.addToInventory(randomItem); player4.attack(player3); player3.useItem(randomManaPotion); class StatusEffect { constructor(name, description, duration) { this.name = name; this.description = description; this.duration = duration; } applyEffect(target) { target.statusEffects.push(this); setTimeout(() => { this.removeEffect(target); }, this.duration); } removeEffect(target) { const index = target.statusEffects.indexOf(this); if (index !== -1) { target.statusEffects.splice(index, 1); } } } const randomStatusEffect = new StatusEffect("Bleeding", "Causes continuous damage over time.", 3000); randomStatusEffect.applyEffect(player3);