-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmatrix.py
52 lines (35 loc) · 1.57 KB
/
matrix.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
# World in which actors reside
# yep. just a simple 10x10 matrix
class world():
def __init__(self):
self.spaceX=10 # size of matrix
self.spaceY=10
self.locations = {} # location dict of all objects
self.screenCleared = False
def registerActor (self, actorInstance):
self.locations[actorInstance] = {"name":actorInstance.name, "icon":actorInstance.icon, "x":0, "y":0}
def deregisterActor (self, actorInstance):
del(self.locations[actorInstance])
def cls (self):
for y in range(self.spaceY + 5): # allow some extra for whatever context prints after
print ('\033[%d;%dH%s' % (y, 0, " " * self.spaceX * 4))
def requestLocationChange (self, obj, x, y):
if x >= self.spaceX or y >= self.spaceY:
return (False)
if x < 0 or y < 0:
return (False)
#print ('\033[%d;%dH%s' % (self.locations[obj]["x"], self.locations[obj]["y"]*2, " ")) # unset icon
self.locations[obj]["x"] = x
self.locations[obj]["y"] = y
#print ('\033[%d;%dH%s' % (self.locations[obj]["x"], self.locations[obj]["y"]*2, self.locations[obj]["icon"])) # set icon
#print ('\033[%d;%dH%s' % (self.spaceY, 0, " "))
return (True)
def printContext (self):
if not self.screenCleared:
print ('\033[2J') # clear screen
print ('\033[H')
self.screenCleared = True
self.cls()
for l in self.locations.keys():
print ('\033[%d;%dH%s' % (self.locations[l]["x"], self.locations[l]["y"]*2, self.locations[l]["icon"]))
print ('\033[%d;%dH%s' % (self.spaceY, 0, " "))