import random
class Character:
def __init__(self, name, race):
self.name = name
self.race = race
self.level = 1
self.experience = 0
self.skills = []
self.is_alive = True
def gain_experience(self, amount):
self.experience += amount
if self.experience >= 10 * self.level:
self.level_up()
def level_up(self):
self.level += 1
self.experience = 0
print(f"{self.name} leveled up to level {self.level}!")
self.learn_new_skill()
def learn_new_skill(self):
skills_available = {
"Slime": ["Acid Spray", "Slime Shield"],
"Human": ["Double Strike", "Shield Bash"],
"Elf": ["Nature's Wrath", "Eagle Eye"],
"Beastman": ["Feral Charge", "Claw Attack"]
}
if self.level % 3 == 0: # Learn a new skill every 3 levels
new_skill = random.choice(skills_available[self.race])
self.skills.append(new_skill)
print(f"You have learned a new skill: {new_skill}!")
class Game:
def __init__(self):
self.character = None
def choose_race(self):
print("Choose your race:")
print("1. Slime")
print("2. Human")
print("3. Elf")
print("4. Beastman")
choice = input("Enter the number of your choice: ")
races = {
"1": ("Slime", ["Absorb", "Basic Movement"]),
"2": ("Human", ["Swordsmanship", "Archery"]),
"3": ("Elf", ["Magic", "Agility"]),
"4": ("Beastman", ["Strength", "Speed"])
}
if choice in races:
race, skills = races[choice]
name = input("Enter your character's name: ")
self.character = Character(name, race)
self.character.skills.extend(skills)
print(f"You chose {race}. Your skills are: {', '.join(skills)}")
else:
print("Invalid choice. Defaulting to Human.")
self.character = Character("Hero", "Human")
self.character.skills = ["Swordsmanship", "Archery"]
def explore_forest(self):
print("\nYou venture deeper into the forest...")
encounter = random.choice(["friendly", "hostile"])
if encounter == "friendly":
self.friendly_encounter()
else:
self.hostile_encounter()
def friendly_encounter(self):
print("You encounter a friendly creature!")
choice = input("Do you want to (1) Befriend or (2) Ignore? ")
if choice == "1":
print("You befriended the creature! You gain experience.")
self.character.gain_experience(5)
elif choice == "2":
print("You chose to ignore the creature.")
else:
print("Invalid option. The creature leaves.")
def hostile_encounter(self):
print("You encounter a hostile creature!")
choice = input("Do you want to (1) Fight or (2) Run away? ")
if choice == "1":
self.fight()
elif choice == "2":
print("You escaped safely!")
else:
print("Invalid option. You hesitate and the creature attacks!")
self.character.is_alive = False
def fight(self):
print("You decide to fight the creature!")
success = random.choice([True, False])
if success:
print("You defeated the creature and gained experience!")
self.character.gain_experience(7)
else:
print("The creature is too strong! You were defeated.")
self.character.is_alive = False
def absorb(self):
print("\nYou absorb some nutrients from the environment...")
print("You feel stronger!")
self.character.gain_experience(3)
def play(self):
self.choose_race()
while self.character.is_alive:
print(f"\nCurrent Level: {self.character.level}, Experience: {self.character.experience}")
print("Current Skills: " + ", ".join(self.character.skills))
print("What do you want to do?")
print("1. Explore the forest.")
print("2. Try to absorb something.")
choice = input("Choose an option (1 or 2): ")
if choice == "1":
self.explore_forest()
elif choice == "2":
self.absorb()
else:
print("Invalid option. Please choose again.")
print("Game Over. Thank you for playing!")
# Start the game
if __name__ == "__main__":
game = Game()
game.play()