-
Notifications
You must be signed in to change notification settings - Fork 0
/
tiles.py
113 lines (84 loc) · 2.93 KB
/
tiles.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
import items, enemies, actions, world
class MapTile:
def adjacent_moves(self):
"""Returns all move actions for adjacent tiles."""
moves =[]
if world.tile_exists(self.x + 1, self.y):
moves.append(actions.MoveEast())
if world.tile_exists(self.x - 2,self.y):
moves.append(actions.MoveWest())
if world.tile_exists(self.x, self.y -1):
moves.append(actions.MoveNorth())
if world.tile_exists(self.x, self.y+1):
moves.append(actions.MoveSouth())
return moves
def available_actions(self):
moves = self.adjacent_moves()
moves.append(actions.ViewInventory())
return moves
def __init__(self, x, y):
self.x = x
self.y = y
def intro_text(self):
raise NotImplementedError()
class StartingRoom(MapTile):
def intro_text(self):
return """
You find yourself in a cave with a flickering tourch on the wall.
You can make out four paths. each equally as dark and foreboding.
"""
def modfiy_player(self,player):
#room has no action on player
pass
class LootRoom(MapTile):
def __init__(self, x, y, item):
self.iitem = item
super().__init__(x,y)
def add_loot(self,player):
player.inventory.append(self.item)
def modify_player(self,player):
self.add_loot(player)
class EnemyRoom(MapTile):
def __init__(self, x, y,enemy):
self.enemy =enemey
super().__init__(x,y)
def modify_player(self,the_player):
if self.senemy.is_alive():
the_player.hp = the_player.hp -self.enemy.damage
print("Enemy does {} damage. You have {} hp remaining.".format(self.enemy.damage,the_player.hp))
def available_actions(self):
if self.enemy.is_alive():
return [action.Flee(tile=self),actions.Attack(enemy= self.enemy)]
else:
return self.adjacent_moves()
class GiantSpiderRoom(EnemyRoom):
def __init__(self, x, y):
super().__init__(x,y, enemies.GiantSpider())
def intro_text(self):
if self.enemy.is_allive():
return """
A giant spider jumps down from its web in front of you!
"""
else:
return """
The corpse of a dead spider rots on the ground.
"""
class FindDaggerRoom(LootRoom):
def __init__(self, x, y):
super().__init__(x,y, items.Dagger())
def intro_text(self):
return """
You notice somthing shiney in the corner; its a dagger!
You pick it up
"""
class LeaveCaveRoom(MapTile):
def intro_text(self):
return """
you see a bright light in the distance
...
it grows as you approach,
its sunlight!
Victory is Yours!
"""
def modify_player(self, player):
player.victory = True