-
카테고리
-
세부 분야
프로그래밍 언어
-
해결 여부
해결됨
제 코딩이 출력이 안되는 이유와 self.hp -= damage 부분이 궁금합니다.
21.01.08 18:40 작성 조회수 103
0
안녕하세요, 선생님.
질문이 있습니다!
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: #class 분류
def __init__(self, name, hp, damage): #변수
self.name=name
self.hp=hp
self.damage=damage
def attack(self, location): # 함수1, 새로운 변수
print("{0} : {1} 방향으로 적군을 공격합니다. [공격력 {2}]".format(self.name, location, self.damage)) #location
def damaged(self, damage): # 함수2
print("{0} : {1} 데미지를 입었습니다.".format(self.name, damage))
self.hp -= damage ##[?]
print("{0} : 현재 체력은 {1}입니다.".format(self.name, self.hp))
if self.hp <= 0:
print("{0} : 파괴되었습니다.".format(self.name))
firebat1=AttackUnit("파이어뱃, 50, 25")
firebat1.attack("5시") #(location)
firebat1.damaged(25) #(damage)
firebat1.damaged(25)
(1) 저렇게 코딩하면 출력이 안되는데 이유를 모르겠어요.
(2) self.hp -= damage로 하는 이유를 모르겠어요.
다른 변수 self.name=name이면
self.name= (name ~어쩌고 저쩌고)로 이해해서
self.hp= (hp-damage)가 돼야 할 것 같은데
왜 self.hp -= damage인지 모르겠습니다.
답변을 작성해보세요.
0
레몬 녹차 (탈퇴)
질문자2021.01.09
a=10
a=a+10 #1
a+=10 #2
##1, 2 둘 다 같은 더하기
a #출력하면 30
a=10
b=3
print(a>b)
print(a>=b) #>=
print(a<b)
print(a<=b)
print(a==b) #등호가 == 비교이고 등호가 = 대입
print(a!=b) #다르다
답변 1