mirror of
https://github.com/arthur-pbty/xiao.git
synced 2026-06-03 23:36:43 +02:00
35 lines
652 B
JavaScript
35 lines
652 B
JavaScript
const TarotCard = require('./TarotCard');
|
|
const cards = require('../../assets/json/tarot');
|
|
const { shuffle } = require('../../util/Util');
|
|
|
|
module.exports = class TarotDeck {
|
|
constructor() {
|
|
this.deck = [];
|
|
this.makeCards();
|
|
}
|
|
|
|
makeCards() {
|
|
const newDeck = [];
|
|
for (const card of cards) {
|
|
newDeck.push(new TarotCard(card));
|
|
}
|
|
this.deck = shuffle(newDeck);
|
|
return this.deck;
|
|
}
|
|
|
|
draw(amount = 1) {
|
|
const drawn = [];
|
|
for (let i = 0; i < amount; i++) {
|
|
const card = this.deck[0];
|
|
this.deck.shift();
|
|
drawn.push(card);
|
|
}
|
|
return amount === 1 ? drawn[0] : drawn;
|
|
}
|
|
|
|
reset() {
|
|
this.makeCards();
|
|
return this;
|
|
}
|
|
};
|