From: Christian Heller Date: Mon, 3 Dec 2018 01:24:08 +0000 (+0100) Subject: Minor refactoring. X-Git-Url: https://plomlompom.com/repos/%7B%7Bdb.prefix%7D%7D/static/%7B%7Bprefix%7D%7D/edit?a=commitdiff_plain;h=676c2ec05e61159b05ee327a6412a17f0c354cc7;p=plomrogue2-experiments Minor refactoring. --- diff --git a/server.py b/server.py index 7f05cb5..35bd9bc 100755 --- a/server.py +++ b/server.py @@ -102,18 +102,21 @@ class Thing: 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': - self.position[0] -= 1 + pos_yx[0] -= 1 elif direction == 'DOWN': - self.position[0] += 1 + pos_yx[0] += 1 elif direction == 'RIGHT': - self.position[1] += 1 + pos_yx[1] += 1 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: @@ -130,14 +133,7 @@ class Thing: 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]: