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 (from parent 1:
5765f66
)
Minor refactoring.
author
Christian Heller
<c.heller@plomlompom.de>
Mon, 3 Dec 2018 01:24:08 +0000
(
02:24
+0100)
committer
Christian Heller
<c.heller@plomlompom.de>
Mon, 3 Dec 2018 01:24:08 +0000
(
02:24
+0100)
server.py
patch
|
blob
|
history
diff --git
a/server.py
b/server.py
index 7f05cb5d687bec9150dabac85a36cdae734c29d1..35bd9bc76ea890c7c72ff9b4a5735c2c5156df2a 100755
(executable)
--- a/
server.py
+++ b/
server.py
@@
-102,18
+102,21
@@
class Thing:
self.position = position
self.task = Task('wait')
self.position = position
self.task = Task('wait')
- def task_wait(self):
- pass
-
- def task_move(self, direction):
+ def _move_pos(self, direction, pos_yx):
if direction == 'UP':
if direction == 'UP':
-
self.position
[0] -= 1
+
pos_yx
[0] -= 1
elif direction == 'DOWN':
elif direction == 'DOWN':
-
self.position
[0] += 1
+
pos_yx
[0] += 1
elif direction == 'RIGHT':
elif direction == 'RIGHT':
-
self.position
[1] += 1
+
pos_yx
[1] += 1
elif direction == 'LEFT':
elif direction == 'LEFT':
- self.position[1] -= 1
+ pos_yx[1] -= 1
+
+ def task_wait(self):
+ pass
+
+ def task_move(self, direction):
+ self._move_pos(direction, self.position)
def decide_task(self):
if self.position[1] > 1:
def decide_task(self):
if self.position[1] > 1:
@@
-130,14
+133,7
@@
class Thing:
else:
direction = kwargs['direction']
test_pos = self.position[:]
else:
direction = kwargs['direction']
test_pos = self.position[:]
- if direction == 'UP':
- test_pos[0] -= 1
- elif direction == 'DOWN':
- test_pos[0] += 1
- elif direction == 'RIGHT':
- test_pos[1] += 1
- elif direction == 'LEFT':
- test_pos[1] -= 1
+ self._move_pos(direction, test_pos)
if test_pos[0] < 0 or test_pos[1] < 0 or \
test_pos[0] >= self.world.map_size[0] or \
test_pos[1] >= self.world.map_size[1]:
if test_pos[0] < 0 or test_pos[1] < 0 or \
test_pos[0] >= self.world.map_size[0] or \
test_pos[1] >= self.world.map_size[1]: