|
|
|
@ -8,7 +8,6 @@ const cardHeight = 360;
|
|
|
|
const cards = new Image();
|
|
|
|
const cards = new Image();
|
|
|
|
const back = new Image();
|
|
|
|
const back = new Image();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let clickableItems = [];
|
|
|
|
let clickableItems = [];
|
|
|
|
clickableItems['hand'] = [];
|
|
|
|
clickableItems['hand'] = [];
|
|
|
|
clickableItems['opponentHand'] = [];
|
|
|
|
clickableItems['opponentHand'] = [];
|
|
|
|
@ -18,6 +17,8 @@ let playerHand = [];
|
|
|
|
let opponentHand = [];
|
|
|
|
let opponentHand = [];
|
|
|
|
let playerBoard = [];
|
|
|
|
let playerBoard = [];
|
|
|
|
let opponentBoard = [];
|
|
|
|
let opponentBoard = [];
|
|
|
|
|
|
|
|
let playerDeck = [];
|
|
|
|
|
|
|
|
let opponentDeck = [];
|
|
|
|
|
|
|
|
|
|
|
|
let deckCount = 60;
|
|
|
|
let deckCount = 60;
|
|
|
|
let deckCountOpponent = 60;
|
|
|
|
let deckCountOpponent = 60;
|
|
|
|
@ -87,8 +88,10 @@ class Board{
|
|
|
|
fillStyle: "#FFF"
|
|
|
|
fillStyle: "#FFF"
|
|
|
|
});
|
|
|
|
});
|
|
|
|
deckCounterSprite.draw();
|
|
|
|
deckCounterSprite.draw();
|
|
|
|
|
|
|
|
|
|
|
|
// TODO: Center in the circle
|
|
|
|
// TODO: Center in the circle
|
|
|
|
ctx.fillText(deckCount, canvas.width-cardWidth/5 - (ctx.measureText(deckCount).width) + 7, canvas.height-cardHeight/5 + 5);
|
|
|
|
ctx.fillStyle = '#000';
|
|
|
|
|
|
|
|
ctx.fillText(playerDeck.length, canvas.width-cardWidth/5 - (ctx.measureText(playerDeck.length).width) + 7, canvas.height-cardHeight/5 + 5);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
drawDeckOpponent(){
|
|
|
|
drawDeckOpponent(){
|
|
|
|
// Opponent's Deck
|
|
|
|
// Opponent's Deck
|
|
|
|
@ -101,7 +104,7 @@ class Board{
|
|
|
|
fillStyle: "#FF0000"
|
|
|
|
fillStyle: "#FF0000"
|
|
|
|
});
|
|
|
|
});
|
|
|
|
clickableItems['deckOpponentSprite'].draw();
|
|
|
|
clickableItems['deckOpponentSprite'].draw();
|
|
|
|
let deckCounterSprite = new Shape({
|
|
|
|
let deckCounterOpponentSprite = new Shape({
|
|
|
|
shape: 'circle',
|
|
|
|
shape: 'circle',
|
|
|
|
name: 'deckCounterOpponent',
|
|
|
|
name: 'deckCounterOpponent',
|
|
|
|
x: cardWidth/2+(cardWidth/8),
|
|
|
|
x: cardWidth/2+(cardWidth/8),
|
|
|
|
@ -110,12 +113,11 @@ class Board{
|
|
|
|
height: cardHeight/8,
|
|
|
|
height: cardHeight/8,
|
|
|
|
fillStyle: "#FFF"
|
|
|
|
fillStyle: "#FFF"
|
|
|
|
});
|
|
|
|
});
|
|
|
|
deckCounterSprite.draw();
|
|
|
|
deckCounterOpponentSprite.draw();
|
|
|
|
|
|
|
|
|
|
|
|
ctx.fillStyle = '#000';
|
|
|
|
ctx.fillStyle = '#000';
|
|
|
|
ctx.strokeStyle = '#000';
|
|
|
|
|
|
|
|
// TODO: Center in the circle
|
|
|
|
// TODO: Center in the circle
|
|
|
|
ctx.fillText(deckCountOpponent, cardWidth/2 + (ctx.measureText(deckCount).width) + 10, cardHeight/1.58);
|
|
|
|
ctx.fillText(opponentDeck.length, cardWidth/2 + (ctx.measureText(opponentDeck.length).width) + 10, cardHeight/1.58);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Naming's getting awkward here...
|
|
|
|
// Naming's getting awkward here...
|
|
|
|
@ -131,18 +133,27 @@ class Board{
|
|
|
|
|
|
|
|
|
|
|
|
// TODO: fix positionX, actually have some maffs
|
|
|
|
// TODO: fix positionX, actually have some maffs
|
|
|
|
let positionX = canvas.width/2 - ((cardWidth/4 * 2) * (playerHand.length - (i+1)) - (cardPadding * (i+1)));
|
|
|
|
let positionX = canvas.width/2 - ((cardWidth/4 * 2) * (playerHand.length - (i+1)) - (cardPadding * (i+1)));
|
|
|
|
|
|
|
|
let positionY = canvas.height - cardHeight/2-20;
|
|
|
|
console.log('drawHand: cardsInHand: '+(i+1)+' / '+playerHand.length);
|
|
|
|
console.log('drawHand: cardsInHand: '+(i+1)+' / '+playerHand.length);
|
|
|
|
|
|
|
|
|
|
|
|
clickableItems['hand'][name] = new Shape({
|
|
|
|
clickableItems['hand'][name] = new Shape({
|
|
|
|
name: name,
|
|
|
|
name: name,
|
|
|
|
x: positionX,
|
|
|
|
x: positionX,
|
|
|
|
y: canvas.height - cardHeight/2-20,
|
|
|
|
y: positionY,
|
|
|
|
width: cardWidth/2,
|
|
|
|
width: cardWidth/2,
|
|
|
|
height: cardHeight/2,
|
|
|
|
height: cardHeight/2,
|
|
|
|
fillStyle: fill
|
|
|
|
fillStyle: fill
|
|
|
|
});
|
|
|
|
});
|
|
|
|
playerHand[i]['clickable'] = clickableItems['hand'][name];
|
|
|
|
playerHand[i]['clickable'] = clickableItems['hand'][name];
|
|
|
|
playerHand[i]['clickable'].draw();
|
|
|
|
playerHand[i]['clickable'].draw();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Add card text
|
|
|
|
|
|
|
|
ctx.fillStyle = '#000';
|
|
|
|
|
|
|
|
ctx.fillText(
|
|
|
|
|
|
|
|
playerHand[i]['name']
|
|
|
|
|
|
|
|
, positionX + (ctx.measureText(playerHand[i]['name']/2).width)
|
|
|
|
|
|
|
|
, positionY+20
|
|
|
|
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@ -182,7 +193,14 @@ class Board{
|
|
|
|
return 0;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
playerHand.push({'name':'CardName', 'cost':1, 'atk':1, 'def':1, 'rarity': 'common', 'effect':null, 'type':'human'});
|
|
|
|
// Random card from deck, remove from deck, add to hand
|
|
|
|
|
|
|
|
let cardToDraw = Math.floor(Math.random() * deckCount);
|
|
|
|
|
|
|
|
let cardDrawn = playerDeck[cardToDraw];
|
|
|
|
|
|
|
|
console.log(cardDrawn);
|
|
|
|
|
|
|
|
// Remove from deck
|
|
|
|
|
|
|
|
playerDeck.splice(cardToDraw, 1);
|
|
|
|
|
|
|
|
// Add to hand
|
|
|
|
|
|
|
|
playerHand.push(cardDrawn);
|
|
|
|
this.drawBoard();
|
|
|
|
this.drawBoard();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
drawACardOpponent(){
|
|
|
|
drawACardOpponent(){
|
|
|
|
@ -231,6 +249,11 @@ class Board{
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// TEMP!!
|
|
|
|
|
|
|
|
createDeckList(playerDeck, deckCount);
|
|
|
|
|
|
|
|
createDeckList(opponentDeck, deckCountOpponent);
|
|
|
|
|
|
|
|
console.log(playerDeck);
|
|
|
|
|
|
|
|
|
|
|
|
// Run board commands here for testing
|
|
|
|
// Run board commands here for testing
|
|
|
|
let board = new Board;
|
|
|
|
let board = new Board;
|
|
|
|
//board.initBoard();
|
|
|
|
//board.initBoard();
|
|
|
|
@ -314,3 +337,11 @@ function clickableCheck(x,y,clickable){
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// TEMP: Create a deck of X different cards that can be drawn/played
|
|
|
|
|
|
|
|
// for UI development, will be done on server and not shown to clients
|
|
|
|
|
|
|
|
function createDeckList(deck, deckCount){
|
|
|
|
|
|
|
|
for(let i = 0; i < deckCount; i++){
|
|
|
|
|
|
|
|
deck.push({'name':'CardName '+(i+1), 'cost':1, 'atk':1, 'def':1, 'rarity': 'common', 'effect':null, 'type':'human'});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|