Initial system development

This commit is contained in:
2021-01-18 22:05:02 +01:00
parent ca29af6b61
commit e78b2ac67d
15 changed files with 481 additions and 363 deletions

View File

@ -4,45 +4,66 @@ const NB_POKER_CARD = 54;
const IDX2CARDFAMILY = ['c', 'd', 'h', 's'];
/* -------------------------------------------- */
export class SoSCardDeck extends Application {
export class SoSCardDeck {
/* -------------------------------------------- */
static async create(data, options) {
data.deck = [];
data.discard = [];
data.cardState = [];
return super.create(data, options);
initCardDeck(actor) {
this.data = {};
this.data.deck = [];
this.data.discard = [];
this.data.cardState = [];
this.data.cardEdge = [];
this.data.actor = actor;
this.shuffleDeck();
}
/* -------------------------------------------- */
shuffleDeck() {
this.cleanCardList();
// Randomize deck
while (data.deck.length != NB_POKER_CARD) {
while (this.data.deck.length != NB_POKER_CARD) {
let idx = new Roll("1d54").roll().total;
if (!this.data.cardState[idx - 1]) {
if (idx == 53) { // Red Joker
data.deck.push = { cardName: 'jr' }
this.data.deck.push( { cardName: 'jr' } );
} else if (idx == 54) { // Black Joker
data.deck.push = { cardName: 'jb' }
this.data.deck.push({ cardName: 'jb' });
} else {
let familyIdx = idx % 4;
let cardName = IDX2CARDFAMILY[familyIdx] + String((idx % 13) + 1);
data.deck.push = { cardName: cardName }
let cardIdx = String( (idx % 13) + 1);
cardIdx = (cardIdx.length < 2) ? "0"+cardIdx: cardIdx;
let cardName = IDX2CARDFAMILY[familyIdx] + cardIdx;
this.data.deck.push( { cardName: cardName } );
}
this.data.cardState[idx - 1] = true;
}
}
}
}
/* -------------------------------------------- */
drawEdge() {
this.data.cardEdge.push( this.data.deck.pop() );
this.data.cardEdge.push( this.data.deck.pop() );
console.log("DRAW EDGE", this.data.cardEdge);
}
/* -------------------------------------------- */
cleanCardList() {
data.discard = []; // Reinit discard pile
data.deck = [];
this.data.discard = []; // Reinit discard pile
this.data.deck = [];
for (let i = 0; i < NB_POKER_CARD; i++) {
data.cardState[i] = false;
this.data.cardState[i] = false;
}
}
/* -------------------------------------------- */
doFlipStat( statData ) {
let card = this.data.deck.pop();
this.data.discard.push( card );
console.log("CARD IS : ", card, this.data.deck.length );
}
}