-
Notifications
You must be signed in to change notification settings - Fork 0
/
card.ts
66 lines (56 loc) · 1001 Bytes
/
card.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
class Card {
suit: string;
rank: string;
value: number;
constructor(rank: string, suit: string) {
this.rank = rank;
this.suit = suit;
switch(rank) {
case 'A':
this.value = 11;
break;
case 'K':
case 'Q':
case 'J':
this.value = 10;
break;
default:
this.value = parseInt(rank);
break;
}
}
rankToLongString(): string {
switch(this.rank){
case 'J':
return "Jack";
case 'Q':
return "Queen";
case 'K':
return "King";
case 'A':
return "Ace";
default:
return this.value.toString();
}
}
suitToLongString(): string {
switch(this.suit){
case '♥':
return "Hearts";
case '♦':
return "Diamonds";
case '♠':
return "Spades";
case '♣':
return "Clubs";
default:
return this.value.toString();
}
}
toString(): string {
return `${this.rank}${this.suit}`;
}
toLongString(): string {
return `${this.rankToLongString()} of ${this.suitToLongString()}`;
}
}