-
Notifications
You must be signed in to change notification settings - Fork 0
/
interface.py
178 lines (131 loc) · 4.23 KB
/
interface.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
import os
from rule import parse_cards, symbolify_cards
from rule import BIG_JOKER_SYMBOL, LITTLE_JOKER_SYMBOL
card = '''
┏━━━━━━━━━━━━━━━━━━┓
┃ ┃
┃ {} ┃
┃ ┃
┃ ┃
┃ ┃
┃ ┃
┃ ┃
┃ ┃
┃ ┃
┃ ┃
┃ ┃
┃ {} ┃
┃ ┃
┗━━━━━━━━━━━━━━━━━━┛
'''
big_joker = '''
┏━━━━━━━━━━━━━━━━━━┓
┃ ┃
┃ J ┃
┃ O ┃
┃ K ┃
┃ E ┃
┃ R ┃
┃ ┃
┃ J ┃
┃ O ┃
┃ K ┃
┃ E ┃
┃ R ┃
┃ ┃
┗━━━━━━━━━━━━━━━━━━┛
'''
little_joker = '''
┏━━━━━━━━━━━━━━━━━━┓
┃ ┃
┃ j ┃
┃ o ┃
┃ k ┃
┃ e ┃
┃ r ┃
┃ ┃
┃ j ┃
┃ o ┃
┃ k ┃
┃ e ┃
┃ r ┃
┃ ┃
┗━━━━━━━━━━━━━━━━━━┛
'''
me_pass_label = '''
.______ ___ _______. _______.
| _ \ / \ / | / |
| |_) | / ^ \ | (----` | (----`
| ___/ / /_\ \ \ \ \ \
| | / _____ \ .----) | .----) |
| _| /__/ \__\ |_______/ |_______/
'''
op_pass_label = '''
_______. _______. ___ .______
/ | / | / \ | _ \
| (----` | (----` / ^ \ | |_) |
\ \ \ \ / /_\ \ | ___/
.----) | .----) | / _____ \ | |
|_______/ |_______/ /__/ \__\ | _|
'''
pass_label = {
"me": me_pass_label,
"op": op_pass_label,
}
widget_height = card.count('\n')
def stylish_card(card, style='op'):
if style == 'me':
card = card.replace('┏', '┌')
card = card.replace('┓', '┐')
card = card.replace('━', '─')
card = card.replace('┃', '│')
card = card.replace('┗', '└')
card = card.replace('┛', '┘')
elif style == 'op':
card = card.replace('┌', '┏')
card = card.replace('┐', '┓')
card = card.replace('─', '━')
card = card.replace('│', '┃')
card = card.replace('└', '┗')
card = card.replace('┘', '┛')
return card
def single_card_widget(c, style):
res = card.format(c, c)
if c is BIG_JOKER_SYMBOL:
res = big_joker
elif c is LITTLE_JOKER_SYMBOL:
res = little_joker
return stylish_card(res, style)
def multi_card_widgets(cards, style):
if len(cards) == 0:
return [pass_label[style]]
else:
cards = symbolify_cards(cards)
return list(map(lambda c: single_card_widget(c, style), cards))
def merge_card_widgets(cards):
cards = list(map(lambda s: s.splitlines(), cards))
s = [''] * widget_height
for n in range(widget_height):
for i, c in enumerate(cards):
sep = 4 * i
s[n] = s[n][:sep] + c[n]
return "\n".join(s)
def shift_card_widgets(card_widgets, length):
lines = card_widgets.splitlines()
shift_lines = map(lambda l: ' ' * length + l, lines)
return "\n".join(shift_lines)
def display_cards(cards, shift=0, style='op'):
print(
shift_card_widgets(
merge_card_widgets(multi_card_widgets(cards, style)),
shift
)
)
def display_table(me, op, played_hand, by):
os.system('clear')
display_cards(op, 30, 'op')
display_cards(played_hand[1], 15, by)
display_cards(me, 0, 'me')
if __name__ == '__main__':
cards = parse_cards("bl22aa33jkq45690")
print(display_cards(cards, 30, 'me'))