-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgraphical_card.py
64 lines (51 loc) · 2.02 KB
/
graphical_card.py
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
from colorama import init, Fore, Back
init()
class GraphicalCard:
long_value_to_short_value_dict = {"Jack": "J", "Queen": "Q", "King": "K", "Ace": "A"}
# suit_to_symbol_dict = {"Clubs": Fore.WHITE + "♣" + Fore.RESET, "Diamonds": Fore.RED + "♦" + Fore.RESET, "Hearts": Fore.RED + "♥" + Fore.RESET, "Spades": Fore.WHITE + "♠" + Fore.RESET}
suit_to_symbol_dict = {"Clubs": "♣", "Diamonds": "♦", "Hearts": "♥", "Spades": "♠"}
color_dict = {"Clubs": Fore.WHITE, "Diamonds": Fore.RED, "Hearts": Fore.RED, "Spades": Fore.WHITE}
def __init__(self, card_name):
self.card_name = card_name
split = card_name.split(" ")
self.value = self.card_to_short_value(split[0])
self.suit = self.card_to_suit_symbol(split[-1])
self.color = self.color_dict[split[-1]]
def card_to_short_value(self, value):
return self.long_value_to_short_value_dict.get(value, value).ljust(2)
def card_to_suit_symbol(self, suit):
return self.suit_to_symbol_dict[suit]
def line_1(self):
print("╭──── ", end="")
def line_2(self):
print(f"│ {self.color}{self.value}{Fore.RESET} ", end=" ")
def line_3(self):
print(f"│ {self.color}{self.suit}{Fore.RESET} ", end=" ")
def graphical_hand(hand, suit = None):
graphical_cards = [GraphicalCard(card) for card in hand]
if suit not in [card.split()[2] for card in hand]:
suit = "of"
for card in graphical_cards:
if suit in card.card_name:
card.line_1()
else:
print(f" ", end=" ")
print()
for card in graphical_cards:
if suit in card.card_name:
card.line_2()
else:
card.line_1()
print()
for card in graphical_cards:
if suit in card.card_name:
card.line_3()
else:
card.line_2()
print()
for card in graphical_cards:
if suit in card.card_name:
print(f" ", end=" ")
else:
card.line_3()
print()