[파이썬] 기초 공부, 스타크래프트 알고리즘


 클래스를 활용한 스타크래프트 알고리즘

개발이라는 것을 하는 거 자체가 너무 어려운거 같다. 개발자들은 돈을 많이 벌어야 한다. 

아주 많이



from random import *

#일반 유닛
class Unit:
    def __init__(selfnamehpspeed):
        self.name = name  
        self.hp = hp
        self.speed = speed
        print("{0} 유닛이 생성되었습니다." .format(name))

    def move(selflocation):
        print("{0} : {1} 방향으로 이동합니다. [속도 : {2}]" .format(self.namelocationself.speed))

    def damaged(selfdamage):
        print("{0} : {1} 데미지를 입었습니다." .format(self.namedamage))
        self.hp -= damage
        print("{0} : 현재 체력은 {1} 입니다." .format(self.nameself.hp))
        if self.hp <=0:
            print("{0} : 파괴되었습니다." .format(self.name))
    


#공격 유닛
class AttackUnit(Unit):  #Unit 클래스 변수 내용 상속
    def __init__(selfnamehpspeeddamage):
        Unit.__init__(selfnamehpspeed)
        self.damage = damage

    def attack(selflocation):
        print("{0} : {1} 방향으로 적군을 공격합니다. [공격력 : {2}]" .format(self.namelocationself.damage))
    
#마린 유닛
class Marine(AttackUnit):
    def __init__(self):
        AttackUnit.__init__(self"마린"4015)

    #스팀팩 
    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 __init__(self):
        AttackUnit.__init__(self"탱크"150135)
        self.seize_mode = False


    def set_seize_mode(self):
        if Tank.seize_developed == False:
            return

        if self.seize_mode == False :
            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
 
# #파이어뱃, 공격유닛, 화염방사기
# firebat1 = AttackUnit("파이어벳", 50, 16)
# firebat1.attack("5시")

# #공격을 2번 받음
# firebat1.damaged(25)
# firebat1.damaged(25)

#드랍쉽 : 공중 유닛, 수송기, 유닛 등을 수송, 공격력 없음 

#비행가능 유닛
class Flyable:
    def __init__(selfflying_speed):
        self.flying_speed = flying_speed

    def fly(selfnamelocation):
        print("{0} : {1} 방향으로 날아갑니다. [속도 {2}]" .format(namelocationself.flying_speed))

#공중 공격 유닛
class FlyableAttackUnit(AttackUnit,Flyable):
    def __init__(selfnamehpdamageflying_speed):
        AttackUnit.__init__(selfnamehp0damage#지상스피드는 0으로 처리한다. 
        Flyable.__init__(selfflying_speed)


    def move(selflocation):
        self.fly(self.namelocation)


#레이스
class Wraith(FlyableAttackUnit):
    def __init__(self):
        FlyableAttackUnit.__init__(self"레이스"80205)
        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(unitMarine):
        unit.stimpack()
    elif isinstance(unitTank):
        unit.set_seize_mode()
    elif isinstance(unitWraith):
        unit.clocking()

for unit in attack_units:
    unit.attack("1시")

for unit in attack_units:
    unit.damaged(randint(5,21)) #공격 랜덤

#게임종료
game_over()






댓글 쓰기

0 댓글