From 88b9d64dca166afb93c852f4cfec7abcbdab02f7 Mon Sep 17 00:00:00 2001 From: marcindbar Date: Thu, 21 May 2015 16:32:50 +0200 Subject: [PATCH 1/4] File .idea added to gitignore list --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index d513b9e..feb848a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ .*.swp __pycache__ +.idea From 6685b557fc6caa23fc6e4882f4ba0666c0030c3e Mon Sep 17 00:00:00 2001 From: marcindbar Date: Thu, 21 May 2015 16:38:20 +0200 Subject: [PATCH 2/4] [roguelike][marcin] Item pickaxe added --- items.py | 16 ++++++++++++++++ map.txt | 2 +- tiles.py | 34 +++++++++++++++++++++++++++------- 3 files changed, 44 insertions(+), 8 deletions(-) diff --git a/items.py b/items.py index 17f8863..ecb34c7 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) + + 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..cf2bc9a 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 @@ -143,8 +157,13 @@ def use(self, item): 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 +172,8 @@ class TileFactory: '1': KeyDoor, '2': KeyFloor, '3': Teleport, - '(': KnifeFloor + '(': KnifeFloor, + 'P': PickaxeFloor, } @staticmethod From 3e7d294322d7e59824d197f5ea9f9598698a839f Mon Sep 17 00:00:00 2001 From: marcindbar Date: Fri, 22 May 2015 09:27:59 +0200 Subject: [PATCH 3/4] [roguelike][marcin] Pickaxe update - changes color when it's useless --- items.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/items.py b/items.py index ecb34c7..60aa31d 100644 --- a/items.py +++ b/items.py @@ -29,7 +29,7 @@ def __init__(self): self.usage = 3 def glyph(self): - return ('P', Colors.DARK_GRAY) + return ('P', Colors.DARK_GRAY) if self.usage < 1 else ('P', Colors.BROWN) def pickaxe_used(self): self.usage -= 1 From 1362ed128421bf57b48067826aad6dc8048ea9dd Mon Sep 17 00:00:00 2001 From: marcindbar Date: Sun, 24 May 2015 00:50:52 +0200 Subject: [PATCH 4/4] [roguelike][marcin] Pickaxe update - ability to destroy doors added --- tiles.py | 48 ++++++++++++++++++++++++++++++------------------ 1 file changed, 30 insertions(+), 18 deletions(-) diff --git a/tiles.py b/tiles.py index cf2bc9a..b4173b0 100644 --- a/tiles.py +++ b/tiles.py @@ -97,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: @@ -120,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): @@ -135,26 +141,32 @@ 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):