Skip to content

Instantly share code, notes, and snippets.

@fogus
Last active February 10, 2022 18:13
Show Gist options
  • Save fogus/a2ce8333eb6ec8c6ad77ffbbfd438248 to your computer and use it in GitHub Desktop.
Save fogus/a2ce8333eb6ec8c6ad77ffbbfd438248 to your computer and use it in GitHub Desktop.
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