mirror of
https://github.com/arthur-pbty/xiao.git
synced 2026-06-03 23:36:43 +02:00
21 lines
344 B
JavaScript
21 lines
344 B
JavaScript
const { shuffle } = require('../util/Util');
|
|
|
|
module.exports = class Deck {
|
|
constructor(cards) {
|
|
this.cards = cards;
|
|
this.deck = shuffle(cards);
|
|
}
|
|
|
|
draw() {
|
|
if (!this.deck.length) this.reset();
|
|
const card = this.deck[0];
|
|
this.deck.shift();
|
|
return card;
|
|
}
|
|
|
|
reset() {
|
|
this.deck = shuffle(this.cards);
|
|
return this.deck;
|
|
}
|
|
};
|