-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgame_functions.py
222 lines (179 loc) · 7 KB
/
game_functions.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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
import time
import random
import game_includes
import game_text
# Global invenory list
inventory = []
def play_adventure():
inventory = []
intro(inventory)
# Validates input from the user
def validate_input(prompt, options):
# print(options)
while True:
response = input(prompt).lower()
for option in options:
if option in response:
# print (option)
return option
slow_print("\n\nI'm sorry. I don't understand. Please try again.\n\n")
# Randomly selects combat description line.
def rand_combat(inventory, actor):
if actor == "monster":
index = random.randint(0, len(game_includes.monster_damage) - 1)
combat_line = game_includes.monster_damage[index]
return combat_line
if actor == "player":
if game_includes.inv_item1 in inventory:
index = random.randint(0, len(game_includes.shillelagh_damage) - 1)
combat_line = game_includes.shillelagh_damage[index]
return combat_line
else:
index = random.randint(0, len(game_includes.unarmed_damage) - 1)
combat_line = game_includes.unarmed_damage[index]
return combat_line
# Prints messages to the console with a delay.
def slow_print(message):
print(message)
time.sleep(1)
# Prints lines with delay
def delay_lines(linelist):
for line in range(len(linelist)):
slow_print(linelist[line])
# Prints lines without delay
def fast_lines(linelist):
for line in range(len(linelist)):
print(linelist[line])
time.sleep(1)
# Prints damage information during fight
def print_fight(inventory, damage, actor):
combat_line = rand_combat(inventory, actor)
time.sleep(2)
print(combat_line + str(damage) + " damage!")
# Prints introductory text to the console.
def intro(inventory):
delay_lines(game_text.intro_lines)
cliff(inventory)
# Does attack calculations for player and monster
def hit_roll(inventory, actor):
if actor == "monster":
damage = random.randint(5, 10)
print_fight(inventory, damage, actor)
return(damage)
if actor == "player":
damage = random.randint(1, 2)
if game_includes.inv_item1 in inventory:
damage *= 10
print_fight(inventory, damage, actor)
return(damage)
# Controls the fight with the monster
def fight(inventory, order):
player_hp = game_includes.player_hp
monster_hp = game_includes.monster_hp
if order == "ballad":
damage = hit_roll(inventory, "monster")
player_hp = player_hp - damage
delay_lines(game_text.ballad2)
elif order == "fight":
damage = hit_roll(inventory, "player")
monster_hp = monster_hp - damage
delay_lines(game_text.attack)
while (player_hp > 0 and monster_hp > 0):
print("player HP: " + str(player_hp))
print("monster HP: " + str(monster_hp))
damage = hit_roll(inventory, "player")
monster_hp = monster_hp - damage
if monster_hp < 1:
break
damage = hit_roll(inventory, "monster")
player_hp = player_hp - damage
if player_hp < 1:
delay_lines(game_text.fight_lose)
play_again()
elif monster_hp < 1:
delay_lines(game_text.fight_win)
inventory.append(game_includes.inv_item2)
cliff(inventory)
# Description and actions at the cliff.
def cliff(inventory):
delay_lines(game_text.cliff_lines)
fast_lines(game_text.cliff_inputs)
cliff_choice = validate_input(game_text.input_req,
game_includes.num_input1 +
game_includes.num_input2 +
game_includes.num_input3 +
game_includes.semantic_cliff1 +
game_includes.semantic_cliff2 +
game_includes.semantic_cliff3)
# double paranthesis to pass pycodestyle error 129
if ((cliff_choice in game_includes.num_input1 or cliff_choice in
game_includes.semantic_cliff1)):
if game_includes.inv_item3 in inventory:
delay_lines(game_text.cliff_wins)
play_again()
else:
delay_lines(game_text.cliff_dies)
play_again()
elif (cliff_choice in game_includes.num_input2 or cliff_choice in
game_includes.semantic_cliff2):
house(inventory)
elif (cliff_choice in game_includes.num_input3 or cliff_choice in
game_includes.semantic_cliff3):
hill(inventory)
# Description and action at the house.
def house(inventory):
delay_lines(game_text.house_lines)
if (game_includes.inv_item2 in inventory and game_includes.inv_item3
not in inventory):
delay_lines(game_text.house_has_item2)
inventory.append(game_includes.inv_item3)
cliff(inventory)
elif (game_includes.inv_item1 in inventory and game_includes.inv_item2
not in inventory):
delay_lines(game_text.house_no_item2)
cliff(inventory)
elif game_includes.inv_item3 in inventory:
delay_lines(game_text.house_has_item3)
cliff(inventory)
else:
delay_lines(game_text.house_no_item1)
inventory.append(game_includes.inv_item1)
cliff(inventory)
# Description and action on the hill.
def hill(inventory):
delay_lines(game_text.hill_lines)
if game_includes.inv_item2 not in inventory:
delay_lines(game_text.hill_fight)
fast_lines(game_text.hill_inputs)
hill_choice = validate_input(game_text.input_req,
game_includes.num_input1 +
game_includes.num_input2 +
game_includes.num_input3 +
game_includes.semantic_hill1 +
game_includes.semantic_hill2 +
game_includes.semantic_hill3)
if ((hill_choice in game_includes.num_input1 or hill_choice
in game_includes.semantic_hill1)):
delay_lines(game_text.ballad1)
fight(inventory, "ballad")
elif (hill_choice in game_includes.num_input2 or hill_choice
in game_includes.semantic_hill2):
delay_lines(game_text.hill_runs)
cliff(inventory)
elif (hill_choice in game_includes.num_input3 or hill_choice
in game_includes.semantic_hill3):
if game_includes.inv_item1 in inventory:
delay_lines(game_text.shillelagh)
else:
delay_lines(game_text.no_shillelagh)
fight(inventory, "fight")
else:
delay_lines(game_text.hill_has_item2)
cliff(inventory)
# Runs runs game again.
def play_again():
play_choice = validate_input(game_text.input_rep,
game_includes.bool_input_yes +
game_includes.bool_input_no)
if play_choice in game_includes.bool_input_yes:
play_adventure()