logo
Search검색어를 포함하는 게시물들이 최신순으로 표시됩니다.
    Table of Contents
    [Python] 멤버 변수의 사용

    이미지 보기

    [Python] 멤버 변수의 사용

    • 21.07.18 작성

    • 읽는 데 2

    TOC

    멤버 변수의 사용

    1. 새 유닛의 생성 : Wraith

    • 레이스 : 공중 유닛, 비행기, 클로킹 (상대방에게 보이지 않는다.)
    class Unit:
            def __init__(self, name, hp, damage):
                self.name = name
                self.hp = hp
                self.damage = damage
                print("{0} 유닛이 생성되었습니다.".format(self.name))
                print("체력 {0}, 공격력 {1}".format(self.hp, self.damage))
    
    wraith1 = Unit("레이스", 80, 5)
    print("유닛 이름 : {0}, 공격력 : {1}".format(wraith1.name, wraith1.damage))
    

    출력값은 다음과 같다.

    유닛 이름 : 레이스, 공격력 : 5
    

    2. 다크아칸의 mind control

    • 상대방 unit을 내 것으로 만드는 것
    wraith2 = Unit("빼앗은 레이스", 80, 5)
    
    # wraith2에는 clocking이라는 기능이 생겼다고 가정
    # wraith2에 .clocking이라는 변수를 추가로 할당하는 것
    wraith2.clocking = True
    
    if wraith2.clocking == True:
        print("{0}는 현재 클로킹 상태입니다.".format(wraith2.name))
    

    Reference

    profile

    FE Developer 박승훈

    노력하는 자는 즐기는 자를 이길 수 없다