» pip install dnd-character
I made this as a quarantine project probably some time around May/June of last year. It was made in a span of probably a week or two. What initially made me think about making a character generator was that back when we were allowed to play D&D our group was somewhat notorious for accidentally stumbling on random NPCs and I figured something like this could help a DM out if they use a laptop while they run their game.
This project was also my foray into Python, and was just for fun.
I wanted to post it here to get some feedback on what I could do better because I'm sure parts of it are very sloppy.
https://github.com/ThatCoolNerd/dnd_5e_character_generator
Some things that I think could be improved:
How the stereotypical alignment and class is generated
How the stats are optimized on a per-class basis
How names are selected
Thanks for reading!
Rolling Stats for a DND Character in Python - Stack Overflow
list - Dungeons and Dragons Character Sheet generator using Python - Stack Overflow
Any D&D fans want to check out my Random Character Generator?
Your code is really clean. It almost respect pep-8. Try to install flake8 and check your code:
flake8 main.py
I am a big fan of docstring that will make your functions shine more ! My favorite format is the google one, but numpy is also a good choice.
For example your die function in functions.py would look like:
def die(count: int, size: int = 6):
""" Generate dice rolls
Args:
count: number of rolls
size: number of faces
Returns:
list of rolls
"""
dice = [randint(1, size) for _ in range(count)]
return diceFinally the last bit of advice would be about organization of your files. We usually put the functions/classes in a specific folder. You could for example move armor.py, races.py, weapons.py classes.py functions.py into a src/ folder.
Let me get it straight to you, your code is overall clean, well organized and documented, the advises will only make your code looks "more professional". If you want to be fancy you could also implement few pytest then set up Travis and codecov, you'll be able to brag with badges !
Congratulations for self-teaching yourself python !
More on reddit.comPython script to auto generate PDF Character sheets from "Fifth Edition Character Sheet"
Videos
» pip install dungeonsheets
A set is not the right choice here; you do need all of the dice.
A function like this should do:
def roll_dice_discarding_lowest(n_dice, dice_rank):
results = [ # Generate n_dice numbers between [1, dice_rank]
random.randint(1, dice_rank)
for n
in range(n_dice)
]
lowest = min(results) # Find the lowest roll among the results
results.remove(lowest) # Remove the first instance of that lowest roll
return sum(results) # Return the sum of the remaining results.
To roll 5d6 discarding the lowest result, call roll_dice_discarding_lowest(5, 6).
roll = []
for i in range(6):
rla = []
for i in range(4):
rla.append(random.randint(1,6))
rla.sort()
roll.append(rla[1]+rla[2]+rla[3])
print("Your first roll is a " + str(roll[0]) + ".")