-
Notifications
You must be signed in to change notification settings - Fork 1
/
Displayer_3.py
executable file
·58 lines (49 loc) · 1.25 KB
/
Displayer_3.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
from BaseDisplayer_3 import BaseDisplayer
import platform
import os
colorMap = {
0 : 97 ,
2 : 40 ,
4 : 100,
8 : 47 ,
16 : 107,
32 : 46 ,
64 : 106,
128 : 44 ,
256 : 104,
512 : 42 ,
1024 : 102,
2048 : 43 ,
4096 : 103,
8192 : 45 ,
16384 : 105,
32768 : 41 ,
65536 : 101,
}
cTemp = "\x1b[%dm%7s\x1b[0m "
class Displayer(BaseDisplayer):
def __init__(self):
if "Windows" == platform.system():
self.display = self.winDisplay
else:
self.display = self.unixDisplay
def display(self, grid):
pass
def winDisplay(self, grid):
for i in range(grid.size):
for j in range(grid.size):
print("%6d " % grid.map[i][j], end="")
print("")
print("")
def unixDisplay(self, grid):
for i in range(3 * grid.size):
for j in range(grid.size):
v = grid.map[int(i / 3)][j]
if i % 3 == 1:
string = str(v).center(7, " ")
else:
string = " "
print(cTemp % (colorMap[v], string), end="")
print("")
if i % 3 == 2:
print("")