Last active
February 10, 2022 18:13
-
-
Save fogus/a2ce8333eb6ec8c6ad77ffbbfd438248 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import random | |
class Die: | |
def __init__(self, n): | |
self.sides = n | |
def roll(self): | |
return random.randint(1, self.sides) | |
dice = [Die(6), Die(6), Die(6)] | |
def rollAll(dice): | |
result = [] | |
for d in dice: | |
result.append(d.roll()) | |
return result | |
def sumDice(dice): | |
return sum(rollAll(dice)) | |
def rollAttributes(dice): | |
attrs = {} | |
for attribute in ["Str", "Dex", "Con", "Int", "Wis", "Chr"]: | |
attrs[attribute] = sumDice(dice) | |
return attrs | |
print(rollAttributes(dice)) | |
class Character: | |
def __init__(self, attrs): | |
self.attributes = attrs | |
# and so on... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment