|
|
|
|
@ -148,12 +148,12 @@ class Board{
|
|
|
|
|
// Draw Elements
|
|
|
|
|
// Loop each item left, and draw if element is currently looped. board,mana,etc.
|
|
|
|
|
if(itemKey in boardElement && boardElement[itemKey] == element){
|
|
|
|
|
if(boardElement[itemKey] == 'hand' && player[itemKey] == 0){
|
|
|
|
|
console.log('PLAYER HAND');
|
|
|
|
|
if(boardElement[itemKey] == 'board' && player[itemKey] == 0){
|
|
|
|
|
console.log('PLAYER BOARD');
|
|
|
|
|
}
|
|
|
|
|
// Get the player the item belongs to
|
|
|
|
|
let itemPlayer = player[itemKey];
|
|
|
|
|
console.log('Element: '+element+', Player: '+itemPlayer);
|
|
|
|
|
//console.log('Element: '+element+', Player: '+itemPlayer);
|
|
|
|
|
|
|
|
|
|
calculateItemSizePosition(itemKey);
|
|
|
|
|
|
|
|
|
|
@ -443,7 +443,6 @@ class Board{
|
|
|
|
|
height: counterheight,
|
|
|
|
|
fillStyle: counterfill
|
|
|
|
|
});
|
|
|
|
|
console.log(deckCounterSprite);
|
|
|
|
|
deckCounterSprite.draw();
|
|
|
|
|
|
|
|
|
|
// Draw deck count text
|
|
|
|
|
@ -478,7 +477,7 @@ class Board{
|
|
|
|
|
toPosition = getCurrentPositionAndLength(elementTo, playerTo)[0]+1
|
|
|
|
|
//console.log(toPosition);
|
|
|
|
|
}
|
|
|
|
|
//console.log('itemKey: '+itemKey+' fromPosition: '+fromPosition+' elementFrom: '+elementFrom+' toPosition: '+toPosition+' playerFrom: '+playerFrom+' playerTo: '+playerTo);
|
|
|
|
|
console.log('itemKey: '+itemKey+' fromPosition: '+fromPosition+' elementFrom: '+elementFrom+' elementTo: '+elementTo+' toPosition: '+toPosition+' playerFrom: '+playerFrom+' playerTo: '+playerTo);
|
|
|
|
|
listPosition[itemKey] = toPosition;
|
|
|
|
|
|
|
|
|
|
// Move from elementFrom to elementTo
|
|
|
|
|
@ -489,7 +488,11 @@ class Board{
|
|
|
|
|
//console.log(boardElement[itemKey]);
|
|
|
|
|
|
|
|
|
|
// Move down(0) the positions of elementFrom, from fromPosition for player
|
|
|
|
|
console.log(JSON.stringify(boardElement));
|
|
|
|
|
console.log(JSON.stringify(listPosition));
|
|
|
|
|
this.moveElementPositions(0, elementFrom, fromPosition, playerFrom);
|
|
|
|
|
console.log(JSON.stringify(boardElement));
|
|
|
|
|
console.log(JSON.stringify(listPosition));
|
|
|
|
|
this.drawBoard();
|
|
|
|
|
return 1; // Got a loop that calls a loop, and checks the new values atm, so this keeps counting down
|
|
|
|
|
|
|
|
|
|
@ -587,18 +590,36 @@ class Board{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Currently only functionality in hand
|
|
|
|
|
playCardToBoard(index){
|
|
|
|
|
playCardToBoard(positionInHand, cardsToPlay = 1){
|
|
|
|
|
|
|
|
|
|
console.log(positionInHand);
|
|
|
|
|
// Loop probably not needed, but may be for eg. 'play X cards from top of deck'
|
|
|
|
|
for(let play = 0; play < cardsToPlay; play++){
|
|
|
|
|
// Check there's space on board TODO: change to locationTo
|
|
|
|
|
// TODO: Normalise this for all element/player combos
|
|
|
|
|
let elementLength = getCurrentPositionAndLength('board', 0)[1];
|
|
|
|
|
if(elementLength >= maxHandSize){
|
|
|
|
|
alert('Board full '+elementLength+'/'+maxHandSize);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
// When done remove false &&
|
|
|
|
|
// TODO: Rewrite for ECS
|
|
|
|
|
// Mana cost required and mana tapping
|
|
|
|
|
if(false && cardPlayed.cost > playerMana.length){
|
|
|
|
|
alert('Not enough mana');
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Move from player0, position 0 (top) of deck, to hand
|
|
|
|
|
this.addFromBoardElement(0, positionInHand, 'hand', 'board', null, null);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(false){
|
|
|
|
|
// Get the card data
|
|
|
|
|
let cardPlayed = playerHand[index];
|
|
|
|
|
let manaUsed = [];
|
|
|
|
|
|
|
|
|
|
// Check if there's space on board to play
|
|
|
|
|
// TODO: Check this in back-end
|
|
|
|
|
if(playerBoard.length >= maxBoardSize){
|
|
|
|
|
alert('No space on board to play card. '+playerBoard.length+'/'+maxBoardSize);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(cardPlayed.cost > playerMana.length){
|
|
|
|
|
alert('Not enough mana');
|
|
|
|
|
return 0;
|
|
|
|
|
@ -635,6 +656,7 @@ class Board{
|
|
|
|
|
playerHand.splice(index, 1);
|
|
|
|
|
// Add to board
|
|
|
|
|
playerBoard.push(cardPlayed);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
this.drawBoard();
|
|
|
|
|
}
|
|
|
|
|
@ -882,8 +904,8 @@ let board = new Board;
|
|
|
|
|
//shuffleDeck(1);
|
|
|
|
|
|
|
|
|
|
// TEMP: Play a card on opponents board (from their deck)
|
|
|
|
|
board.playCardToBoardFromDeckOpponent();
|
|
|
|
|
board.playCardToBoardFromDeckOpponent();
|
|
|
|
|
//board.playCardToBoardFromDeckOpponent();
|
|
|
|
|
//board.playCardToBoardFromDeckOpponent();
|
|
|
|
|
|
|
|
|
|
//board.drawBoard();
|
|
|
|
|
|
|
|
|
|
@ -891,7 +913,7 @@ board.playShield(4);
|
|
|
|
|
board.playShieldOpponent(4);
|
|
|
|
|
|
|
|
|
|
board.drawBoard(true);
|
|
|
|
|
board.drawACard(3);
|
|
|
|
|
//board.drawACard(3);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
canvas.addEventListener('contextmenu', function(event) {
|
|
|
|
|
@ -992,7 +1014,8 @@ canvas.addEventListener('click', function(event) {
|
|
|
|
|
cardStatus[itemKey] = 'tapped';
|
|
|
|
|
case 'hand':
|
|
|
|
|
// Can be played
|
|
|
|
|
//board.playCardToBoard(index);
|
|
|
|
|
// Play from item listPosition, 1 card
|
|
|
|
|
board.playCardToBoard(listPosition[itemKey], 1);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
@ -1039,6 +1062,7 @@ canvas.addEventListener('click', function(event) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// # PLAYER HAND
|
|
|
|
|
if(false){
|
|
|
|
|
playerHand.forEach(function(card, index){
|
|
|
|
|
|
|
|
|
|
let clickable = card.clickable;
|
|
|
|
|
@ -1054,6 +1078,7 @@ canvas.addEventListener('click', function(event) {
|
|
|
|
|
board.drawBoard();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// # PLAYER BOARD
|
|
|
|
|
playerBoard.forEach(function(card, index){
|
|
|
|
|
@ -1107,13 +1132,13 @@ function clickableCheck(x,y,clickable=false,itemKey=false){
|
|
|
|
|
// simultaneously. It works, so that's nice
|
|
|
|
|
if(clickable === false && itemKey !== false){
|
|
|
|
|
clickable = {};
|
|
|
|
|
console.log(clickable);
|
|
|
|
|
console.log(itemKey);
|
|
|
|
|
//console.log(clickable);
|
|
|
|
|
//console.log(itemKey);
|
|
|
|
|
clickable.x = position[itemKey][0];
|
|
|
|
|
clickable.y = position[itemKey][1];
|
|
|
|
|
clickable.width = size[itemKey][0];
|
|
|
|
|
clickable.height = size[itemKey][1];
|
|
|
|
|
console.log(clickable);
|
|
|
|
|
//console.log(clickable);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Debug Stuff
|
|
|
|
|
@ -1257,7 +1282,7 @@ function calculateItemSizePosition(itemKey){
|
|
|
|
|
let height = 0;
|
|
|
|
|
|
|
|
|
|
let i = listPosition[itemKey];
|
|
|
|
|
console.log('cardName: '+cardData[itemKey].name+' listPosition/i: '+i);
|
|
|
|
|
//console.log('cardName: '+cardData[itemKey].name+' listPosition/i: '+i);
|
|
|
|
|
|
|
|
|
|
if(itemPlayer == 1 && itemElement == 'board'){
|
|
|
|
|
positionX = canvas.width/2 - (cardWidth * (itemListLength - i) - (cardPadding * i));
|
|
|
|
|
@ -1271,6 +1296,12 @@ function calculateItemSizePosition(itemKey){
|
|
|
|
|
width = cardWidth;
|
|
|
|
|
height = cardHeight;
|
|
|
|
|
}
|
|
|
|
|
if(itemPlayer == 0 && itemElement == 'board'){
|
|
|
|
|
positionX = canvas.width/2 - (cardWidth * (itemListLength - (i+1)) - (cardPadding * (i+1)));
|
|
|
|
|
positionY = canvas.height - cardHeight-30-(cardHeight);
|
|
|
|
|
width = cardWidth;
|
|
|
|
|
height = cardHeight;
|
|
|
|
|
}
|
|
|
|
|
if(itemPlayer == 0 && itemElement == 'hand'){
|
|
|
|
|
positionX = canvas.width/2 - (cardWidth * (itemListLength - (i+1)) - (cardPadding * (i+1)));
|
|
|
|
|
positionY = canvas.height-cardWidth*1.5-20;
|
|
|
|
|
|