Advertisement
Guest User

Untitled

a guest
Jul 20th, 2019
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.18 KB | None | 0 0
  1. import time
  2.  
  3.  
  4. def fire_gun(magazine_capacity, reserve_capacity, fire_rate, time_to_reload):
  5. """parameters including the numerator/denominator, fire rate, and reload speed"""
  6.  
  7. rounds = magazine_capacity
  8.  
  9.  
  10. def reloading(time_to_reload):
  11. print('\nRELOADING', end='')
  12. for dot in range(time_to_reload):
  13. time.sleep(1)
  14. print('.', end='', flush=True)
  15.  
  16.  
  17. print('\nHold ENTER to shoot')
  18. print('\n\n{}/{}'.format(rounds, reserve_capacity))
  19.  
  20.  
  21. while rounds > 0 or reserve_capacity > 0:
  22. shoot = input()
  23.  
  24. rounds -= 1
  25. print('{}/{}'.format(rounds, reserve_capacity))
  26.  
  27. if rounds == 0 and reserve_capacity == 0:
  28. print('OUT OF AMMO')
  29. break
  30. elif shoot.upper() == 'DONE':
  31. sure = input('Are you sure?\n> ')
  32. if sure.lower() == 'y':
  33. break
  34. elif rounds == 0:
  35. reloading(time_to_reload)
  36. if reserve_capacity <= magazine_capacity:
  37. rounds += reserve_capacity
  38. reserve_capacity -= reserve_capacity
  39. else:
  40. rounds += magazine_capacity
  41. reserve_capacity -= magazine_capacity
  42. print('\n\n{}/{}'.format(rounds, reserve_capacity))
  43.  
  44.  
  45. time.sleep(fire_rate) # Faster!!
  46.  
  47.  
  48. def start():
  49. guns = {
  50. 'ASSAULT': lambda: fire_gun(40, 130, 0.1, 7),
  51. 'SHOTGUN': lambda: fire_gun(6, 30, 2, 12),
  52. 'SUBMACHINE': lambda: fire_gun(40, 200, 0, 5),
  53. 'SNIPER': lambda: fire_gun(1, 15, 0, 5),
  54. 'MARKSMAN': lambda: fire_gun(20, 100, 0.8, 9),
  55. 'PISTOL': lambda: fire_gun(10, 100, 0.6, 3),
  56. 'LAUNCHER': lambda: fire_gun(1, 10, 0, 7)
  57. }
  58. while True:
  59. firearm = input('CHOOSE YOUR GUN (ENTER to exit; VIEW to view gun selection)\n> ').upper()
  60.  
  61. if firearm == 'VIEW':
  62. print('\n')
  63. for gun in guns:
  64. print('| {}'.format(gun), end=' ')
  65. print('|\n')
  66. start()
  67. try:
  68. guns[firearm]()
  69. except KeyError:
  70. break
  71.  
  72.  
  73. if __name__ == "__main__":
  74. start()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement