Add OppBoard, and draw using itemdata

develop
Nathan Steel 1 year ago
parent 59a6614607
commit 158bd627c7

@ -85,6 +85,8 @@ class Board{
this.drawPlayerNames('Nathan', 'Evil Nathan');
this.drawCardsECS(); // Atop most everything atm for testing
if(gameWin){
this.drawWin();
}
@ -122,6 +124,61 @@ class Board{
}
}
drawCardsECS(){
// Loop all items
for(let itemKey = 0; itemKey < item.length; itemKey++){
// Check if item is not in deck, deck items aren't to be drawn
// 'key' in 'object'
if(itemKey in boardElement && boardElement[itemKey] != 'deck'){
// Check if item belongs to opponent for now
// this will just be used to set positioning in the future
if(itemKey in player && player[itemKey] == 1){
// Just for opponentBoard atm
// This method will need to draw all cards, calcing their positions
// Which sounds hard
let opponentBoardLength = getCurrentPositionAndLength('board', 1)[1];
// I know it's redundant, just need to get my head around it all
// Setting position, will be moved elsewhere when working fully
let cardPadding = 10;
let i = listPosition[itemKey];
console.log('cardName: '+cardData[itemKey].name);
console.log('i/listPosition: '+i);
console.log('boardLength: '+opponentBoardLength);
let positionX = canvas.width/2 - (cardWidth * (opponentBoardLength - i) - (cardPadding * i));
console.log('posX: '+positionX);
let positionY = cardHeight + 30;
let width = cardWidth;
let height = cardHeight;
position[itemKey] = [positionX,positionY];
size[itemKey] = [width, height];
// Check status (for tapped atm)
let border = null;
if(cardStatus[itemKey] == 'tapped'){border = '#E0BC00';}
let name = itemKey; // Not needed really anymore, but keeping for now
positionX = position[itemKey][0];
positionY = position[itemKey][1];
width = size[itemKey][0];
height = size[itemKey][1];
let fill = '#CCC';
let shape = new Shape({
name: name,
x: positionX,
y: positionY,
width: width,
height: height,
fillStyle: fill,
strokeStyle: border
});
shape.draw();
}
}
}
}
// Draw Invidual Cards, called by other deck stuff
// Might be put into a card class, makes sense, eh.
drawCard(array, arrayKey, name, positionX, positionY, width, height, fill, border){
@ -364,6 +421,8 @@ class Board{
}
drawCardsOnBoardOpponent(){
// OLD, being rewritten
if(true){
for (let i = 0; i < opponentBoard.length; i++) {
let name = 'cardOnBoardOpponent_'+(i+1);
@ -380,6 +439,7 @@ class Board{
this.drawCard(opponentBoard, i, name, positionX, positionY, width, height, fill);
}
}
}
// Currently only functionality in hand
playCardToBoard(index){
@ -435,6 +495,11 @@ class Board{
}
playCardToBoardFromDeckOpponent(){
if(opponentBoard.length >= maxBoardSize){
alert('No space on board to play card. '+opponentBoard.length+'/'+maxBoardSize);
return 0;
}
// Loop items for opponent deck. boardElement = deck, and player = 1
for(let itemKey = 0; itemKey < item.length; itemKey++){
// Check if item is in deck
@ -443,31 +508,19 @@ class Board{
// Check if item belongs to opponent
if(itemKey in player && player[itemKey] == 1){
// Check list position for top of deck
if(listPosition[itemKey] == 0){
// Set the new position (on board)
listPosition[itemKey] = getCurrentPositionAndLength('board', 1)[0]+1
// Move from current item to board
boardElement[itemKey] = 'board';
}
else{
// Move all other items in deck down in position by 1 to get new 0
listPosition[itemKey]--;
}
}
}
// 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];
if(opponentBoard.length >= maxBoardSize){
alert('No space on board to play card. '+opponentBoard.length+'/'+maxBoardSize);
return 0;
}
// Remove from deck
opponentDeck.splice(cardToDraw, 1);
// Add to board
opponentBoard.push(cardPlayed);
this.drawBoard();
}
@ -680,11 +733,12 @@ createDeckList(opponentDeck, deckCountOpponent, 1);
// Run board commands here for testing
let board = new Board;
//board.initBoard();
shuffleDeck(0);
shuffleDeck(1);
//shuffleDeck(0);
//shuffleDeck(1);
// TEMP: Play a card on opponents board (from their deck)
board.playCardToBoardFromDeckOpponent();
board.playCardToBoardFromDeckOpponent();
board.drawBoard();
@ -896,7 +950,7 @@ function shuffleDeck(playerId){
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);
//console.log(itemKey);
tempDeck.push(itemKey);
}
}
@ -904,6 +958,7 @@ function shuffleDeck(playerId){
// Temporary shuffle until algo selected/written
let id, shuffledPile, i;
console.log(tempDeck.length);
for (i = tempDeck.length - 1; i > 0; i--) {
id = Math.floor(Math.random() * (i + 1));
//shuffledPile = tempDeck[i];
@ -928,4 +983,31 @@ function untapAll(){
untap(playerBoard);
untap(opponentShield);
}
function getCurrentPositionAndLength(elementName, playerId){
let highestListPosition = 0;
let length = 0;
// Loop all the items
// Think making the for loop, and the if into something to be called that fires functions would be smart?
for(let itemKey = 0; itemKey < item.length; itemKey++){
// Check the item is the correct boardElement
// 'key' in 'object'
if(itemKey in boardElement && boardElement[itemKey] == elementName){
// Check if item belongs to the player
if(itemKey in player && player[itemKey] == playerId){
if(listPosition[itemKey]){
if(listPosition[itemKey] >= highestListPosition){
highestListPosition = listPosition[itemKey];
length++;
}
}
}
}
}
return [highestListPosition, length];
}

Loading…
Cancel
Save