From 242cc155843d467812a041dd4f6e9d90f6e7327c Mon Sep 17 00:00:00 2001 From: Nguyễn Gia Phong Date: Sun, 19 Nov 2017 15:00:24 +0700 Subject: Give Plum cloning ability --- brutalmaze/characters.py | 35 ++++------------------------------- brutalmaze/maze.py | 11 +++++++++-- setup.py | 2 +- 3 files changed, 14 insertions(+), 34 deletions(-) diff --git a/brutalmaze/characters.py b/brutalmaze/characters.py index 372600b..6a830cc 100644 --- a/brutalmaze/characters.py +++ b/brutalmaze/characters.py @@ -246,24 +246,6 @@ class Enemy: self.maze.map[self.x][self.y] = WALL -class Butter(Enemy): - """Object representing an enemy of Butter type.""" - def __init__(self, maze, x, y): - Enemy.__init__(self, maze, x, y, 'Butter') - - -class Orange(Enemy): - """Object representing an enemy of Orange type.""" - def __init__(self, maze, x, y): - Enemy.__init__(self, maze, x, y, 'Orange') - - -class Chocolate(Enemy): - """Object representing an enemy of Chocolate type.""" - def __init__(self, maze, x, y): - Enemy.__init__(self, maze, x, y, 'Chocolate') - - class Chameleon(Enemy): """Object representing an enemy of Chameleon type. @@ -290,18 +272,6 @@ class Chameleon(Enemy): self.wound += wound -class SkyBlue(Enemy): - """Object representing an enemy of Sky Blue type.""" - def __init__(self, maze, x, y): - Enemy.__init__(self, maze, x, y, 'SkyBlue') - - -class Plum(Enemy): - """Object representing an enemy of Plum type.""" - def __init__(self, maze, x, y): - Enemy.__init__(self, maze, x, y, 'Plum') - - class ScarletRed(Enemy): """Object representing an enemy of Scarlet Red type.""" def __init__(self, maze, x, y): @@ -323,4 +293,7 @@ class ScarletRed(Enemy): def new_enemy(maze, x, y): """Return an enemy of a random type in the grid (x, y).""" color = choices(maze.enemy_weights) - return getattr(modules[__name__], color)(maze, x, y) + try: + return getattr(modules[__name__], color)(maze, x, y) + except AttributeError: + return Enemy(maze, x, y, color) diff --git a/brutalmaze/maze.py b/brutalmaze/maze.py index 1bd51b1..13db616 100644 --- a/brutalmaze/maze.py +++ b/brutalmaze/maze.py @@ -108,8 +108,15 @@ class Maze: x, y = choice(walls) if all(self.map[x + a][y + b] == WALL for a, b in ADJACENT_GRIDS): continue - self.enemies.append(new_enemy(self, x, y)) - walls.remove((x, y)) + enemy = new_enemy(self, x, y) + self.enemies.append(enemy) + if enemy.color == 'Plum': + for e in self.enemies: + if e.color == 'Plum' and e.awake: x, y = e.x, e.y + try: + walls.remove((x, y)) + except ValueError: + enemy.x, enemy.y = x, y def pos(self, x, y): """Return coordinate of the center of the grid (x, y).""" diff --git a/setup.py b/setup.py index cce9e85..aa2abbf 100755 --- a/setup.py +++ b/setup.py @@ -7,7 +7,7 @@ with open('README.rst') as f: setup( name='brutalmaze', - version='0.1.2', + version='0.1.3', description='A hash and slash game with fast-paced action and a minimalist art style', long_description=long_description, url='https://github.com/McSinyx/brutalmaze', -- cgit 1.4.1