Add attackShield functionality, and win screen

develop
Nathan Steel 1 year ago
parent 8f2a93f58f
commit bb7c87f131

@ -35,6 +35,7 @@ const maxShield = 4;
let inspectCard = null; let inspectCard = null;
let attackingCard = null; let attackingCard = null;
let gameWin = 0;
// Gonna need lots of refactoring, and sorting // Gonna need lots of refactoring, and sorting
class Board{ class Board{
@ -67,9 +68,31 @@ class Board{
this.drawPlayerNames('Nathan', 'Evil Nathan'); this.drawPlayerNames('Nathan', 'Evil Nathan');
if(gameWin){
this.drawWin();
}
this.drawInspectedCard(); this.drawInspectedCard();
} }
drawWin(){
var winBoard = new Shape({
name: name,
x: 0,
y: canvas.height/2 - (canvas.height/4)/2,
width: canvas.width,
height: canvas.height/4,
fillStyle: '#CCC',
strokeStyle: '#00EEAA'
});
winBoard.draw();
ctx.fillStyle = '#000';
ctx.font = "bold 50pt Arial";
ctx.fillText('WINNER', 200, 300);
ctx.font = "10pt Arial";
}
drawPlayerNames(playerName, opponentName = false){ drawPlayerNames(playerName, opponentName = false){
// Player Name // Player Name
ctx.fillText(playerName, 50, canvas.height - 50); ctx.fillText(playerName, 50, canvas.height - 50);
@ -400,12 +423,13 @@ class Board{
this.drawBoard(); this.drawBoard();
} }
// Do the attack // Do the attack
makeAttack(index){ makeAttack(index, array = null){
if(array == null){ array = opponentBoard; }
// If card attacked // If card attacked
// Compare attackingCard and defendingCard // Compare attackingCard and defendingCard
let defendingCard = opponentBoard[index]; let defendingCard = array[index];
if(defendingCard.atk <= attackingCard[0].atk){ if(defendingCard.atk <= attackingCard[0].atk){
opponentBoard.splice(index, 1); array.splice(index, 1);
// Need to push to grave, etc. here in future too // Need to push to grave, etc. here in future too
} }
if(attackingCard[0].atk <= defendingCard.atk){ if(attackingCard[0].atk <= defendingCard.atk){
@ -419,6 +443,9 @@ class Board{
} }
endAttack(){ endAttack(){
attackingCard = null; attackingCard = null;
if(opponentShield.length <= 0){
gameWin = 1;
}
this.drawBoard(); this.drawBoard();
} }
@ -534,7 +561,7 @@ canvas.addEventListener('click', function(event) {
// is being done, attack needs to be made, inspecting card. // is being done, attack needs to be made, inspecting card.
// Prevents user from doing other actions until completed or cancelled event // Prevents user from doing other actions until completed or cancelled event
let specialEvent = false; let specialEvent = false;
if(inspectCard !== null || attackingCard !== null){ if(inspectCard !== null || attackingCard !== null || gameWin){
specialEvent = true; specialEvent = true;
} }
@ -627,6 +654,18 @@ canvas.addEventListener('click', function(event) {
board.drawBoard(); board.drawBoard();
} }
}); });
// # OPPONENT SHIELD
opponentShield.forEach(function(card, index){
let clickable = card.clickable;
if(clickableCheck(x,y,clickable)){
// Check if card if getting attacked
if(attackingCard !== null){
board.makeAttack(index, opponentShield);
}
board.drawBoard();
}
});
}, false); }, false);

Loading…
Cancel
Save