Это список персонажей специальной системы, которую я создал для своего последнего проекта CS230
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}\n\n"
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
Это мешочек для игральных костей, который он использует. Мне не разрешено редактировать сам мешочек для кубиков для этого проекта. Мне его дал мой инструктор.
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
Это основной файл, в который будут распечатаны результаты.
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)
Я постоянно получаю сообщение об ошибке обратной трассировки. Что с этим не так?
Я пытался добиться того, чтобы результаты отображались так, как будто вы создали персонажа и в чем он хорош по каждой характеристике, но это просто возвращается с ошибкой обратной трассировки.
Traceback (most recent call last):
File "c:\Users\****\Downloads\CharacterSheetEditor\main.py", line 21, in
dice_bag = DiceBag()
^^^^^^^^^
TypeError: DiceBag.__init__() missing 1 required positional argument: 'dice'
Подробнее здесь: https://stackoverflow.com/questions/792 ... ial-system
Мне нужно построить специальную систему Fallout [закрыто] ⇐ Python
Программы на Python
-
Anonymous
1733611039
Anonymous
Это список персонажей специальной системы, которую я создал для своего последнего проекта CS230
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}\n\n"
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
Это мешочек для игральных костей, который он использует. Мне не разрешено редактировать сам мешочек для кубиков для этого проекта. Мне его дал мой инструктор.
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
Это основной файл, в который будут распечатаны результаты.
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)
Я постоянно получаю сообщение об ошибке обратной трассировки. Что с этим не так?
Я пытался добиться того, чтобы результаты отображались так, как будто вы создали персонажа и в чем он хорош по каждой характеристике, но это просто возвращается с ошибкой обратной трассировки.
Traceback (most recent call last):
File "c:\Users\****\Downloads\CharacterSheetEditor\main.py", line 21, in
dice_bag = DiceBag()
^^^^^^^^^
TypeError: DiceBag.__init__() missing 1 required positional argument: 'dice'
Подробнее здесь: [url]https://stackoverflow.com/questions/79261305/i-have-to-build-the-fallout-special-system[/url]
Ответить
1 сообщение
• Страница 1 из 1
Перейти
- Кемерово-IT
- ↳ Javascript
- ↳ C#
- ↳ JAVA
- ↳ Elasticsearch aggregation
- ↳ Python
- ↳ Php
- ↳ Android
- ↳ Html
- ↳ Jquery
- ↳ C++
- ↳ IOS
- ↳ CSS
- ↳ Excel
- ↳ Linux
- ↳ Apache
- ↳ MySql
- Детский мир
- Для души
- ↳ Музыкальные инструменты даром
- ↳ Печатная продукция даром
- Внешняя красота и здоровье
- ↳ Одежда и обувь для взрослых даром
- ↳ Товары для здоровья
- ↳ Физкультура и спорт
- Техника - даром!
- ↳ Автомобилистам
- ↳ Компьютерная техника
- ↳ Плиты: газовые и электрические
- ↳ Холодильники
- ↳ Стиральные машины
- ↳ Телевизоры
- ↳ Телефоны, смартфоны, плашеты
- ↳ Швейные машинки
- ↳ Прочая электроника и техника
- ↳ Фототехника
- Ремонт и интерьер
- ↳ Стройматериалы, инструмент
- ↳ Мебель и предметы интерьера даром
- ↳ Cантехника
- Другие темы
- ↳ Разное даром
- ↳ Давай меняться!
- ↳ Отдам\возьму за копеечку
- ↳ Работа и подработка в Кемерове
- ↳ Давай с тобой поговорим...
Мобильная версия