• 카테고리

    질문 & 답변
  • 세부 분야

    프로그래밍 언어

  • 해결 여부

    미해결

생성자가 제대로 작동하지 않습니다.

20.07.28 18:33 작성 조회수 408

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

답변을 작성해보세요.

1

Marine 과 Tank 클래스의 생성자가

__int__ 로 잘못되어 있었네요

__init__ 으로 바꿔주세요 ^^