-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathcard.py
53 lines (47 loc) · 1.47 KB
/
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
# Author: Reilly Bova
# Date: 30 September 2018
# File: card.py
# About: Implements a playing card
class Card:
def __init__(self, id):
self.id = id
# Identify Suite
if (id < 13):
self.suite = '♦'
self.suiteID = 0
elif (id < 26):
self.suite = '♣'
self.suiteID = 1
elif (id < 39):
self.suite = '♥'
self.suiteID = 2
else:
self.suite = '♠'
self.suiteID = 3
# Identify Order
rem = (id % 13) + 2
self.orderID = rem
if (rem <= 10):
self.order = str(rem)
elif (rem == 11):
self.order = 'J'
elif (rem == 12):
self.order = 'Q'
elif (rem == 13):
self.order = 'K'
elif (rem == 14):
self.order = 'A'
# For representation (multi-line, so returning array makes it easier to arrange cards horizontally later)
def viz(self):
symbol = self.suite
ord = self.order[0]
if (len(self.order) == 2):
pad = self.order[1]
else:
pad = ' '
# Style influenced by https://codereview.stackexchange.com/questions/82103/ascii-fication-of-playing-cards
return [ "┌───────┐",
f"│{ord}{pad} │",
f"│ {symbol} │",
f"│ {ord}{pad}│",
"└───────┘"]