Move drawDecks to one method, Fix deck counter

develop
Nathan Steel 1 year ago
parent 5d059aedeb
commit 0c5b52aded

@ -83,8 +83,7 @@ class Board{
this.drawCardsOnBoard(); this.drawCardsOnBoard();
this.drawCardsOnBoardOpponent(); this.drawCardsOnBoardOpponent();
this.drawDeck(); this.drawDecks();
this.drawDeckOpponent();
this.drawShield(); this.drawShield();
this.drawShieldOpponent(); this.drawShieldOpponent();
@ -360,58 +359,100 @@ class Board{
ctx.font = "10pt Arial"; ctx.font = "10pt Arial";
} }
drawDeck(){ drawDecks(){
// Deck // Draw all decks belonging to players (currently 2, could be 3-5 in future, for PvE raids)
clickableItems['deckSprite'] = new Shape({ // TODO: Probably add this as an item of boardElement 'realDeck', as 'deck' is cards in deck
name: 'deck', // actually, maybe change current 'deck' to 'inDeck', reads better
x: canvas.width-cardWidth*1.5-40, let name = null;
y: canvas.height-cardHeight*1.5-60, let countername = null;
width: cardWidth*1.5, let x = null;
height: cardHeight*1.5, let counterx = null;
fillStyle: "#0000FF" let y = null;
}); let countery = null;
//ctx.fillRect(canvas.width-cardWidth/2-60, canvas.height/2-cardHeight/4, cardWidth/2, cardHeight/2); let width = null;
clickableItems['deckSprite'].draw(); let counterwidth = null;
let deckCounterSprite = new Shape({ let height = null;
shape: 'circle', let counterheight = null;
name: 'deckCounter', let fill = null;
x: canvas.width-cardWidth*.6, let counterfill = '#FFF';
y: canvas.height-cardHeight*.6, let textx = null;
width: cardWidth*.375, let texty = null;
height: cardHeight*.375, let deckLength = 0;
fillStyle: "#FFF"
}); for(let playerId = 0; playerId < players; playerId++){
deckCounterSprite.draw(); if(playerId == 0){
// Deck
name= 'deck';
x= canvas.width-cardWidth*1.5-40;
y= canvas.height-cardHeight*1.5-60;
width= cardWidth*1.5;
height= cardHeight*1.5;
fill= "#0000FF";
countername= 'deckCounter';
counterx= canvas.width-cardWidth*.6;
countery= canvas.height-cardHeight*.6;
counterwidth= cardWidth*.375;
counterheight= cardHeight*.375;
// TODO: Center in the circle
deckLength = getCurrentPositionAndLength('deck', 0)[1];
textx = canvas.width-cardWidth*.6 - (ctx.measureText(deckLength).width) + 7;
texty = canvas.height-cardHeight*.6 + 5;
}
if(playerId == 1){
// Opponent's Deck
name= 'deckOpponent';
x= 40;
y= 60;
width= cardWidth*1.5;
height= cardHeight*1.5;
fill= "#FF0000";
countername= 'deckCounterOpponent';
counterx= cardWidth*1.5+(cardWidth*.375);
countery= cardHeight*1.5+(cardHeight*.375);
counterwidth= cardWidth*.375;
counterheight= cardHeight*.375;
counterfill= "#FFF";
deckLength = getCurrentPositionAndLength('deck', 1)[1];
textx=cardWidth*1.5 + (ctx.measureText(deckLength).width) + 10;
texty=cardHeight*1.9;
// TODO: Center in the circle }
ctx.fillStyle = '#000';
ctx.fillText(playerDeck.length, canvas.width-cardWidth*.6 - (ctx.measureText(playerDeck.length).width) + 7, canvas.height-cardHeight*.6 + 5); // Actually draw the decks base on the size/position, etc.
} clickableItems[name+'Sprite'] = new Shape({
drawDeckOpponent(){ name: name,
// Opponent's Deck x: x,
clickableItems['deckOpponentSprite'] = new Shape({ y: y,
name: 'deckOpponent', width: width,
x: 40, height: height,
y: 60, fillStyle: fill
width: cardWidth*1.5, });
height: cardHeight*1.5, //ctx.fillRect(canvas.width-cardWidth/2-60, canvas.height/2-cardHeight/4, cardWidth/2, cardHeight/2);
fillStyle: "#FF0000" clickableItems[name+'Sprite'].draw();
});
clickableItems['deckOpponentSprite'].draw(); // Draw circle for deck count to sit in
let deckCounterOpponentSprite = new Shape({ let deckCounterSprite = new Shape({
shape: 'circle', shape: 'circle',
name: 'deckCounterOpponent', name: countername,
x: cardWidth*1.5+(cardWidth*.375), x: counterx,
y: cardHeight*1.5+(cardHeight*.375), y: countery,
width: cardWidth*.375, width: counterwidth,
height: cardHeight*.375, height: counterheight,
fillStyle: "#FFF" fillStyle: counterfill
}); });
deckCounterOpponentSprite.draw(); console.log(deckCounterSprite);
deckCounterSprite.draw();
// Draw deck count text
// TODO: Center in the circle
ctx.fillStyle = '#000';
ctx.fillText(deckLength, textx, texty);
}
ctx.fillStyle = '#000';
// TODO: Center in the circle
ctx.fillText(opponentDeck.length, cardWidth*1.5 + (ctx.measureText(opponentDeck.length).width) + 10, cardHeight*1.9);
} }
addFromBoardElement(playerFrom, fromPosition, elementFrom, elementTo, toPosition=null, playerTo=null){ addFromBoardElement(playerFrom, fromPosition, elementFrom, elementTo, toPosition=null, playerTo=null){

Loading…
Cancel
Save