|
|
|
@ -30,6 +30,8 @@ let cardsInOpponentsHand = 0;
|
|
|
|
const maxHandSize = 4;
|
|
|
|
const maxHandSize = 4;
|
|
|
|
const maxBoardSize = 3;
|
|
|
|
const maxBoardSize = 3;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let inspectCard = null;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Gonna need lots of refactoring, and sorting
|
|
|
|
// Gonna need lots of refactoring, and sorting
|
|
|
|
class Board{
|
|
|
|
class Board{
|
|
|
|
@ -58,6 +60,8 @@ class Board{
|
|
|
|
this.drawOpponentHand();
|
|
|
|
this.drawOpponentHand();
|
|
|
|
|
|
|
|
|
|
|
|
this.drawPlayerNames('Nathan', 'Evil Nathan');
|
|
|
|
this.drawPlayerNames('Nathan', 'Evil Nathan');
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
this.drawInspectedCard();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
drawPlayerNames(playerName, opponentName = false){
|
|
|
|
drawPlayerNames(playerName, opponentName = false){
|
|
|
|
@ -300,6 +304,23 @@ class Board{
|
|
|
|
|
|
|
|
|
|
|
|
this.drawBoard();
|
|
|
|
this.drawBoard();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
inspectOpponentBoard(index){
|
|
|
|
|
|
|
|
// Get the card data
|
|
|
|
|
|
|
|
inspectCard = [opponentBoard, index];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
this.drawBoard();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
drawInspectedCard(){
|
|
|
|
|
|
|
|
if(inspectCard != null){
|
|
|
|
|
|
|
|
let positionX = canvas.width/2 - cardWidth;
|
|
|
|
|
|
|
|
let positionY = canvas.height/2 - cardHeight;
|
|
|
|
|
|
|
|
let width = cardWidth*2;
|
|
|
|
|
|
|
|
let height = cardHeight*2;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
this.drawCard(inspectCard[0], inspectCard[1], name, positionX, positionY, width, height, '#D1D100');
|
|
|
|
|
|
|
|
console.log('inspect');
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// TEMP!!
|
|
|
|
// TEMP!!
|
|
|
|
@ -316,12 +337,31 @@ board.playCardToBoardFromDeckOpponent();
|
|
|
|
board.drawBoard();
|
|
|
|
board.drawBoard();
|
|
|
|
|
|
|
|
|
|
|
|
canvas.addEventListener('click', function(event) {
|
|
|
|
canvas.addEventListener('click', function(event) {
|
|
|
|
|
|
|
|
console.log('EVENT LISTENER');
|
|
|
|
|
|
|
|
console.log('');
|
|
|
|
|
|
|
|
|
|
|
|
var x = event.pageX - canvasLeft,
|
|
|
|
var x = event.pageX - canvasLeft,
|
|
|
|
y = event.pageY - canvasTop;
|
|
|
|
y = event.pageY - canvasTop;
|
|
|
|
|
|
|
|
|
|
|
|
// Collision detection between clicked offset and clickableItems
|
|
|
|
// Collision detection between clicked offset and clickableItems
|
|
|
|
// https://stackoverflow.com/a/9880302
|
|
|
|
// https://stackoverflow.com/a/9880302
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(inspectCard != null){
|
|
|
|
|
|
|
|
console.log(inspectCard);
|
|
|
|
|
|
|
|
clickable = inspectCard[0][inspectCard[1]].clickable;
|
|
|
|
|
|
|
|
console.log(clickable);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(clickableCheck(x,y,clickable)){
|
|
|
|
|
|
|
|
console.log('clicked inspect card');
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}else{
|
|
|
|
|
|
|
|
console.log('not inspected card');
|
|
|
|
|
|
|
|
// Stop inspecting card if player clicks off it
|
|
|
|
|
|
|
|
inspectCard = null;
|
|
|
|
|
|
|
|
board.drawBoard();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// # PLAYER DECK
|
|
|
|
// # PLAYER DECK
|
|
|
|
clickable = clickableItems['deckSprite'];
|
|
|
|
clickable = clickableItems['deckSprite'];
|
|
|
|
|
|
|
|
|
|
|
|
@ -358,6 +398,25 @@ canvas.addEventListener('click', function(event) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// # PLAYER BOARD
|
|
|
|
|
|
|
|
playerBoard.forEach(function(card, index){
|
|
|
|
|
|
|
|
let clickable = card.clickable;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(clickableCheck(x,y,clickable)){
|
|
|
|
|
|
|
|
board.startAttack(index);
|
|
|
|
|
|
|
|
board.drawBoard();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// # OPPONENT BOARD
|
|
|
|
|
|
|
|
opponentBoard.forEach(function(card, index){
|
|
|
|
|
|
|
|
let clickable = card.clickable;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(clickableCheck(x,y,clickable)){
|
|
|
|
|
|
|
|
board.inspectOpponentBoard(index);
|
|
|
|
|
|
|
|
board.drawBoard();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
}, false);
|
|
|
|
}, false);
|
|
|
|
|
|
|
|
|
|
|
|
|