Untitled
import random class Player: def __init__(self): self.ammo = 10 # Number of available bullets self.accuracy = 0.7 # Reloading accuracy (70% accuracy) def reload(self): if self.ammo < 10: self.ammo += 1 self.accuracy += 0.1 # Increase reloading accuracy by 10% print("Reloading...") else: print("Ammunition is already full!") def shoot(self): if self.ammo > 0: if random.random() < self.accuracy: self.ammo -= 1 print("Enemy hit!") else: print("Missed!") else: print("No ammunition left. Please reload!") def display_ammo(self): print(f"Ammunition: {self.ammo}") class Enemy: def __init__(self): self.health = random.randint(50, 100) def take_damage(self, damage): self.health -= damage if self.health <= 0: print("Enemy defeated!") else: print(f"Enemy health: {self.health}") # Game loop player = Player() enemy = Enemy() while True: print("\n1. Shoot") print("2. Reload") print("3. Quit") choice = input("Enter your choice (1-3): ") if choice == '1': player.shoot() enemy.take_damage(20) # Assuming each successful shot deals 20 damage player.display_ammo() elif choice == '2': player.reload() player.display_ammo() elif choice == '3': print("Game Over!") break else: print("Invalid choice. Choose again!") # Additional environment variables (example) environment = { "time": "night", "weather": "rainy", "location": "jungle" } # Additional enemy logic (example) def enemy_logic(environment): if environment["location"] == "jungle": print("Enemy hiding in the bushes!") elif environment["time"] == "night" and environment["weather"] == "rainy": print("Enemy has low visibility!") else: print("Enemy ready to attack!") enemy_logic(environment)
Leave a Comment