Add listPosition component, and shuffle mechanic

develop
Nathan Steel 1 year ago
parent f753d5d3df
commit 59a6614607

@ -27,6 +27,7 @@ let size = {};
//let shape = {};
let cardStatus = {}; // tapped, attacking, inspected, untargettable
let player = {};
let listPosition = {};
let playerHand = [];
let opponentHand = [];
@ -433,6 +434,27 @@ class Board{
this.drawBoard();
}
playCardToBoardFromDeckOpponent(){
// Loop items for opponent deck. boardElement = deck, and player = 1
for(let itemKey = 0; itemKey < item.length; itemKey++){
// Check if item is in deck
// 'key' in 'object'
if(itemKey in boardElement && boardElement[itemKey] == 'deck'){
// Check if item belongs to opponent
if(itemKey in player && player[itemKey] == 1){
// Check list position for top of deck
}
}
}
// Select card from top of deck?
// Switch the item boardElement from deck->board
// not for here: if player = 1 and boardElement = board draw it
//
// Random card from deck
let cardToDraw = Math.floor(Math.random() * deckCount);
let cardPlayed = opponentDeck[cardToDraw];
@ -658,6 +680,8 @@ createDeckList(opponentDeck, deckCountOpponent, 1);
// Run board commands here for testing
let board = new Board;
//board.initBoard();
shuffleDeck(0);
shuffleDeck(1);
// TEMP: Play a card on opponents board (from their deck)
board.playCardToBoardFromDeckOpponent();
@ -840,7 +864,7 @@ function createDeckList(deck, deckCount, playerId){
if(effect == 0){ effect = 'effect here'; } else{ effect = null }
item.push[itemCount];
item.push(itemCount);
boardElement[itemCount] = 'deck';
cardData[itemCount] = {
'name':'CardName '+(i+1)
@ -853,7 +877,8 @@ function createDeckList(deck, deckCount, playerId){
, 'colour':colour
, 'tapped':false
};
player[playerId];
player[itemCount] = playerId;
listPosition[itemCount] = i;
// Previous iteration, kept to prevent errors for now
deck.push(cardData[itemCount]);
@ -861,6 +886,36 @@ function createDeckList(deck, deckCount, playerId){
}
}
function shuffleDeck(playerId){
let tempDeck = [];
for(let itemKey = 0; itemKey < item.length; itemKey++){
// Check if item is in deck
// 'key' in 'object'
if(itemKey in boardElement && boardElement[itemKey] == 'deck'){
// Check if item belongs to opponent
if(itemKey in player && player[itemKey] == playerId){
// This will shuffle, but not from OG deck state.
// Will need to get the listPosition and order by that first
console.log(itemKey);
tempDeck.push(itemKey);
}
}
}
// Temporary shuffle until algo selected/written
let id, shuffledPile, i;
for (i = tempDeck.length - 1; i > 0; i--) {
id = Math.floor(Math.random() * (i + 1));
//shuffledPile = tempDeck[i];
//tempDeck[i] = tempDeck[id];
//tempDeck[id] = shuffledPile;
// Change the position within the deck
listPosition[tempDeck[id]] = i;
}
}
function untap(array){
console.log(array);
array.forEach(function(card, key){

Loading…
Cancel
Save