Skip to content

Commit

Permalink
add function comments
Browse files Browse the repository at this point in the history
  • Loading branch information
miami78 committed Jun 4, 2020
1 parent afaa301 commit 4ec75ad
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions js/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@
this.putClass(position, 'barrier');
}
};

// Function to place weapons
game.prototype.placeWeapon = function(weapon) {
const colPosition = randomNum();
const rowPosition = randomNum();
Expand All @@ -190,7 +190,7 @@
this.putClass(position, weapon, true);
}
};

// Function to place players
game.prototype.placePlayer = function (player) {
const colPosition = randomNum();
const rowPosition = randomNum();
Expand All @@ -207,7 +207,7 @@
this.putClass(position, player.name);
}
};

// Function to check if cell has a barrier
game.prototype.hasBarriers = function(fromPosition, toPosition) {
const direction = toPosition.col == fromPosition.col ? 'row' : 'col';
const diff = direction === 'col'
Expand Down Expand Up @@ -375,7 +375,7 @@
.values(this.weapons)
.find(weapon => weapon.position && weapon.position.col === newPosition.col && weapon.position.row === newPosition.row);
};

// Function to switch weapon when a player lands on it
game.prototype.switchWeapon = function(player) {
const position = player.position;
const newWeapon = this.findWeaponByPosition(position);
Expand Down Expand Up @@ -403,7 +403,7 @@


}

// Function to check if players are close to each other
game.prototype.isReadyToFight = function() {
// get player1 position
const colPlayer1 = this.player1.position.col;
Expand All @@ -427,6 +427,7 @@
}
return false;
};
// Function to refresh player health and weapons
game.prototype.getPlayerStats = function() {
// Knight stats
let knightHealth = document.querySelector('#knightHealthInput');
Expand All @@ -446,7 +447,7 @@
dragonAttack.innerHTML = this.player2.weapon.damage;
dragonWeapon.innerHTML = this.player2.weapon.img;
};

// Function to enable/ dissable the fight buttons
game.prototype.enableFightButton = function () {
const p1Attack = document.getElementById("P1Attack");
const p2Attack = document.getElementById("P2Attack");
Expand All @@ -464,6 +465,7 @@
p1Defend.classList.add('disabled')
}
}
// Function to set the action buttons
game.prototype.createActionButtonsEvents = function() {
const $actions = Array.from(document.querySelectorAll(".action"));
$actions.forEach(($action) => {
Expand Down Expand Up @@ -499,6 +501,7 @@
});

}
// Function that performs calculations on fight and defend buttons
game.prototype.performAction = function(action) {
switch (action.type) {
case "attack":
Expand All @@ -524,6 +527,7 @@
this.enableFightButton()

}
// Function that initiates the fight sequence
game.prototype.tryFight = function() {
const self = this;
if (!self.isReadyToFight()){
Expand All @@ -532,7 +536,7 @@
self.enableFightButton()
self.removeShowMove()
};

// button to start a new game and rules
$(window).on("load", function() {
document.getElementById("newGameBtn").addEventListener("click", function() {
const newGame = new game();
Expand Down

0 comments on commit 4ec75ad

Please sign in to comment.