-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
157 lines (127 loc) · 5.62 KB
/
main.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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
import sys
try:
import pyfiglet
except ImportError:
pyfiglet = None
import characters
import battle
import items
import tools
import world
# screen width (for kindle)
block_width = 48
def main():
# figlet fonts
if pyfiglet != None:
fig_death = pyfiglet.Figlet(font='poison')
fig_win = pyfiglet.Figlet(font='doom')
# print intro
tools.interface.do_intro()
# get game setup
player_name, difficulty, starting_items = tools.interface.game_setup()
# define hero
me = characters.Hero(name=player_name, hp=100, lvl=1)
# apply difficulty
if difficulty == tools.interface.DIFF_EASY:
height = 5
width = 5
enemy_rooms = 5
loot_rooms = 15
elif difficulty == tools.interface.DIFF_MEDIUM:
height = 7
width = 7
enemy_rooms = 15
loot_rooms = 15
elif difficulty == tools.interface.DIFF_HARD:
height = 8
width = 8
enemy_rooms = 50
loot_rooms = 5
if starting_items == tools.interface.ITEMS_FEW:
me.weapon = items.weapons.HandAxe()
me.body.head = items.armour.LeatherHelmet()
me.inventory.append(items.consumables.Medkit(quantity=1))
elif starting_items == tools.interface.ITEMS_MEDIUM:
me.weapon = items.weapons.Scimitar()
me.body.chest = items.armour.LeatherChest()
me.body.head = items.armour.LeatherHelmet()
me.body.legs = items.armour.LeatherLegs()
me.body.shield = items.armour.SmallShield()
me.inventory.append(items.consumables.Medkit(quantity=3))
elif starting_items == tools.interface.ITEMS_LOTS:
me.weapon = items.weapons.Katana()
me.body.boots = items.armour.LeatherBoots()
me.body.chest = items.armour.LeatherChest()
me.body.head = items.armour.LeatherHelmet()
me.body.legs = items.armour.LeatherLegs()
me.body.shield = items.armour.SmallShield()
me.inventory.append(items.consumables.Medkit(quantity=5))
world_map = world.mapping.Map(width, height, loot_rooms, enemy_rooms)
start_location = world.mapping.pick_rand_room(width, height)
me.location = start_location
try:
while True:
tools.utils.cls()
room = world_map.get_room(me.location)
print(tools.interface.build_room_scene(me, room, block_width))
if room.enemies:
for enemy in room.enemies:
if enemy.is_alive():
try:
battle.battle(me, enemy, room.boss)
except characters.WinException:
if pyfiglet != None:
print(fig_win.renderText('You defeated!'))
else:
print(tools.interface.text_centre('You Defeated!', block_width))
# enemy drops loot
while len(enemy.loot) > 0:
_loot = enemy.loot.pop()
room.loot.append(_loot)
print(tools.interface.text_centre('{} dropped {}'.format(enemy.name, _loot),
block_width))
room.description = '{} lays dead on the floor Dead!'.format(enemy.name)
tools.utils.pause()
except characters.DeadException:
if pyfiglet != None:
print(fig_death.renderText('You died!'))
else:
print(tools.interface.text_centre('You Died!', block_width))
sys.exit(2)
except characters.EscapeException:
print(tools.interface.text_centre('You ran from the battle!', block_width))
tools.utils.pause()
if room.loot:
room.description += '\n{} '.format(me.name)
room.description +='took the following from this room:\n'
while len(room.loot) > 0:
_loot = room.loot.pop()
me.add_item(_loot)
print(tools.interface.text_centre('{} found {}'.format(me.name, _loot),
block_width))
room.description += '[{}] '.format(_loot)
tools.utils.pause()
# add support for vendor/shop rooms
# coming soon...
# allow item use
tools.utils.cls()
print(tools.interface.build_room_scene(me, room, block_width))
tools.interface.use_item_free(me)
# get direction
tools.utils.cls()
print(tools.interface.build_room_scene(me, room, block_width))
direction = world.mapping.handle_move(world_map, me)
tools.utils.cls()
print(tools.interface.build_room_scene(me, room, block_width))
print("You head off towards the {}".format(direction))
tools.utils.pause()
except characters.WinBossException:
if pyfiglet != None:
fig_boss_win = pyfiglet.Figlet(font='caligraphy')
print(fig_boss_win.renderText('You'))
print(fig_boss_win.renderText('Win'))
else:
print(tools.interface.text_centre('\n\nYOU WON!!!!!\n\n', block_width))
sys.exit(0)
if __name__ == '__main__':
main()