cards/card.ts
2026-01-16 21:14:50 -07:00

72 lines
936 B
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
}
get decimalIndex() {
const base = 2
return this.index.toString(base)
}
get decimalSuit() {
const base = 2
return this.suit.toString(base)
}
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]
}
}