Code Pal Result
Code Pal Result
/** @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