diff --git a/.gitignore b/.gitignore index d513b9e..feb848a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ .*.swp __pycache__ +.idea diff --git a/items.py b/items.py index 17f8863..60aa31d 100644 --- a/items.py +++ b/items.py @@ -23,3 +23,19 @@ def glyph(self): def __str__(self): return "key" + +class Pickaxe(Item): + def __init__(self): + self.usage = 3 + + def glyph(self): + return ('P', Colors.DARK_GRAY) if self.usage < 1 else ('P', Colors.BROWN) + + def pickaxe_used(self): + self.usage -= 1 + + def get_pickaxe_usage(self): + return self.usage + + def __str__(self): + return "pickaxe (%s)" % self.usage \ No newline at end of file diff --git a/map.txt b/map.txt index 422e34c..e0b0023 100644 --- a/map.txt +++ b/map.txt @@ -4,7 +4,7 @@ #######.#.......#######.#........#.....#.......................................# #######.#...3...#######.#.######.#.....#.......................................# #######.1.......#######.#.######.#.....#.......................................# -#######.#.......#######.#......#.#######.......................................# +#######P#.......#######.#......#.#######.......................................# ####....#.......#######.######.#.#######.......................................# ####+#######.##########+#......#.#######.......................................# #........###.#########..#.######.#######.......................................# diff --git a/tiles.py b/tiles.py index 4d8d606..b4173b0 100644 --- a/tiles.py +++ b/tiles.py @@ -35,13 +35,12 @@ def glyph(self): return self.item.glyph() if self.item else ('.', Colors.DARK_GRAY) - class KeyFloor(Floor): def __init__(self, y, x): super().__init__(y,x) self.item = Key() -# new comment + class KnifeFloor(Floor): def __init__(self, y, x): self.y = y @@ -50,15 +49,31 @@ def __init__(self, y, x): class Wall(Tile): + def __init__(self,y,x): + self.y = y + self.x = x + self.destroyed = False + def passable(self): - return False + if self.destroyed: + return True + else: + return False def glyph(self): - return ('#', Colors.WHITE) + return ('#', Colors.DARK_GRAY) if self.destroyed else ('#', Colors.WHITE) def __str__(self): return "wall" + def use(self, item): + if isinstance(item, items.Pickaxe) and item.get_pickaxe_usage() > 0: + self.destroyed = True + item.pickaxe_used() + return "you have destroyed the wall, %s" % item + else: + raise ActionException("You can not use %s here" % item) + class Teleport(Tile): def passable(self): @@ -74,7 +89,6 @@ def open(self): return "you used the teleport" -# new comment class Door(Tile): OPEN = 1 CLOSED = 2 @@ -83,12 +97,13 @@ def __init__(self, y, x): super().__init__(y, x) self.item = False self.state = Door.CLOSED + self.destroyed = False def passable(self): - return self.state == Door.OPEN + return True if self.destroyed or self.state == Door.OPEN else False def glyph(self): - return ('/' if self.passable() else '+', Colors.BROWN) + return (';', Colors.DARK_GRAY) if self.destroyed else ('/' if self.passable() else '+', Colors.BROWN) def open(self): if self.state == Door.CLOSED: @@ -106,8 +121,13 @@ def __str__(self): return "door" def use(self, item): - if isinstance(item, items.Knife): - return "you stab at the door, leaving a mark" + if not self.destroyed: + if isinstance(item, items.Knife): + return "you stab at the door, leaving a mark" + if isinstance(item, items.Pickaxe) and item.get_pickaxe_usage() > 0: + self.destroyed = True + item.pickaxe_used() + return "you have destroyed the door, %s" % item class KeyDoor(Door): @@ -121,30 +141,41 @@ class KeyDoor(Door): def __init__(self, y, x): super().__init__(y, x) self.state = KeyDoor.LOCKED + self.destroyed = False def glyph(self): - return (self.glyphs[self.state], Colors.DARK_RED) + return (';', Colors.DARK_GRAY) if self.destroyed else (self.glyphs[self.state], Colors.DARK_RED) def open(self): - if self.state == KeyDoor.LOCKED: - raise ActionException("this door is locked") - super().open() + if not self.destroyed: + if self.state == KeyDoor.LOCKED: + raise ActionException("this door is locked") + super().open() def use(self, item): - if isinstance(item, items.Key) and self.state == KeyDoor.LOCKED: - self.state = KeyDoor.CLOSED - return "you have unlocked the door" - if isinstance(item, items.Key) and self.state == KeyDoor.CLOSED: - self.state = KeyDoor.LOCKED - return "you have locked the door" - else: - raise ActionException("Close the door, please.") - - super().use(item) - + if not self.destroyed: + if isinstance(item, items.Pickaxe) and item.get_pickaxe_usage() > 0: + self.destroyed = True + item.pickaxe_used() + return "you have destroyed the door, %s" % item + if isinstance(item, items.Key) and self.state == KeyDoor.LOCKED: + self.state = KeyDoor.CLOSED + return "you have unlocked the door" + if isinstance(item, items.Key) and self.state == KeyDoor.CLOSED: + self.state = KeyDoor.LOCKED + return "you have locked the door" + else: + raise ActionException("Close the door, please.") + super().use(item) + + +class PickaxeFloor(Floor): + def __init__(self, y, x): + self.y = y + self.x = x + self.item = items.Pickaxe() -# new comment class TileFactory: TILES = { '.': Floor, @@ -153,7 +184,8 @@ class TileFactory: '1': KeyDoor, '2': KeyFloor, '3': Teleport, - '(': KnifeFloor + '(': KnifeFloor, + 'P': PickaxeFloor, } @staticmethod