Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
.*.swp
__pycache__
.idea
16 changes: 16 additions & 0 deletions items.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion map.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#######.#.......#######.#........#.....#.......................................#
#######.#...3...#######.#.######.#.....#.......................................#
#######.1.......#######.#.######.#.....#.......................................#
#######.#.......#######.#......#.#######.......................................#
#######P#.......#######.#......#.#######.......................................#
####....#.......#######.######.#.#######.......................................#
####+#######.##########+#......#.#######.......................................#
#........###.#########..#.######.#######.......................................#
Expand Down
84 changes: 58 additions & 26 deletions tiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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):
Expand All @@ -74,7 +89,6 @@ def open(self):
return "you used the teleport"


# new comment
class Door(Tile):
OPEN = 1
CLOSED = 2
Expand All @@ -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:
Expand All @@ -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):
Expand All @@ -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,
Expand All @@ -153,7 +184,8 @@ class TileFactory:
'1': KeyDoor,
'2': KeyFloor,
'3': Teleport,
'(': KnifeFloor
'(': KnifeFloor,
'P': PickaxeFloor,
}

@staticmethod
Expand Down