• 카테고리

    질문 & 답변
  • 세부 분야

    프로그래밍 언어

  • 해결 여부

    미해결

시즈모드 작동이 안 됩니다 ㅠㅠ

20.12.01 15:25 작성 조회수 197

0

지상 유닛과 공중 유닛 생성하고, 전투 돌입해서 마린의 스팀팩 까지는 잘 동작됐는데 그 이후에 탱크의

시즈모드가 동작이 안 됩니다. 한 번 봐주시면 감사하겠습니다^^

from random import *

class Unit:
    def __init__(selfnamehpspeeddamage):
        self.name = name
        self.hp = hp
        self.damage = damage
        self.speed = speed
        print("\n{0} has been made".format(self.name))
        print("It's hp is {0}, and damage is {1}".format(self.hp, self.damage))

    def move(selflocation):
        # print("[ground unit moving on]")
        print("\n{0} : moving on to the {1} speed [{2}]"
              .format(self.name, location, self.speed))

    def damaged(selfdamage):
        print("\n{0} : {1} damaged! I'm hitted!".format(self.name, damage))
        self.hp -= damage
        print("\n{0} : now I've got {1} hp left!".format(self.name, self.hp))
        if self.hp <= 0:
            print("\n{0} : It's been destroyed".format(self.name))


class AttackUnit(Unit):
    def __init__(selfnamehpspeeddamage):  # self : 자기 자신을 의미. 클래스에서는 거의 항상 사용
        Unit.__init__(self, name, hp, speed, damage)
        self.damage = damage

    def attack(selflocation):
        print("\n{0} : {1} at the enemy! attack now! damage [{2}]"
              .format(self.name, location, self.damage))


class Flyable:
    def __init__(selfspeed):
        self.speed = speed

    def fly(selfnamelocation):
        print("\n{0} : fly to the {1}! speed [{2}]"
              .format(name, location, self.speed))


## 다중상속
class FlyableAttackUnit(AttackUnitFlyable):
    def __init__(selfnamehpspeeddamage):
        AttackUnit.__init__(self, name, hp, 0, damage)  # 지상 speed,0
        Flyable.__init__(self, speed)

    def move(selflocation):  # 메소드 오버라이딩: 자식 클래스의 함수를 호출 혹은 재정의함
        # print("[AirAttacker moving on]")
        self.fly(self.name, location)

class Marine(AttackUnit):
    def __init__(self):
        AttackUnit.__init__(self"Marine"4015)

    def steampack(self):
        if self.hp > 10 :
            self.hp -= 10
            print("\n{0} : steampack on. [decrease 10 hp / left {1} hp]"
                  .format(self.name, self.hp))
        
        else:
            print("\n{0} : Not enough to use steampack")


class Tank(AttackUnit):
    seize_developed = False
    def __init__(self):
        AttackUnit.__init__(self"Tank"150135)
        self.seizemode = False
    
    def seizemode(self):
        if Tank.seize_developed == False:
            return

        # 시즈모드가 아닐 때 -> 시즈모드
        if self.seizemode == False:
            print("\n{0} : Seize on.".format(self.name))
            self.damage *= 2
            self.seizemode = True

        # 시즈모드일 때 -> 시즈모드 해제
        else:
            print("\n{0} : Seize off.".format(self.name))
            self.damage /= 2
            self.seizemode = False


class Wraith(FlyableAttackUnit):
    def __init__(self):
        FlyableAttackUnit.__init__(self"Wraith"80205)
        self.clocking = False # 클로킹 모드(해제 상태)

    def cloking(self):
        # 클로킹 모드 해제
        if self.clocking == True:
            print("\n{0} : Clocking off".format(self.name))
            self.clocking = False
        # 클로킹 모드 작동
        else:
            print("\n{0} : Clocking on.".format(self.name))


def game_start():
    print("\n[log] The new game has veen started!")


def game_over():
    print("Player : It was good game")
    print("[log] Player gonna out of here")


## 게임시작
game_start()

# 마린 3기 생성
m1 = Marine()
m2 = Marine()
m3 = Marine()

# 탱크 2기 생성
t1 = Tank()
t2 = Tank()

# 레이스 1기 생성
w1 = Wraith()

# 유닛 일괄 관리 ( 생성된 모든 유닛 append )
a_unit = []
a_unit.append(m1)
a_unit.append(m2)
a_unit.append(m3)
a_unit.append(t1)
a_unit.append(t2)
a_unit.append(w1)

# 전군 이동
for unit in a_unit:
    unit.move("1'o")

# 탱크 시즈모드 개발
Tank.seize_developed = True
print("\nSeize mode developed complete!")

# 공격 준비(마린 : 스팀팩, 탱크 : 시즈모드, 레이스 : 클로킹 )
for unit in a_unit:
    if isinstance(unit, Marine):
        unit.steampack()
    elif isinstance(unit, Tank):
        unit.seizemode()
    elif isinstance(unit, Wraith):
        unit.clocking()

# 전군 공격
for unit in a_unit:
    unit.attack("1'o")

# 전군 피해
for unit in a_unit:
    unit.damaged(randint(521))  # 공격은 랜덤으로 받음(5,20)

# 게임 종료
game_over()

답변 1

답변을 작성해보세요.

0

답변이 늦어 대단히 죄송합니다.

탱크의 시즈모드 설정하는 함수명과 시즈 모드를 표시하는 bool 멤버변수의 이름이 같아서 발생한 에러입니다.

def seizemode(self): 를 def setseizemode(self): 로 바꿔주시구요.

그리고 레이스의 클로킹 함수에도 오타가 있네요

def cloking(self): 를 def setclocking(self): 으로 바꿔주세요

마지막으로 for 문을 아래와 같이 변경해주시면 됩니다.

for unit in a_unit:

    if isinstance(unit, Marine):

        unit.steampack()

    elif isinstance(unit, Tank):

        unit.setseizemode() # 수정한 부분

    elif isinstance(unit, Wraith):

        unit.setclocking() # 수정한 부분