top of page

소스 코드 제출

공개·회원 52명

20250819



def game_start():
    print("[알림] 새로운 게임을 시작 합니다.")

def game_over():
    pass

game_start()

game_over()

class Unit:
    def __init__(self, name, hp, speed) :
        self.name =name
        self.hp = hp
        self.speed = speed     # 지상 이동 속도

    def move(self, location):  # 이동 동작 정의
        print("[지상 유닛 이동]")
        print("{0} : {1} 방향으로 이동합니다. [속도 {2}]" \
              .format(self.name, location, self.speed))
class AttackUnit(Unit):
    def __init__(self, name, hp, damage, speed):
        super().__init__(name,hp, speed)        # 자식이 부모의 메소드 호출할때는 self 안씀!!!
        self.damage = damage
    def attack(self, location) :
        print("{0} : {1} 방향 적군을 공격합니다.[공격력 {2}]" .format(self.name, location, self.damage))
    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 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(Flyable, AttackUnit) :      #다중상속
    def __init__(self, name, hp, damage, flying_speed)  :
        AttackUnit.__init__(self, name, hp, damage, 0)
        Flyable.__init__(self, flying_speed)

    #메소드 오버라이딩(덮어쓰기, 재정의)
    def move(self,location):
        print("[공중 유닛 이동]")
        Flyable.fly(self,self.name, location)


class BuildingUnit(Unit):
    def __init__(self, name, hp, location) :
        super().__init__(name, hp, 0)
        self.location = location

suppply_deport = BuildingUnit("보급고", 500, "7시")

interceptor =FlyableAttackUnit("요격기", 200, 6, 5)
interceptor.fly(interceptor.name, "3시")

hoverbike = AttackUnit("호버 바이크", 80, 20, 10) # 지상 이동 속도 10
spacecruiser = FlyableAttackUnit("우주 순양함", 500, 25, 3) # 비행 속도 3

hoverbike.move("11시")
spacecruiser.move("9시")

def game_start():
    print("[알림] 새로운 게임을 시작 합니다.")

def game_over():
    pass

game_start()

game_over()



파이썬 프로젝트 리스트
https://www.freecodecamp.org/korean/news/python-projects-for-beginners/#example16



4회 조회
주소 : 경기도 용인시 광교중앙로 302 블루 스퀘어 602호
연락처 : 031) 216 - 1546 ,     031) 215 - 1546
사업자등록번호 : 465-92-00916
​학원 등록 제 4603호
bottom of page