home
·
contact
·
privacy
projects
/
plomrogue2-experiments
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
398d5e5
)
Improve Map class design.
author
Christian Heller
<c.heller@plomlompom.de>
Wed, 16 Jan 2019 22:06:44 +0000
(23:06 +0100)
committer
Christian Heller
<c.heller@plomlompom.de>
Wed, 16 Jan 2019 22:06:44 +0000
(23:06 +0100)
server_/game.py
patch
|
blob
|
history
diff --git
a/server_/game.py
b/server_/game.py
index 52afc458b69fdb73096c67dcc2ba1c4c1e3463b6..82759c25aee6b97fa37e978589f1fc3d05744aae 100644
(file)
--- a/
server_/game.py
+++ b/
server_/game.py
@@
-16,6
+16,11
@@
class Map(game_common.Map):
pos_i = self.get_pos_i(yx)
self.terrain = self.terrain[:pos_i] + c + self.terrain[pos_i + 1:]
pos_i = self.get_pos_i(yx)
self.terrain = self.terrain[:pos_i] + c + self.terrain[pos_i + 1:]
+ def __iter__(self):
+ for y in range(self.size[0]):
+ for x in range(self.size[1]):
+ yield [y, x]
+
@property
def size_i(self):
return self.size[0] * self.size[1]
@property
def size_i(self):
return self.size[0] * self.size[1]
@@
-37,11
+42,6
@@
class Map(game_common.Map):
def new_from_shape(self, init_char):
return Map(self.size, init_char*self.size_i)
def new_from_shape(self, init_char):
return Map(self.size, init_char*self.size_i)
- def iterate(self):
- for y in range(self.size[0]):
- for x in range(self.size[1]):
- yield [y, x]
-
def are_neighbors(self, pos_1, pos_2):
return abs(pos_1[0] - pos_2[0]) <= 1 and abs(pos_1[1] - pos_2[1] <= 1)
def are_neighbors(self, pos_1, pos_2):
return abs(pos_1[0] - pos_2[0]) <= 1 and abs(pos_1[1] - pos_2[1] <= 1)
@@
-117,10
+117,8
@@
class Task:
direction = self.args[0]
else:
direction = self.kwargs['direction']
direction = self.args[0]
else:
direction = self.kwargs['direction']
- test_pos = self.thing.world.map_.move(self.thing.position,
- direction)
- map_tile = self.thing.world.map_[test_pos]
- if map_tile != '.':
+ test_pos = self.thing.world.map_.move(self.thing.position, direction)
+ if self.thing.world.map_[test_pos] != '.':
raise GameError('would move into illegal terrain')
for t in self.thing.world.things:
if t.position == test_pos:
raise GameError('would move into illegal terrain')
for t in self.thing.world.things:
if t.position == test_pos:
@@
-187,7
+185,7
@@
class Thing(game_common.Thing):
if self._stencil is not None:
return self._stencil
m = self.world.map_.new_from_shape('?')
if self._stencil is not None:
return self._stencil
m = self.world.map_.new_from_shape('?')
- for pos in m
.iterate()
:
+ for pos in m:
if pos == self.position or m.are_neighbors(pos, self.position):
m[pos] = '.'
self._stencil = m
if pos == self.position or m.are_neighbors(pos, self.position):
m[pos] = '.'
self._stencil = m
@@
-196,7
+194,7
@@
class Thing(game_common.Thing):
def get_visible_map(self):
stencil = self.get_stencil()
m = self.world.map_.new_from_shape(' ')
def get_visible_map(self):
stencil = self.get_stencil()
m = self.world.map_.new_from_shape(' ')
- for pos in m
.iterate()
:
+ for pos in m:
if stencil[pos] == '.':
m[pos] = self.world.map_[pos]
return m
if stencil[pos] == '.':
m[pos] = self.world.map_[pos]
return m