This is the character sheet of the special system that I have made for my final CS230 project
import random
from BagOfDice import DiceBag
# Lists of strings containing the names of each SPECIAL, skill, and attribute
specials_list = ["strength", "perception", "endurance", "charisma", "intelligence", "agility", "luck"]
skills_list = ["barter", "energyweapons", "explosives", "guns", "lockpick", "medicine", "meleeweapons", "repair", "science", "sneak", "speech", "survival", "unarmed"]
attributes_list = ["hitpoints", "actionpoints", "skillpoints", "carryweight", "damagethreshold", "radiationresistance", "movespeed", "compassrange", "criticalchance"]
# Dictionary that contains each skill as keys and the SPECIAL that determines their initial value
skill_special_relationship = {
"barter": "charisma",
"energyweapons": "perception",
"explosives": "endurance",
"guns": "agility",
"lockpick": "perception",
"medicine": "intelligence",
"meleeweapons": "strength",
"repair": "intelligence",
"science": "intelligence",
"sneak": "agility",
"speech": "charisma",
"survival": "endurance",
"unarmed": "strength"
}
class CharacterSheet:
def __init__(self, dice):
self.dice = dice
self.name = "Jean Doe"
self.specials = {}
self.skills = {}
self.attributes = {}
self.setSpecials()
def setSpecials(self):
for special in specials_list:
self.specials[special] = 0
remaining_points = 40
for special in self.specials:
roll = random.randint(1, 10)
if remaining_points - roll >= 0:
self.specials[special] = roll
remaining_points -= roll
else:
self.specials[special] = remaining_points
remaining_points = 0
self.setSkills()
self.setAttributes()
def setSkills(self):
for skill in skills_list:
self.skills[skill] = 0
for skill, special in skill_special_relationship.items():
self.skills[skill] = 5 + (self.specials[special] * 2) + (self.specials["luck"] // 2)
def setAttributes(self):
for attribute in attributes_list:
self.attributes[attribute] = 0
self.attributes["hitpoints"] = 50
for _ in range(self.specials["endurance"]):
self.attributes["hitpoints"] += self.dice.roll(1, 50)
for _ in range(self.specials["luck"]):
self.attributes["hitpoints"] += self.dice.roll(1, 10)
self.attributes["actionpoints"] = 35
for _ in range(self.specials["agility"]):
self.attributes["actionpoints"] += self.dice.roll(1, 10)
self.attributes["skillpoints"] = 10 + self.specials["intelligence"]
self.attributes["carryweight"] = 150
for _ in range(self.specials["strength"]):
self.attributes["carryweight"] += self.dice.roll(1, 20)
self.attributes["damagethreshold"] = self.specials["endurance"] // 2
self.attributes["radiationresistance"] = 0
for _ in range(self.specials["endurance"]):
self.attributes["radiationresistance"] += self.dice.roll(1, 4)
self.attributes["movespeed"] = 75 + (self.specials["agility"] * 5)
self.attributes["compassrange"] = 50 + (self.specials["perception"] * 10)
self.attributes["criticalchance"] = self.specials["luck"]
def setName(self, newName):
self.name = newName
def setAV(self, key, value):
if key in self.specials:
self.specials[key] = value
self.setSkills()
self.setAttributes()
elif key in self.skills:
self.skills[key] = value
elif key in self.attributes:
self.attributes[key] = value
def forceAV(self, key, value):
if key in self.specials:
self.specials[key] = value
elif key in self.skills:
self.skills[key] = value
elif key in self.attributes:
self.attributes[key] = value
def modAV(self, key, value):
if key in self.specials:
self.specials[key] += value
self.setSkills()
self.setAttributes()
elif key in self.skills:
self.skills[key] += value
elif key in self.attributes:
self.attributes[key] += value
def getAV(self, key):
if key in self.specials:
return self.specials[key]
elif key in self.skills:
return self.skills[key]
elif key in self.attributes:
return self.attributes[key]
else:
return None
def __str__(self):
output = f"Name: {self.name}nn"
output += "SPECIALs:n"
for special, value in self.specials.items():
output += f"{special.capitalize()}: {value}n"
output += "nSkills:n"
for skill, value in self.skills.items():
output += f"{skill.capitalize()}: {value}n"
output += "nAttributes:n"
for attribute, value in self.attributes.items():
output += f"{attribute.capitalize()}: {value}n"
return output
This is the dice bag it using
import random
class Die:
def __init__(self, sides):
self.sides = sides
self.value = 1
def roll(self):
self.value = random.randrange(1,self.sides+1)
return self.value
class DiceBag:
def __init__(self, dice):
self.dice = dice
def singleRoll(self, selectedDie):
for die in self.dice:
if die.sides == selectedDie:
return die.roll()
return -1
def multiRoll(self, selectedDie, numberOfRolls):
for die in self.dice:
if die.sides == selectedDie:
total = 0
for i in range(0,numberOfRolls):
total += die.roll()
return total
return -1
This is the main file that will print the results
from BagOfDice import Die, DiceBag
from CharacterSheetEditor import CharacterSheet
dice_bag = DiceBag()
dice_bag.add_die(Die(4))
dice_bag.add_die(Die(6))
dice_bag.add_die(Die(10))
dice_bag.add_die(Die(20))
dice_bag.add_die(Die(50))
character_sheet = CharacterSheet(dice_bag)
#Call setName, setAV, forceAV, modAV, and getAV to show that they work
character_sheet.setName("John Doe")
character_sheet.setAV("strength", 8)
character_sheet.forceAV("barter", 50)
character_sheet.modAV("intelligence", 2)
# Get and print attribute values
print(character_sheet.getAV("strength")) # Expected: 8
print(character_sheet.getAV("barter")) # Expected: 50
print(character_sheet.getAV("intelligence")) # Expected: (Original value + 2)
# Print the character sheet
print(character_sheet)
I keep getting a trace back error. What is going wrong with it?
I’ve tried to get the outputs to come where it shows up like you’ve made a character and what they are good at in each stat but it just comes back with a trace back error.
Traceback (most recent call last):
File "c:Users****DownloadsCharacterSheetEditormain.py", line 21, in <module>
dice_bag = DiceBag()
^^^^^^^^^
TypeError: DiceBag.__init__() missing 1 required positional argument: 'dice'
New contributor
Skinwalker05711 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
1