Created
July 9, 2019 00:39
-
-
Save tyronewantedsmok/d180b38c0796a6ca71f6f4df7554404b to your computer and use it in GitHub Desktop.
gun simulator
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import time | |
def fire_gun(magazine_capacity, reserve_capacity, fire_rate, time_to_reload): | |
"""parameters including the numerator/denominator, fire rate, and reload speed""" | |
rounds = magazine_capacity | |
def reloading(time_to_reload): | |
print('\nRELOADING', end='') | |
for dot in range(time_to_reload): | |
time.sleep(1) | |
print('.', end='', flush=True) | |
print('\nHold ENTER to shoot') | |
print('\n\n{}/{}'.format(rounds, reserve_capacity)) | |
while rounds > 0 or reserve_capacity > 0: | |
shoot = input() | |
rounds -= 1 | |
print('{}/{}'.format(rounds, reserve_capacity)) | |
if rounds == 0 and reserve_capacity == 0: | |
print('OUT OF AMMO') | |
break | |
elif shoot.upper() == 'DONE': | |
sure = input('Are you sure?\n> ') | |
if sure.lower() == 'y': | |
break | |
elif rounds == 0: | |
reloading(time_to_reload) | |
if reserve_capacity <= magazine_capacity: | |
rounds += reserve_capacity | |
reserve_capacity -= reserve_capacity | |
else: | |
rounds += magazine_capacity | |
reserve_capacity -= magazine_capacity | |
print('\n\n{}/{}'.format(rounds, reserve_capacity)) | |
time.sleep(fire_rate) # Faster!! | |
def start(): | |
guns = { | |
'ASSAULT': lambda: fire_gun(40, 130, 0.1, 7), | |
'SHOTGUN': lambda: fire_gun(6, 30, 2, 12), | |
'SUBMACHINE': lambda: fire_gun(40, 200, 0, 5), | |
'SNIPER': lambda: fire_gun(1, 15, 0, 5), | |
'MARKSMAN': lambda: fire_gun(20, 100, 0.8, 9), | |
'PISTOL': lambda: fire_gun(10, 100, 0.6, 3), | |
'LAUNCHER': lambda: fire_gun(1, 10, 0, 7) | |
} | |
while True: | |
firearm = input('CHOOSE YOUR GUN (ENTER to exit; VIEW to view gun selection)\n> ').upper() | |
if firearm == 'VIEW': | |
print('\n') | |
for gun in guns: | |
print('| {}'.format(gun), end=' ') | |
print('|\n') | |
start() | |
try: | |
guns[firearm]() | |
except KeyError: | |
break | |
if __name__ == "__main__": | |
start() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You added in another never returning recursion in line 66. Either put a
continue
there, which will skip the rest of the loop, or movetry: ... except: ...
into anelse
branch.