-
Notifications
You must be signed in to change notification settings - Fork 0
/
Displayer.py
62 lines (51 loc) · 1.36 KB
/
Displayer.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
#!/usr/bin/env python
# coding:utf-8
from BaseDisplayer 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 xrange(grid.size):
for j in xrange(grid.size):
print "%6d " % grid.map[i][j],
print ""
print ""
def unixDisplay(self, grid):
#os.system("clear")
for i in xrange(3 * grid.size):
for j in xrange(grid.size):
v = grid.map[i / 3][j]
if i % 3 == 1:
string = str(v).center(7, ' ')
else:
string = ' '
print cTemp % (colorMap[v], string),
print ""
if i % 3 == 2:
print ""