Sure, here is a simple Python program that will start an RPG (Role-Playing Game) game:
# main.py
import random
class Character:
def __init__(self, name, health, strength, agility):
self.name = name
self.health = health
self.strength = strength
self.agility = agility
def attack(self, target):
damage = self.strength - target.agility
if damage < 0:
damage = 0
target.health -= damage
if target.health <= 0:
print(f"{target.name} has been defeated!")
exit()
print(f"{self.name} attacked {target.name} for {damage} damage.")
def display_stats(self):
print(f"Name: {self.name}")
print(f"Health: {self.health}")
print(f"Strength: {self.strength}")
print(f"Agility: {self.agility}")
class Enemy(Character):
def __init__(self, name, health, strength, agility, loot):
super().__init__(name, health, strength, agility)
self.loot = loot
def drop_loot(self):
print(f"You found {self.loot} dropped by {self.name}.")
def start_game():
player = Character("Player", 100, 20, 15)
print("Welcome to the RPG game!")
print("Your current stats:")
player.display_stats()
enemies = [
Enemy("Goblin", 50, 10, 15, "Goblin Sword"),
Enemy("Orc", 80, 20, 20, "Orc Axe"),
Enemy("Dragon", 200, 40, 30, "Dragon Scale")
]
while True:
enemy = random.choice(enemies)
print(f"\nYou encountered a {enemy.name}!")
player.attack(enemy)
enemy.attack(player)
player.display_stats()
if player.health <= 0:
print("Game Over!")
break
if __name__ == "__main__":
start_game()
This program defines a Character class with attributes for name, health, strength, and agility. It also defines an Enemy class that inherits from Character and has an additional loot attribute. The start_game function sets up a player character and a list of enemies, then enters a loop in which the player battles a randomly chosen enemy. If the player's health drops to 0 or below, the game ends.