cards/card.ts
Github Readme Stats Bot 63ea3ff952 Card and Pile tests
2026-01-17 18:10:52 -07:00

82 lines
1.1 KiB
TypeScript

export enum Index {
Joker,
One,
Two,
Three,
Four,
Five,
Six,
Seven,
Eight,
Nine,
Ten,
Jack,
Queen,
King,
Ace
}
export enum Suit {
Diamond,
Club,
Heart,
Spade
}
export default class Card {
index: Index
suit: Suit
constructor(index: Index, suit: Suit) {
this.index = index
this.suit = suit
}
// 000, 001, 010...
get decimalIndex() {
const base = 2
const digits = 3
return this
.index
.toString(base)
.padStart(digits, '0')
}
// 00, 01, 10, 11
get decimalSuit() {
const base = 2
const digits = 2
return this
.suit
.toString(base)
.padStart(digits, '0')
}
get pretty() {
return `${this.prettyIndex} of ${this.prettySuit}`
}
get prettyIndex() {
return [
'Joker',
'One',
'Two',
'Three',
'Four',
'Five',
'Six',
'Seven',
'Eight',
'Nine',
'Ten',
'Jack',
'Queen',
'King',
'Ace'
][this.index]
}
get prettySuit() {
return ['♦', '♣', '♥', '♠'][this.suit]
}
}