-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.py
63 lines (56 loc) · 1.52 KB
/
config.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
import ConfigParser
class Level(object):
def load_file(self, filename="level.map"):
self.map = [[]]
self.key = {}
self.posx = 0
self.posy = 0
parser = ConfigParser.ConfigParser()
parser.read(filename)
tempMap = parser.get("level", "map").split("\n")
for line in tempMap:
self.map.append(list(line))
for section in parser.sections():
if len(section) == 1:
desc = dict(parser.items(section))
self.key[section] = desc
self.map.pop(0)
print len(self.map)
self.width = len(self.map[0])
self.height = len(self.map)
for y, line in enumerate(self.map):
for x, c in enumerate(line):
if self.map[y][x] == "x":
self.posx = x
self.posy = y
def get_tile(self, x, y):
try:
char = self.map[y][x]
except IndexError:
return {}
try:
return self.key[char]
except KeyError:
return {}
def is_wall(self, x, y):
return self.get_bool(x, y, 'wall')
def render(self):
out = ""
for line in self.map:
# for map_x, c in enumerate(line):
# tile = self.key[c]['name']
# if tile == 'unit':
# out += "x"
# elif tile == 'blank':
# out += "-"
for char in line:
out += char
out += "\n"
return out
def move(self, dx, dy):
y = self.posy
x = self.posx
self.map[y][x] = '-'
self.posy = (self.height+y+dy)%self.height
self.posx = (self.width+x+dx)%self.width
self.map[self.posy][self.posx] = 'x'