class
- 서로 연관이 있는 변수와 함수의 집합, 동일한 모양을 함수로 찍어냄.
init
- 생성자(constructor)
- 사용자가 따로 호출하지 않아도 클래스 객체를 생성할 때 자동으로 호출됨.
method
멤버변수
- self.변수명 = 값
- class 내에서 사용할 수 있는 변수
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))
marine1 = Unit("마린", 40, 5)
tank = Unit("탱크", 150, 35)
wraith1 = Unit("레이스", 80, 5)
print("유닛 이름 : {0}, 공격력 : {1}".format(wraith1.name, wraith1.damage))
wraith2 = Unit("빼앗은 레이스", 80, 5)
wraith2.clocking = True
if wraith2.clocking == True:
print("{0}는 현재 클로킹 상태입니다.".format(wraith2.name))