생성자가 제대로 작동하지 않습니다.
566
작성자 없음
작성한 질문수 0
0
marine 생성자가 작동을 안합니다...
생성자를 전부 맞게 적은 것 같은데 다음과 같은 오류가 발생해요.
line 113, in <module>
m1 = Marine()
TypeError: __init__() missing 4 required positional arguments: 'name', 'hp', 'speed', and 'damage'
from random import *
# 일반 유닛
class Unit:
def __init__(self, name, hp, speed):
self.name = name
self.hp = hp
self.speed = speed
print("{0} 유닛이 생성되었습니다.".format(name))
def move(self, location):
print("[지상 유닛 이동]")
print("{0} : {1} 방향으로 이동합니다. [속{2}]".format(self.name, location, self.speed))
def damaged(self, damage):
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))
# 공격 유닛
class AttackUnit(Unit):
def __init__(self, name, hp, speed, damage):
Unit.__init__(self, name, hp, speed)
self.damage = damage
def attack(self, location):
print("{0} : {1} 방향으로 적군을 공격합니다. [공격력 {2}] " \
.format(self.name, location, self.damage))
class Marine(AttackUnit):
def __int__(self):
AttackUnit.__init__(self, "마린", 40, 1, 5)
def stimpack(self):
if self.hp > 10:
self.hp -= 10
print("{0} : 스팀팩을 사용합니다. (hp 10 감소)".format(self.name))
else:
print("{0} : 체력이 부족하여 스팀팩을 사용하지 않습니다.".format(self.name))
class Tank(AttackUnit):
seize_developed = False
def __int__(self):
AttackUnit.__init__(self, "탱크", 150, 1, 35)
self.seize_mode = False
def set_seize_mode(self):
if not Tank.seize_developed:
return
# 현재 시즈모드가 아닐 때 -> 시즈 모드
if not self.seize_mode:
print("{0} : 시즈모드로 전환합니다.".format(self.name))
self.damage *= 2
self.seize_mode = True
else:
print("{0} : 시즈모드를 해제합니다.".format(self.name))
self.damage /= 2
self.seize_mode = False
class Flyable:
def __init__(self, flying_speed):
self.flying_speed = flying_speed
def fly(self, name, location):
print("{0} : {1} 방향으로 날아갑니다. [속도 {2}]".format(name, location, self.flying_speed))
class FlyableAttackUnit(AttackUnit, Flyable):
def __init__(self, name, hp, damage, flying_speed):
AttackUnit.__init__(self, name, hp, 0, damage)
Flyable.__init__(self, flying_speed)
def move(self, location):
print("[공중 유닛 이동]")
self.fly(self.name, location)
class Wraith(FlyableAttackUnit):
def __init__(self):
FlyableAttackUnit.__init__(self, "레이스", 80, 20, 5)
self.clocked = False
def clocking(self):
if self.clocked == True:
print("{0} : 클로킹 모드 해제합니다.".format(self.name))
self.clocked = False
else:
print("{0} : 클로킹 모드 설정합니다.".format(self.name))
self.clocked = True
def game_start():
print("[알림] 새로운 게임을 시작합니다.")
def game_over():
print("Player : gg")
print("[Player] 님이 게임에서 퇴장하였습니다.")
# 게임 진행
game_start()
m1 = Marine()
m2 = Marine()
m3 = Marine()
t1 = Tank()
t2 = Tank()
w1 = Wraith()
attack_units = []
attack_units.append(m1)
attack_units.append(m2)
attack_units.append(m3)
attack_units.append(t1)
attack_units.append(t2)
attack_units.append(w1)
for unit in attack_units:
unit.move("1시")
Tank.seize_developed = True
print("[알림] 탱크 시즈 모드 개발이 완료되었습니다.")
for unit in attack_units:
if isinstance(unit, Marine):
unit.stimpack()
elif isinstance(unit, Tank):
unit.set_seize_mode()
elif isinstance(unit, Wraith):
unit.clocking()
for unit in attack_units:
unit.attack("1시")
for unit in attack_units:
unit.damaged(randint(5, 20)) # 공격은 랜덤으로 받음
# 게임 종료
game_over()
답변 1
quiz 8 오류 문제
0
76
1
str() 작성 위치
0
59
1
아나콘다
0
65
1
윈도우 설치 도와주세요
0
76
1
std_weight함수에서weight만return가능한가요?
0
70
1
오른쪽위 실행버튼을 누르면 터미널에 에러가 뜨고 컨트롤+F5를 누르면 에러가 안뜹니다.
0
38
1
설치해서 시작하는데 문제가 있습니다.
0
70
1
함수 입력할 때 설명 툴팁 나오게 하려면 어떻게 하나요?
0
113
1
2장 환경설정 문의
0
79
1
스타크래프트 프로젝트
0
79
1
python 파일명.py 입력시 Python 출력
0
138
1
로드맵 질문있습니다!
0
92
2
오류
0
76
1
질문 있습니다.
0
79
1
블로그에 학습한 내용을 정리해도 괜찮을까요?
0
175
1
#퀴즈 3의 5번 질문
0
72
1
print("ㅋ"*5) 에 대한 결과가 도출되지 않습니다
0
83
1
가변인자의 위치가 중요한가요?
0
81
1
vscode옛날 버전 설치
0
227
1
글자색상이 선생님처럼 안나옵니다
0
190
1
슬프네
0
156
1
quiz 6번 관련 문의입니다.
0
132
1
퀴즈#3에 대해서 이렇게 작성해도 되나요?
0
197
1
피드백 부탁드립니다
0
93
1





