Untitled

 avatar
unknown
plain_text
2 years ago
3.1 kB
1
Indexable
// Define the character class
class Character {
  constructor(name, strength, agility, intelligence) {
    this.name = name;
    this.strength = strength;
    this.agility = agility;
    this.intelligence = intelligence;
    this.health = 100;
    this.level = 1;
    this.experience = 0;
  }

  // Method to attack another character
  attack(enemy) {
    let damage = this.strength - enemy.agility;
    if (damage > 0) {
      enemy.health -= damage;
      console.log(`${this.name} attacks ${enemy.name} for ${damage} damage!`);
      if (enemy.health <= 0) {
        console.log(`${enemy.name} has been defeated!`);
        this.gainExperience(enemy.level * 10);
      }
    } else {
      console.log(`${this.name} misses the attack!`);
    }
  }

  // Method to gain experience points
  gainExperience(points) {
    this.experience += points;
    if (this.experience >= this.level * 100) {
      this.levelUp();
    }
  }

  // Method to level up
  levelUp() {
    this.level++;
    this.strength += 5;
    this.agility += 5;
    this.intelligence += 5;
    this.health = 100;
    console.log(`${this.name} has leveled up to level ${this.level}!`);
  }
}

// Define the wrestler class
class Wrestler extends Character {
  constructor(name, strength, agility, intelligence, signatureMove) {
    super(name, strength, agility, intelligence);
    this.signatureMove = signatureMove;
  }

  // Method to perform the signature move
  performSignatureMove(enemy) {
    let damage = this.strength * 2 - enemy.agility;
    if (damage > 0) {
      enemy.health -= damage;
      console.log(`${this.name} performs ${this.signatureMove} on ${enemy.name} for ${damage} damage!`);
      if (enemy.health <= 0) {
        console.log(`${enemy.name} has been defeated!`);
        this.gainExperience(enemy.level * 20);
      }
    } else {
      console.log(`${this.name} misses the signature move!`);
    }
  }
}

// Define the game
class WWE_RPG {
  constructor(player1, player2) {
    this.player1 = player1;
    this.player2 = player2;
  }

  // Method to start the game
  start() {
    console.log(`${this.player1.name} vs. ${this.player2.name}`);
    console.log(`${this.player1.name} has ${this.player1.health} health and ${this.player1.level} level`);
    console.log(`${this.player2.name} has ${this.player2.health} health and ${this.player2.level} level`);

    let currentPlayer = this.player1;
    let otherPlayer = this.player2;

    while (this.player1.health > 0 && this.player2.health > 0) {
      currentPlayer.attack(otherPlayer);
      if (otherPlayer.health > 0) {
        currentPlayer = this.switchPlayers(currentPlayer, otherPlayer);
        otherPlayer = this.switchPlayers(otherPlayer, currentPlayer);
      }
    }

    console.log(`Game over! ${currentPlayer.name} wins!`);
  }

  // Method to switch players
  switchPlayers(player1, player2) {
    let temp = player1;
    player1 = player2;
    player2 = temp;
    return player1;
  }
}

// Create some characters
let johnCena = new Wrestler("John Cena", 2
Editor is loading...