import time
import random
class Gun:
def init(self, name="Pistol", ammo=6):
self.name = name
self.ammo = ammo
self.max_ammo = ammo
def shoot(self):
if self.ammo > 0:
print("BANG! π«")
self.ammo -= 1
else:
print("Click... No ammo! β")
def reload(self):
print("Reloading...", end="")
time.sleep(1)
self.ammo = self.max_ammo
print(" Done! β
")
def status(self):
print(f"{self.name} | Ammo: {self.ammo}/{self.max_ammo}")
Main loop
gun = Gun()
while True:
gun.status()
action = input("Choose action: [s]hoot, [r]eload, [q]uit: ").lower()
if action == 's':
gun.shoot()
elif action == 'r':
gun.reload()
elif action == 'q':
print("Goodbye!")
break
else:
print("Invalid input.")
import time
import random
class Gun:
def init(self, name="Pistol", ammo=6):
self.name = name
self.ammo = ammo
self.max_ammo = ammo
Main loop
gun = Gun()
while True:
gun.status()
action = input("Choose action: [s]hoot, [r]eload, [q]uit: ").lower()