Skip to content

gunΒ #32

Description

@susboy12345

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.")

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions