diff --git a/public/board.js b/public/board.js index 7149b1b..1e5cedf 100644 --- a/public/board.js +++ b/public/board.js @@ -743,10 +743,38 @@ class Board{ // Sets the listPosition to the next in line for new boardElement // Changes the listPosition of each item in previous boardElement // All for same player, although below playerFrom/playerTo can be set to switch between players - // TODO: Removes any cardStatus + + // TODO:Check if shield can be destroyed (instantly, i.e. poisontouch, or some mechanic/spell akin) + // Check the shield is not tapped, if not can't be destroyed + if(!this.isTapped(itemKey)){ + alert('Shield not tapped, cannot be destroyed'); + return false; + } + // Check if all other shields are tapped before destroying the shield + // TODO: Normalise the loop!!! + // Think this can be done by looping what's needed, then returning itemKeys in array for each + // item that hits criteria, then looping that new array and applying logic? + + // 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] == 'shield'){ + // Check each shield on the board of the owner of shield being attacked + if(itemKey in player && player[itemKey] == player[itemKey]){ + // If ANY of their shields are untapped, you can't destroy target + if(cardStatus[itemKey] != 'tapped'){ + alert('There is an untapped shield, cannot destroy target'); + return false; + } + } + } + } + + // Shield is now destroyed, move it from shield to owners hand (for the catchup mechanic) //addFromBoardElement(playerFrom, fromPosition, elementFrom, elementTo, toPosition=null, playerTo=null) this.addFromBoardElement(player[itemKey], listPosition[itemKey], boardElement[itemKey], 'hand', null, null); + return true; } sendToGrave(itemKey){ @@ -771,6 +799,10 @@ class Board{ // TODO: Remove status of card, and do/don't do effect depending on locationTo/locationFrom? cardStatus[itemKey] = null; } + isTapped(itemKey){ + if(cardStatus[itemKey] == 'tapped'){ return true; } + return false; + } } // TODO: TEMP!! Replace soon