mirror of
https://github.com/arthur-pbty/xiao.git
synced 2026-06-06 22:44:32 +02:00
Playing Card Commands structure system
This commit is contained in:
@@ -0,0 +1,46 @@
|
||||
const displaySuits = {
|
||||
spades: '♠',
|
||||
diamonds: '♦',
|
||||
hearts: '♥',
|
||||
clubs: '♣',
|
||||
joker: '⭐'
|
||||
};
|
||||
|
||||
module.exports = class Card {
|
||||
constructor(value, suit) {
|
||||
this.value = value;
|
||||
this.suit = suit;
|
||||
}
|
||||
|
||||
get blackjackValue() {
|
||||
if (this.value === 'Joker') return 0;
|
||||
if (this.value === 'King' || this.value === 'Queen' || this.value === 'Jack') return 10;
|
||||
if (this.value === 'Ace') return 11;
|
||||
return this.value;
|
||||
}
|
||||
|
||||
get display() {
|
||||
return `${displaySuits[this.suit]} ${this.value}`;
|
||||
}
|
||||
|
||||
get pokersolverKey() {
|
||||
if (this.value === 'Joker') return null;
|
||||
let suitLetter;
|
||||
switch (this.suit) {
|
||||
case 'clubs': suitLetter = 'c'; break;
|
||||
case 'hearts': suitLetter = 'h'; break;
|
||||
case 'diamonds': suitLetter = 'd'; break;
|
||||
case 'spades': suitLetter = 's'; break;
|
||||
}
|
||||
let value;
|
||||
switch (this.value) {
|
||||
case 'King': value = 'K'; break;
|
||||
case 'Queen': value = 'Q'; break;
|
||||
case 'Jack': value = 'J'; break;
|
||||
case 'Ace': value = 'A'; break;
|
||||
case 10: value = 'T'; break;
|
||||
default: value = this.value; break;
|
||||
}
|
||||
return `${value}${suitLetter}`;
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,44 @@
|
||||
const Card = require('./Card');
|
||||
const suits = ['spades', 'hearts', 'diamonds', 'clubs'];
|
||||
const faces = ['Jack', 'Queen', 'King'];
|
||||
const { shuffle } = require('../../util/Util');
|
||||
|
||||
module.exports = class Deck {
|
||||
constructor(options) {
|
||||
this.deckCount = options.deckCount || 1;
|
||||
this.includeJokers = options.includeJokers || false;
|
||||
this.deck = [];
|
||||
this.makeCards(this.deckCount);
|
||||
}
|
||||
|
||||
makeCards(deckCount) {
|
||||
for (let i = 0; i < deckCount; i++) {
|
||||
for (const suit of suits) {
|
||||
this.deck.push(new Card('Ace', suit));
|
||||
for (let j = 2; j <= 10; j++) this.deck.push(new Card(j, suit));
|
||||
for (const face of faces) this.deck.push(new Card(face, suit));
|
||||
}
|
||||
if (this.includeJokers) {
|
||||
this.deck.push(new Card('Joker', 'joker'));
|
||||
this.deck.push(new Card('Joker', 'joker'));
|
||||
}
|
||||
}
|
||||
this.deck = shuffle(this.deck);
|
||||
return this.deck;
|
||||
}
|
||||
|
||||
draw(amount = 1) {
|
||||
const cards = [];
|
||||
for (let i = 0; i < amount; i++) {
|
||||
const card = this.deck[0];
|
||||
this.deck.shift();
|
||||
cards.push(card);
|
||||
}
|
||||
return amount === 1 ? cards[0] : cards;
|
||||
}
|
||||
|
||||
reset() {
|
||||
this.deck = this.makeCards(this.deckCount);
|
||||
return this;
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user