Here's the final mini project I was asking this question for. I'm currently on day 4 of learning Javascript and this is the best I got. Thank you so much again!
class player {
constructor(name,phrase) {
this._name = name;
this._catchPhrase = phrase;
this._health = 100;
this._abilities = {
_cannonball: {
_damage: 20,
_currAmount: 3,
},
_arrows: {
_damage: 10,
_currAmount: 10,
},
}
}
set lowerCannon(lowerBy) {
this._abilities._cannonball._currAmount -= lowerBy;
}
set lowerArrows(lowerBy) {
this._abilities._arrows._currAmount -= lowerBy;
}
set lowerHealth(lowerBy) {
this._health -= lowerBy;
if (this._health <= 0) {
this._health = 0;
}
}
}
//shooting functions that lower current amount
var shootCannon = (playerTurn,playerHit) => {
if (playerTurn._health === 0 || playerHit._health === 0)
{
//console.log('Game has already ended!')
}
if (playerTurn._abilities._cannonball._currAmount === 0) {
console.log(`${playerTurn._name} is out of Cannonballs!`)
shootArrows(playerTurn,playerHit);
}
else {
playerTurn.lowerCannon = '1';
playerHit.lowerHealth = playerTurn._abilities._cannonball._damage;
console.log(`${playerTurn._name} has fired a cannonball dealing ${playerTurn._abilities._cannonball._damage} damage!...`);
console.log()
console.log(`${playerHit._name}'s health is now at ${playerHit._health}!`);
console.log()
}
}
var shootArrows = (playerTurn,playerHit) => {
if (playerTurn._health === 0 || playerHit._health === 0)
{
//console.log('Game has already ended!')
}
if (playerTurn._abilities._arrows._currAmount === 0) {
console.log(`${playerTurn._name} is out of arrows!`)
shootCannonball(playerTurn,playerHit);
}
else {
playerTurn.lowerArrows = '1';
playerHit.lowerHealth = playerTurn._abilities._arrows._damage;
console.log(`${playerTurn._name} has fired arrows! dealing ${playerTurn._abilities._arrows._damage} damage!...`);
console.log()
console.log(`${playerHit._name}'s health is now at ${playerHit._health}!`);
console.log()
}
}
//Make computer fight each other functions
var randomAttack = (playerTurn,playerHit) =>{
index = Math.floor(Math.random()*2);
if (index === 1) {
return shootArrows(playerTurn,playerHit);
}
else {
return shootCannon(playerTurn,playerHit);
}
}
var botMatch = (playerTurn,playerHit) => {
if (playerTurn._health <= 0 || playerHit._health <= 0) {
if (playerTurn._health > playerHit._health) {
console.log(`${playerTurn._name} has won!`)
}
if (playerTurn._health < playerHit._health) {
console.log(`${playerHit._name} has won!`)
}
console.log('Game Over!')
}
else {
randomAttack(playerTurn,playerHit);
randomAttack(playerHit,playerTurn);
botMatch(playerTurn,playerHit);
}
}
const player1 = new player('Juan','Let\'s Go!');
const player2 = new player('Jaileth','Beep Beep');
botMatch(player1,player2);