|
|
|
|
@ -469,6 +469,8 @@ class Board{
|
|
|
|
|
// Move itemKey fromPosition in elementFrom to toPosition in elementTo
|
|
|
|
|
// 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++){
|
|
|
|
|
// Get the item from the element
|
|
|
|
|
if(itemKey in boardElement && boardElement[itemKey] == elementFrom){
|
|
|
|
|
@ -539,53 +541,31 @@ class Board{
|
|
|
|
|
}
|
|
|
|
|
// Draw a card, traditional TCG
|
|
|
|
|
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++){
|
|
|
|
|
if(playerHand.length >= maxHandSize){
|
|
|
|
|
alert('Hand full '+playerHand.length+'/'+maxHandSize);
|
|
|
|
|
// Check there's space in hand
|
|
|
|
|
// TODO: Normalise this for all element/player combos
|
|
|
|
|
let elementLength = getCurrentPositionAndLength('hand', 0)[1];
|
|
|
|
|
if(elementLength >= maxHandSize){
|
|
|
|
|
alert('Hand full '+elementLength+'/'+maxHandSize);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Random card from deck, remove from deck, add to hand
|
|
|
|
|
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();
|
|
|
|
|
}
|
|
|
|
|
// Move from player0, position 0 (top) of deck, to hand
|
|
|
|
|
this.addFromBoardElement(0, 0, 'deck', 'hand', null, null);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
drawACardOpponent(cardsToDraw = 1){
|
|
|
|
|
for(let draw = 0; draw < cardsToDraw; draw++){
|
|
|
|
|
// Move from player0, position 0 (top) of deck, to hand
|
|
|
|
|
this.addFromBoardElement(1, 0, 'deck', 'hand', null, null);
|
|
|
|
|
}
|
|
|
|
|
// Move from player1, position 0 (top) of deck, to hand
|
|
|
|
|
|
|
|
|
|
if(false){
|
|
|
|
|
for(let draw = 0; draw < cardsToDraw; draw++){
|
|
|
|
|
if(opponentHand.length >= maxHandSize){
|
|
|
|
|
alert('Hand full '+opponentHand.length+'/'+maxHandSize);
|
|
|
|
|
// Check there's space in hand
|
|
|
|
|
// TODO: Normalise this for all element/player combos
|
|
|
|
|
let elementLength = getCurrentPositionAndLength('hand', 1)[1];
|
|
|
|
|
if(elementLength >= maxHandSize){
|
|
|
|
|
alert('Hand full '+elementLength+'/'+maxHandSize);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
// Random card from deck, remove from deck, add to hand
|
|
|
|
|
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();
|
|
|
|
|
}
|
|
|
|
|
this.addFromBoardElement(1, 0, 'deck', 'hand', null, null);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|