Add max hand size check ECS

develop
Nathan Steel 1 year ago
parent 9569dc8320
commit 3c1309a63a

@ -469,6 +469,8 @@ class Board{
// Move itemKey fromPosition in elementFrom to toPosition in elementTo // Move itemKey fromPosition in elementFrom to toPosition in elementTo
// Can also switch item between players // Can also switch item between players
// Loop all items, get the item with boardElement elementFrom and player playerFrom
for(let itemKey = 0; itemKey < item.length; itemKey++){ for(let itemKey = 0; itemKey < item.length; itemKey++){
// Get the item from the element // Get the item from the element
if(itemKey in boardElement && boardElement[itemKey] == elementFrom){ if(itemKey in boardElement && boardElement[itemKey] == elementFrom){
@ -539,53 +541,31 @@ class Board{
} }
// Draw a card, traditional TCG // Draw a card, traditional TCG
drawACard(cardsToDraw = 1){ drawACard(cardsToDraw = 1){
for(let draw = 0; draw < cardsToDraw; draw++){
// Move from player0, position 0 (top) of deck, to hand
this.addFromBoardElement(0, 0, 'deck', 'hand', null, null);
}
if(false){
// For loop so that animations will play each time (when they exist)
for(let draw = 0; draw < cardsToDraw; draw++){ for(let draw = 0; draw < cardsToDraw; draw++){
if(playerHand.length >= maxHandSize){ // Check there's space in hand
alert('Hand full '+playerHand.length+'/'+maxHandSize); // TODO: Normalise this for all element/player combos
let elementLength = getCurrentPositionAndLength('hand', 0)[1];
if(elementLength >= maxHandSize){
alert('Hand full '+elementLength+'/'+maxHandSize);
return 0; return 0;
} }
// Move from player0, position 0 (top) of deck, to hand
// Random card from deck, remove from deck, add to hand this.addFromBoardElement(0, 0, 'deck', 'hand', null, null);
let cardToDraw = Math.floor(Math.random() * deckCount);
let cardDrawn = playerDeck[cardToDraw];
// Remove from deck
playerDeck.splice(cardToDraw, 1);
// Add to hand
playerHand.push(cardDrawn);
this.drawBoard();
}
} }
} }
drawACardOpponent(cardsToDraw = 1){ drawACardOpponent(cardsToDraw = 1){
for(let draw = 0; draw < cardsToDraw; draw++){ for(let draw = 0; draw < cardsToDraw; draw++){
// Move from player0, position 0 (top) of deck, to hand // Move from player1, position 0 (top) of deck, to hand
this.addFromBoardElement(1, 0, 'deck', 'hand', null, null);
}
if(false){ // Check there's space in hand
for(let draw = 0; draw < cardsToDraw; draw++){ // TODO: Normalise this for all element/player combos
if(opponentHand.length >= maxHandSize){ let elementLength = getCurrentPositionAndLength('hand', 1)[1];
alert('Hand full '+opponentHand.length+'/'+maxHandSize); if(elementLength >= maxHandSize){
alert('Hand full '+elementLength+'/'+maxHandSize);
return 0; return 0;
} }
// Random card from deck, remove from deck, add to hand this.addFromBoardElement(1, 0, 'deck', 'hand', null, null);
let cardToDraw = Math.floor(Math.random() * deckCountOpponent);
let cardDrawn = opponentDeck[cardToDraw];
// Remove from deck
opponentDeck.splice(cardToDraw, 1);
// Add to hand
opponentHand.push(cardDrawn);
this.drawBoard();
}
} }
} }

Loading…
Cancel
Save