에 영향을 받고, 항상 그것이 기본 값의에 나는 생물의 마력을 재설정 할 수 없습니다 의미하기 때문에 문제가되는, 한 번에 모두 값을 설정합니다. 다음은이여러 속성 한 번
class Stats:
def __init__ (self,hp,height,strength,speed,skill,agility,perception):
x = random.randint(-2,2)
self.hp = hp+x
x = random.randint(-10,10)
self.height = height+x
x = random.randint(-2,2)
self.strength = strength+x
x = random.randint(-2,2)
self.speed = speed+x
x = random.randint(-1,1)
self.skill = skill+x
x = random.randint(-2,2)
self.agility = agility+x
x = random.randint(-2,2)
self.perception = perception+x
class Creature:
def __init__ (self,name,stats,top_image,side_image):
self.name = name
self.base_stats = stats
self.stats = stats
# More code here for rest of attributes
처리하는 코드의 일부는 Creature.stats
및 Creature.base_stats
이 같은 stats
변수를 참조하고 있기 때문에 아마 문제가있어?
(편집)
생물 클래스의 __init__
에서 참조 stats
은 __init__
기능에 Stats
객체
예, 그들은 동일한'stats' 변수를 참조하고 있습니다. 그 행동을 피하기 위해 사본에 할당하기 –
두 개의 동일한 'Stats' 객체를 만들 필요없이 통계를 복사하는 방법이 있습니까? 특히 통계를 준 임의화한 이후로는 문제를 일으키거나 정확히 내가 원하는 방식대로 작동하지 않을 수 있습니다. – Oliver