Play card from hand to board

develop
Nathan Steel 1 year ago
parent e7ea3b2b88
commit c89640e33a

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

Loading…
Cancel
Save