我正在尝试将我的旧游戏引擎转换成一个使用类而不仅仅是字典的新版本
我的目标是从两个不同的类中添加相似的键值,以便修改玩家的统计信息
class player:
def __init__(self, name, level, xp, nextlvlxp, stats, inventory):
self.name = ''
self.level = 1
self.xp = 0
self.nextlvlxp = 25
self.stats = {
'str': [],
'dex': [],
'con': [],
'int': [],
'wis': [],
'cha': [],
'modstr': [],
'moddex': [],
'modcon': [],
'modint': [],
'modwis': [],
'modcha': []
}
self.combat_stats = {
'totalhp': [],
'currenthp':[],
'totalmp': [],
'currentmp': [],
'baseatk': [],
'attack': [],
'speed': [],
'perception':[]
}
self.noncombat_stats = {
'evasion': [],
}
self.inventory = {}
class Item():
def __init__(self, name, description, stats, value):
self.name = name
self.description = description
self.stats = {}
self.value = value
class Weapon(Item):
def __init__(self, name, description, stats, value):
self.stats = stats
super().__init__(name, description, value)
def __str__(self):
return "{}\n=====\n{}\nValue: {}\nStats: {}".format(self.name, self.description, self.value, self.stats)
class Sword(Weapon):
def __init__(self):
super().__init__(name="Sword",
description="A common shortsword",
stats = {
'str': 2,
'dex': 1
},
value = 10)
电子xample:items ‘剑’’str’+玩家‘str’=玩家‘modstr’
我想把这些加在一起,还有下一个dex的值,我想用一种非竞争性的方式。我真的不知道从哪里开始,我只是刚刚学会如何写今天的课。有没有什么方法可以通过字典将具有相同键的值添加到一起
这基本上就是您要做的,但是我不确定您的情况,因为您的默认属性是空列表
例如:
相关问题 更多 >
编程相关推荐