0% found this document useful (0 votes)
31 views3 pages

Code Pal Result

The document defines two classes - Enemy and Player - to represent characters in the game "Lag Free Fire". The Enemy class constructor takes in a name, health, and damage amount. It has methods to retrieve these attributes and attack a player by reducing their health. The Player class is similar, but with a method to reduce its own health. An example at the end demonstrates creating an enemy and player, having the enemy attack to reduce the player's health, and logging the results.

Uploaded by

ikangfadli19
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
31 views3 pages

Code Pal Result

The document defines two classes - Enemy and Player - to represent characters in the game "Lag Free Fire". The Enemy class constructor takes in a name, health, and damage amount. It has methods to retrieve these attributes and attack a player by reducing their health. The Player class is similar, but with a method to reduce its own health. An example at the end demonstrates creating an enemy and player, having the enemy attack to reduce the player's health, and logging the results.

Uploaded by

ikangfadli19
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 3

/**

* Represents an enemy in the game "Lag Free Fire".


*/
class Enemy {
/**
* Constructor for the Enemy class.
*
* @param {string} name - The name of the enemy.
* @param {number} health - The health of the enemy.
* @param {number} damage - The damage dealt by the enemy.
*/
constructor(name, health, damage) {
/** @private */
this.name = name;

/** @private */
this.health = health;

/** @private */
this.damage = damage;
}

/**
* Getter method to retrieve the name of the enemy.
*
* @returns {string} The name of the enemy.
*/
getName() {
return this.name;
}

/**
* Getter method to retrieve the health of the enemy.
*
* @returns {number} The health of the enemy.
*/
getHealth() {
return this.health;
}

/**
* Getter method to retrieve the damage dealt by the enemy.
*
* @returns {number} The damage dealt by the enemy.
*/
getDamage() {
return this.damage;
}

/**
* Attacks a player, reducing their health based on the enemy's damage.
*
* @param {Player} player - The player being attacked.
*/
attack(player) {
player.reduceHealth(this.damage);
}
}
/**
* Represents a player in the game "Lag Free Fire".
*/
class Player {
/**
* Constructor for the Player class.
*
* @param {string} name - The name of the player.
* @param {number} health - The health of the player.
* @param {number} damage - The damage dealt by the player.
*/
constructor(name, health, damage) {
/** @private */
this.name = name;

/** @private */
this.health = health;

/** @private */
this.damage = damage;
}

/**
* Getter method to retrieve the name of the player.
*
* @returns {string} The name of the player.
*/
getName() {
return this.name;
}

/**
* Getter method to retrieve the health of the player.
*
* @returns {number} The health of the player.
*/
getHealth() {
return this.health;
}

/**
* Getter method to retrieve the damage dealt by the player.
*
* @returns {number} The damage dealt by the player.
*/
getDamage() {
return this.damage;
}

/**
* Reduces the player's health by a specified amount.
*
* @param {number} amount - The amount by which the health should be reduced.
*/
reduceHealth(amount) {
this.health -= amount;
}
}
// Usage Example for Enemy and Player

// Create an enemy and a player


const enemy = new Enemy("Enemy1", 100, 20);
const player = new Player("Player1", 100, 10);

// Attack the player with the enemy


enemy.attack(player);

// Check the player's health after the attack


console.log(`${player.getName()}'s health: ${player.getHealth()}`);

You might also like