Skip to content

Instantly share code, notes, and snippets.

@paulreece42
Created December 11, 2025 04:10
Show Gist options
  • Select an option

  • Save paulreece42/5ed82a2eb16e5ab609ce11402b6496db to your computer and use it in GitHub Desktop.

Select an option

Save paulreece42/5ed82a2eb16e5ab609ce11402b6496db to your computer and use it in GitHub Desktop.
This is example code generated by quen3-coder:30b on ollama, the prompt was simply: "Write a dungeons and dragons style game, in Python"
import random
import time
class Character:
def __init__(self, name, char_class):
self.name = name
self.char_class = char_class
self.level = random.randint(1, 6)
self.health = self.level * 10
self.max_health = self.health
self.attack = self.level * 3
self.defense = self.level * 2
self.xp = 0
self.gold = 10
self.inventory = []
self.equipped_weapon = None
self.equipped_armor = None
# Class-specific abilities
if char_class == "Warrior":
self.attack += 2
self.defense += 3
elif char_class == "Mage":
self.attack += 4
self.health -= 2
elif char_class == "Rogue":
self.attack += 1
self.defense += 1
self.health += 2
elif char_class == "Druid":
self.attack += 1
self.defense += 2
self.health += 3
elif char_class == "Thief":
self.attack += 1
self.defense += 1
self.health += 1
self.gold += 5
def take_damage(self, damage):
actual_damage = max(1, damage - self.defense)
self.health -= actual_damage
return actual_damage
def heal(self, amount):
self.health = min(self.max_health, self.health + amount)
def gain_xp(self, amount):
self.xp += amount
if self.xp >= self.level * 10:
self.level_up()
def level_up(self):
self.level += 1
self.max_health += 10
self.health = self.max_health
self.attack += 3
self.defense += 2
print(f"๐ŸŽ‰ {self.name} leveled up to level {self.level}!")
def show_stats(self):
print(f"\n--- {self.name} ({self.char_class}) ---")
print(f"Level: {self.level}")
print(f"Health: {self.health}/{self.max_health}")
print(f"Attack: {self.attack}")
print(f"Defense: {self.defense}")
print(f"XP: {self.xp}")
print(f"Gold: {self.gold}")
if self.inventory:
print(f"Inventory: {', '.join(self.inventory)}")
else:
print("Inventory: Empty")
class Monster:
def __init__(self, name, level):
self.name = name
self.level = level
self.health = level * 8
self.attack = level * 2
self.defense = level * 1
self.xp_reward = level * 5
self.gold_reward = level * 3
def take_damage(self, damage):
actual_damage = max(1, damage - self.defense)
self.health -= actual_damage
return actual_damage
class DnDGame:
def __init__(self):
self.party = []
self.current_location = "Village Square"
self.game_over = False
self.turn = 0
def start_game(self):
print("๐Ÿฐ Welcome to the Dungeons & Dragons Adventure! ๐Ÿฐ")
print("=" * 50)
print("You are on a quest to defeat the evil sorcerer!")
print("Choose your character and begin your journey...\n")
# Create party
self.create_party()
# Start adventure
self.adventure_loop()
def create_party(self):
print("Choose your character class:")
print("1. Warrior - High health and defense")
print("2. Mage - High attack power")
print("3. Rogue - Balanced stats")
print("4. Druid - Nature magic and health")
print("5. Thief - Stealth and gold")
for i in range(1, 4): # Create 3 characters
print(f"\nPlayer {i}, choose your class:")
choice = input("Enter 1-5: ")
classes = ["Warrior", "Mage", "Rogue", "Druid", "Thief"]
if choice.isdigit() and 1 <= int(choice) <= 5:
char_class = classes[int(choice) - 1]
else:
char_class = random.choice(classes)
print(f"Invalid choice, randomly selected {char_class}")
name = input(f"Enter name for {char_class}: ")
if not name:
name = f"Hero_{i}"
character = Character(name, char_class)
self.party.append(character)
print(f"Created {character.name} the {character.char_class}!")
def adventure_loop(self):
while not self.game_over and len(self.party) > 0:
self.turn += 1
print(f"\n{'='*50}")
print(f"Turn {self.turn} - {self.current_location}")
print(f"{'='*50}")
# Show party status
for character in self.party:
character.show_stats()
# Action choice
print("\nWhat would you like to do?")
print("1. Explore")
print("2. Rest")
print("3. Shop")
print("4. View Party")
print("5. Quit Game")
choice = input("Enter your choice (1-5): ")
if choice == "1":
self.explore()
elif choice == "2":
self.rest()
elif choice == "3":
self.shop()
elif choice == "4":
self.view_party()
elif choice == "5":
print("Thanks for playing!")
self.game_over = True
else:
print("Invalid choice!")
def explore(self):
locations = [
"Forest Clearing", "Cave Entrance", "Abandoned Temple",
"Mountain Path", "Swamp", "Ancient Ruins", "Dark Forest"
]
location = random.choice(locations)
self.current_location = location
print(f"\nYou explore the {location}...")
time.sleep(1)
encounter = random.random()
if encounter < 0.3: # 30% chance of monster
self.battle()
elif encounter < 0.6: # 30% chance of treasure
self.find_treasure()
elif encounter < 0.8: # 20% chance of event
self.event()
else: # 20% chance of nothing
print("You find nothing of interest.")
def battle(self):
monster_types = ["Goblin", "Orc", "Skeleton", "Wolf", "Spider", "Zombie"]
monster_name = random.choice(monster_types)
monster_level = random.randint(1, self.party[0].level + 2)
monster = Monster(monster_name, monster_level)
print(f"\nโš”๏ธ A {monster.name} (Level {monster.level}) appears!")
# Battle loop
while monster.health > 0 and any(char.health > 0 for char in self.party):
print(f"\n{monster.name} HP: {monster.health}")
# Player turn
for i, character in enumerate(self.party):
if character.health <= 0:
continue
print(f"\n{character.name}'s turn:")
print("1. Attack")
print("2. Heal")
print("3. Use Item")
action = input("Choose action (1-3): ")
if action == "1":
damage = random.randint(character.attack - 2, character.attack + 2)
actual_damage = monster.take_damage(damage)
print(f"{character.name} attacks for {actual_damage} damage!")
if monster.health <= 0:
print(f"๐ŸŽ‰ {monster.name} defeated!")
character.gain_xp(monster.xp_reward)
character.gold += monster.gold_reward
print(f"{character.name} gained {monster.xp_reward} XP and {monster.gold_reward} gold!")
break
elif action == "2":
heal_amount = random.randint(5, 10)
character.heal(heal_amount)
print(f"{character.name} heals for {heal_amount} HP!")
elif action == "3":
if character.inventory:
item = character.inventory.pop()
print(f"{character.name} uses {item}!")
if item == "Health Potion":
character.heal(15)
elif item == "Gold Piece":
character.gold += 1
else:
print("No items in inventory!")
# Monster turn
if monster.health > 0:
for character in self.party:
if character.health > 0:
damage = random.randint(monster.attack - 1, monster.attack + 1)
actual_damage = character.take_damage(damage)
print(f"{monster.name} attacks {character.name} for {actual_damage} damage!")
if character.health <= 0:
print(f"{character.name} has been defeated!")
# Check if party is defeated
if all(char.health <= 0 for char in self.party):
print("\n๐Ÿ’€ Your party has been defeated!")
self.game_over = True
def find_treasure(self):
treasures = [
"Health Potion", "Gold Piece", "Magic Scroll",
"Iron Sword", "Leather Armor", "Silver Ring"
]
treasure = random.choice(treasures)
print(f"\n๐Ÿ’ฐ You found a {treasure}!")
for character in self.party:
if treasure == "Health Potion":
character.heal(10)
print(f"{character.name} used the potion and healed 10 HP!")
else:
character.inventory.append(treasure)
print(f"{character.name} added {treasure} to inventory!")
def event(self):
events = [
"You find a mysterious map leading to a hidden treasure!",
"A friendly wizard offers to teach you a new spell!",
"You discover a hidden passage in the wall!",
"A merchant offers to buy your items at a good price!",
"You encounter a group of travelers who share their supplies!"
]
event = random.choice(events)
print(f"\n๐ŸŒŸ {event}")
if "map" in event:
print("The map shows a secret location!")
self.current_location = "Secret Cave"
elif "wizard" in event:
for character in self.party:
character.gain_xp(5)
print("All party members gained 5 XP!")
elif "merchant" in event:
gold_gained = random.randint(5, 15)
for character in self.party:
character.gold += gold_gained
print(f"You gained {gold_gained} gold from the merchant!")
def rest(self):
print("\n๐Ÿ˜ด You rest and recover your health...")
time.sleep(1)
for character in self.party:
if character.health < character.max_health:
heal_amount = min(10, character.max_health - character.health)
character.heal(heal_amount)
print(f"{character.name} recovered {heal_amount} HP!")
print("Rest complete!")
def shop(self):
print("\n๐Ÿช Welcome to the shop!")
print("Items for sale:")
print("1. Health Potion (5 gold) - Heals 10 HP")
print("2. Iron Sword (20 gold) - +5 attack")
print("3. Leather Armor (15 gold) - +3 defense")
print("4. Exit Shop")
while True:
choice = input("What would you like to buy? (1-4): ")
if choice == "4":
break
if choice == "1":
if any(char.gold >= 5 for char in self.party):
for character in self.party:
if character.gold >= 5:
character.gold -= 5
character.inventory.append("Health Potion")
print(f"{character.name} bought a Health Potion!")
break
else:
print("Not enough gold!")
elif choice == "2":
if any(char.gold >= 20 for char in self.party):
for character in self.party:
if character.gold >= 20:
character.gold -= 20
character.inventory.append("Iron Sword")
character.attack += 5
print(f"{character.name} bought an Iron Sword!")
break
else:
print("Not enough gold!")
elif choice == "3":
if any(char.gold >= 15 for char in self.party):
for character in self.party:
if character.gold >= 15:
character.gold -= 15
character.inventory.append("Leather Armor")
character.defense += 3
print(f"{character.name} bought Leather Armor!")
break
else:
print("Not enough gold!")
def view_party(self):
print("\n๐Ÿ‘ฅ Your Party:")
for i, character in enumerate(self.party):
print(f"{i+1}. {character.name} - {character.char_class} (Level {character.level})")
# Start the game
if __name__ == "__main__":
game = DnDGame()
game.start_game()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment