-
Notifications
You must be signed in to change notification settings - Fork 0
/
golf_game.py
239 lines (199 loc) · 8 KB
/
golf_game.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
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
import random
#Clubs setup
driver_distances = list(range(230, 280, 5))
low_distances = list(range(185, 215, 5))
mid_distances = list(range(130, 185, 5))
high_distances = list(range(90, 135, 5))
gap_wedge_distances = list(range(50, 85, 5))
lob_wedge_distances = list(range(10, 50, 5))
putt_outcomes = [1,2,3]
#Define functions for hitting clubs
def hit_driver():
club_distance = random.choice(driver_distances)
return club_distance
def hit_low_iron():
club_distance = random.choice(low_distances)
return club_distance
def hit_mid_iron():
club_distance = random.choice(mid_distances)
return club_distance
def hit_high_iron():
club_distance = random.choice(high_distances)
return club_distance
def hit_gap_wedge():
club_distance = random.choice(gap_wedge_distances)
return club_distance
def hit_lob_wedge():
club_distance = random.choice(lob_wedge_distances)
return club_distance
def finish_hole():
finish = random.choice(putt_outcomes)
return finish
#Hole/Course Setup
full_hole_range = list(range(130,520,5))
par3_range = list(range(130,255,5))
par4_range = list(range(255,445,5))
par5_range = list(range(445,520,5))
par3_4_range = par3_range + par4_range
par3_5_range = par3_range + par5_range
par4_5_range = par4_range + par5_range
par3_count = 0
par4_count = 0
par5_count = 0
#Scorecard setup
total_strokes = 0
total_to_par = 0
#Intro prompt
print()
print("Welcome to Dan's Golf Course! Are you ready to play?")
print()
initial_answer = input("yes/no: ")
if initial_answer == "no":
print()
print("Come back when you are ready to play.")
print()
exit()
else:
print()
print("Great lets go!")
print()
print()
club_message = "Here are your club choices: Driver, Low Iron, Mid Iron, High Iron, Gap Wedge, Lob Wedge"
print(club_message)
print()
print()
print()
#Main game
#Setting up loop for each hole 1-9
for x in range(1, 10):
#Set up hole count restrictions on par
if par3_count < 2 and par4_count < 5 and par5_count < 2:
hole_length = random.choice(full_hole_range)
if par3_count >= 2 and par4_count < 5 and par5_count < 2:
hole_length = random.choice(par4_5_range)
if par3_count >= 2 and par4_count < 5 and par5_count >= 2:
hole_length = random.choice(par4_range)
if par3_count < 2 and par4_count < 5 and par5_count >= 2:
hole_length = random.choice(par3_4_range)
if par3_count < 2 and par4_count >= 5 and par5_count >= 2:
hole_length = random.choice(par3_range)
if par3_count >= 2 and par4_count >= 5 and par5_count < 2:
hole_length = random.choice(par5_range)
if par3_count < 2 and par4_count >= 5 and par5_count < 2:
hole_length = random.choice(par3_5_range)
#Set up par for the hole
if hole_length <= 250:
par = 3
par3_count += 1
elif hole_length > 250 and hole_length <= 440:
par = 4
par4_count += 1
elif hole_length > 440:
par = 5
par5_count += 1
#Set initial parameters before starting a hole
distance_remaining = hole_length
hole_shots = 0
#Show player the hole information
print("Hole #" + str(x) + " is a " + str(hole_length) + "-yard Par " + str(par) + "." )
print()
#Start loop to be able to choose clubs while at least 20 yards away
while distance_remaining >= 20:
club = input("What club would you like to use? ")
if club == "Driver" or club == "driver":
shot_distance = hit_driver()
print()
print("You hit your Driver " + str(shot_distance) + " yards.")
distance_remaining = abs(distance_remaining - shot_distance)
print("You have " + str(distance_remaining) + " yards left.")
print()
hole_shots += 1
elif club == "Low Iron" or club == "low iron" or club == "Low iron" or club == "low Iron" or club == "low" or club == "Low":
shot_distance = hit_low_iron()
print()
print("You hit your Low Iron " + str(shot_distance) + " yards.")
distance_remaining = abs(distance_remaining - shot_distance)
print("You have " + str(distance_remaining) + " yards left.")
print()
hole_shots += 1
elif club == "Mid Iron" or club == "mid iron" or club == "Mid iron" or club == "mid Iron" or club == "mid" or club == "Mid":
shot_distance = hit_mid_iron()
print()
print("You hit your Mid Iron " + str(shot_distance) + " yards.")
distance_remaining = abs(distance_remaining - shot_distance)
print("You have " + str(distance_remaining) + " yards left.")
print()
hole_shots += 1
elif club == "High Iron" or club == "high iron" or club == "High iron" or club == "high Iron" or club == "high" or club == "High":
shot_distance = hit_high_iron()
print()
print("You hit your High Iron " + str(shot_distance) + " yards.")
distance_remaining = abs(distance_remaining - shot_distance)
print("You have " + str(distance_remaining) + " yards left.")
print()
hole_shots += 1
elif club == "Gap Wedge" or club == "gap wedge" or club == "Gap wedge" or club == "gap Wedge" or club == "gap" or club == "Gap":
shot_distance = hit_gap_wedge()
print()
print("You hit your Gap Wedge " + str(shot_distance) + " yards.")
distance_remaining = abs(distance_remaining - shot_distance)
print("You have " + str(distance_remaining) + " yards left.")
print()
hole_shots += 1
elif club == "Lob Wedge" or club == "lob wedge" or club == "Lob wedge" or club == "lob Wedge" or club == "lob" or club == "Lob":
shot_distance = hit_lob_wedge()
print()
print("You hit your Lob Wedge " + str(shot_distance) + " yards.")
distance_remaining = abs(distance_remaining - shot_distance)
print("You have " + str(distance_remaining) + " yards left.")
print()
hole_shots += 1
#Finish the hole by putting
if distance_remaining < 20:
if distance_remaining == 0:
putts = 0
else:
putts = finish_hole()
hole_strokes = hole_shots + putts
hole_to_par = hole_strokes - par
total_strokes += hole_strokes
total_to_par += hole_to_par
#Show player hole/round scoring info
if putts == 0:
print("You're in the hole! You're in for " + str(hole_strokes) + " strokes.")
else:
print("You're on the green! After " + str(putts) + " putt(s), you're in for " + str(hole_strokes) + " strokes.")
if hole_to_par > 0:
print("Your score for the hole is +" + str(hole_to_par) + " to par.")
elif hole_to_par == 0:
print("Your score for the hole is even to par.")
else:
print("Your score for the hole is " + str(hole_to_par) + " to par.")
print()
print("You've hit a total of " + str(total_strokes) + " strokes so far.")
if total_to_par > 0:
print("Your score for the round is +" + str(total_to_par) + " to par.")
elif total_to_par == 0:
print("Your score for the round is even to par.")
else:
print("Your score for the round is " + str(total_to_par) + " to par.")
print()
print()
print()
#Final score messages & exit prompt
print("Congratulations on finishing your 9-hole round!")
print("Your stroke total is " + str(total_strokes) + ".")
if total_to_par > 0:
print("Your score for the day is +" + str(total_to_par) + " to par.")
elif total_to_par == 0:
print("Your score for the day is even to par.")
else:
print("Your score for the day is " + str(total_to_par) + " to par.")
print()
print()
print("THANKS FOR PLAYING! PLEASE SEND ME ANY FEEDBACK.")
print()
print()
leave = input("type 'exit' to exit ")
if leave == "exit":
exit()