import streamlit as st import random class DNDCharacter: def __init__(self, name, char_class, level, race, background, alignment): self.name = name self.char_class = char_class self.level = level self.race = race self.background = background self.alignment = alignment self.stats = { "Strength": 0, "Dexterity": 0, "Wisdom": 0, "Charisma": 0, "Constitution": 0, "Intelligence": 0 } self.hit_points = 0 self.armor_class = 0 self.initiative = 0 self.speed = 0 self.proficiencies = [] self.equipment = [] self.features_and_traits = [] self.spells = [] def roll_stats(self): for stat in self.stats: self.stats[stat] = random.randint(1, 20) def show_stats(self): st.write("Strength: ", self.stats["Strength"]) st.write("Dexterity: ", self.stats["Dexterity"]) st.write("Wisdom: ", self.stats["Wisdom"]) st.write("Charisma: ", self.stats["Charisma"]) st.write("Constitution: ", self.stats["Constitution"]) st.write("Intelligence: ", self.stats["Intelligence"]) def show_character_sheet(self): st.write("Name: ", self.name) st.write("Class: ", self.char_class) st.write("Level: ", self.level) st.write("Race: ", self.race) st.write("Background: ", self.background) st.write("Alignment: ", self.alignment) self.show_stats() st.write("Hit Points: ", self.hit_points) st.write("Armor Class: ", self.armor_class) st.write("Initiative: ", self.initiative) st.write("Speed: ", self.speed) st.write("Proficiencies: ", self.proficiencies) st.write("Equipment: ", self.equipment) st.write("Features and Traits: ", self.features_and_traits) st.write("Spells: ", self.spells) # Streamlit app st.title("D&D Character Sheet") name = st.text_input("Name") char_class = st.text_input("Class") level = st.number_input("Level", min_value=1, max_value=20, value=1) race = st.text_input("Race") background = st.text_input("Background") alignment = st.text_input("Alignment") if st.button("Roll Stats"): character = DNDCharacter(name, char_class, level, race, background, alignment) character.roll_stats() character.show_character_sheet()