728x90
반응형

메소드 3

[ Python ] pass

# pass # 일반 유닛 class Unit: def __init__(self, name, hp, speed): self.name = name self.hp = hp self.speed = speed def move(self, location): print("[지상 유닛 이동]") print("{0} : {1} 방향으로 이동합니다. [속도 {2}]".format(self.name, location, self.speed)) # 공격 유닛 class AttackUnit(Unit): def __init__(self, name, hp, damage, speed=0): Unit.__init__(self, name, hp, speed) # 부모에게 값을 넘겨주어 초기화하는 작업. self.damage = dama..

Python 2021.03.07

[ Python ] 메소드 오버라이딩

# 메소드 오버라이딩 # 일반 유닛 class Unit: def __init__(self, name, hp, speed): self.name = name self.hp = hp self.speed = speed def move(self, location): print("[지상 유닛 이동]") print("{0} : {1} 방향으로 이동합니다. [속도 {2}]".format(self.name, location, self.speed)) # 상속받을 때 '클래스명(상속받을 클래스명)' # 공격 유닛 class AttackUnit(Unit): def __init__(self, name, hp, damage, speed=0): Unit.__init__(self, name, hp, speed) # 부..

Python 2021.03.07

[ Python ] 메소드

# 메소드 class Unit: def __init__(self, name, hp, damage): self.name = name self.hp = hp self.damage = damage print("{0} 유닛이 생성 되었습니다.".format(self.name)) print("체력 {0}, 공격력 {1}".format(self.hp, self.damage)) # 공격 유닛 class AttackUnit: def __init__(self, name, hp, damage): self.name = name self.hp = hp self.damage = damage def attack(self, location): print("{0} : {1} 방향으로 적군을 공격 합니다. [공격력 : {2}]".fo..

Python 2021.03.07
728x90
반응형
LIST