-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathworld.py
124 lines (102 loc) · 3.79 KB
/
world.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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
# E Y E B L I N K
# ====================================== WORLD ================================================
import enemies
import random
class MapTile:
def __init__(self, x, y):
self.x = x
self.y = y
def intro_text(self):
raise NotImplementedError("Create a subclass instead!")
def modify_player(self,player):
pass
class ThreeCyborgsTile(MapTile):
def intro_text(self):
return """
There are lots of shelves full of parts, dirt and junk.
You can see a stand with three cyborgs on it.
They look asleep and abandoned for some reason.
"""
class StartTile(MapTile):
def intro_text(self):
return """
There's only a wall with a strange drawing on it.
There are doors to the east and the west.
There's a plastic curtain to the north.
"""
class CrystalMachineTile(MapTile):
def intro_text(self):
return """
Some sort of machinery is inside a crystal container
with a built-in electromagnetic door.
The door seems operated from a panel on the right.
You look carefully at the panel and see a red button,
a keypad and a holographic display.
"""
class DesertTile(MapTile):
def intro_text(self):
return """
You open the door but you can't go nowhere from here.
The door is suspended on the nothingness.
All you can see is an infinite desert.
"""
class CenterTile(MapTile):
def intro_text(self):
return """
You find yourself in another chamber.
There are doors on your left and right.
In the center there's a drawing, it seems a labyrinth ...
To the north there's a long and dark corridor.
"""
class OceanTile(MapTile):
def intro_text(self):
return """
You open the door but you can't go nowhere from here.
The door is suspended on the nothingness.
All you can see is an infinite ocean.
"""
class ExitTile(MapTile):
def intro_text(self):
return """
After walking for a while you arrive to a large room.
Poweful lights and pure white walls are so bright that you can barely open your eyes.
The only thing here is an artifact like a ring. It's void within.
It has flashing lights on it.
"""
class EnemyTile(MapTile):
def __init__(self, x, y):
r = random.random()
if r < 0.75:
self.enemy = enemies.GlassSpider()
self.alive_text = "A Glass Spider attacks you!"
self.dead_text = '''The floor is full of Glass Spider junk.
...
There's nothing more here but the remainings of some droids.'''
else:
self.enemy = enemies.Guardian()
self.alive_text = "A Guardian attacks you!"
self.dead_text = '''The floor is full of Guardian parts.
...
There's nothing more here but the remainings of some droids.'''
super().__init__(x,y)
def intro_text(self):
if self.enemy.is_alive():
return self.alive_text
else:
return self.dead_text
def modify_player(self, player):
if self.enemy.is_alive():
player.hp = player.hp - self.enemy.damage
print("Enemy does {} damage. You have {} HP remaining.".format(self.enemy.damage, player.hp))
world_map = [
[EnemyTile(0,0),ExitTile(1,0),EnemyTile(2,0)],
[DesertTile(0,1),CenterTile(1,1),OceanTile(2,1)],
[ThreeCyborgsTile(0,2),StartTile(1,2),CrystalMachineTile(2,2)]
]
def tile_at(x,y): # locates the tile at a coordinate
if x < 0 or y < 0:
return None
try:
return world_map[y][x]
except IndexError:
return None