728x90
반응형

클래스 9

[ Python ] 스타크래프트 후반전

# 스타크래프트 전반전 # 텍스트 기반으로 실제 게임을 하는 것처럼 프로젝트 만들기. from random import randint # 일반 유닛 class Unit: def __init__(self, name, hp, speed=0): self.name = name self.hp = hp self.speed = speed print("{0} 유닛이 생성되었습니다.".format(self.name)) def move(self, location): print("{0} : {1} 방향으로 이동합니다. [속도 {2}]".format(self.name, location, self.speed)) def damaged(self, damage): print("{0} : {1} 데미지를 입었습니다.".format(s..

Python 2021.03.07

[ Python ] pass

# pass # 일반 유닛 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=0): Unit.__init__(self, name, hp, speed) # 부모에게 값을 넘겨주어 초기화하는 작업. self.damage = dama..

Python 2021.03.07

[ Python ] 메소드 오버라이딩

# 메소드 오버라이딩 # 일반 유닛 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=0): Unit.__init__(self, name, hp, speed) # 부..

Python 2021.03.07

[ Python ] 멤버 변수

클래스 외부에서 원하는 변수 확장 확장된 변수는 확장한 객체에 대해서만 적용되고 다른 객체에 대해서는 적용되지 않는다. # 클래스 만들기 # __init__ : Python에서 사용되는 생성자 # marine이나 tank 같은 객체가 만들어질 때 자동으로 호출되는 부분. # 객체 : 클래스에 의해 만들어진. # marine, tank는 Unit 클래스의 '인스턴스'라고 한다. # 멤버 변수 : 클래스 내에서 정의된 변수(self.name/self.hp/self.damage) # ------------ 클래스 생성 시작 -------------- class Unit: def __init__(self, name, hp, damage): self.name = name self.hp = hp se..

Python 2021.03.07

[ Python ] 클래스 생성자 선언

# 클래스 만들기 # __init__ : Python에서 사용되는 생성자 # marine이나 tank 같은 객체가 만들어질 때 자동으로 호출되는 부분. # 객체 : 클래스에 의해 만들어진. # marine, tank는 Unit 클래스의 '인스턴스'라고 한다. # ------------ 클래스 생성 시작 -------------- 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)) # ---..

Python 2021.03.07

[ Python ] 클래스 만들기

# 클래스 만들기 # ------------ 클래스 생성 시작 -------------- 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)) # ------------ 클래스 생성 끝 -------------- marine1 = Unit("마린", 40, 5) marine2 = Unit("마린", 40, 5) tank = Unit("탱크", 150, 35)

Python 2021.03.07

[ Python ] 클래스 시작하기.

# 클래스 # 스타크래프트 게임 예시 # 마린 : 공격 유닛, 군인. 총을 쏠 수 있음 name = "마린" # 유닛의 이름 hp = 40 # 유닛의 체력 damage = 5 # 유닛의 공격력 print("{0} 유닛이 생성되었습니다.".format(name)) print("체력 {0}, 공격력 {1}\n".format(hp, damage)) # 탱크 : 공격 유닛, 탱크. 포를 쏠 수 있는데, 일반 모드 / 시즈 모드 tank_name = "탱크" tank_hp = 150 tank_damage = 35 print("{0} 유닛이 생성되었습니다.".format(tank_name)) print("체력 {0}, 공격력 {1}\n".format(tank_hp, tank_damage)) tank2_name = ..

Python 2021.03.07

class, extends 설명

Class 자바스크립트에서는 함수처럼 활용된다. constructor 클래스 인스턴스를 생성하고 생성한 인스턴스를 초기화하는 역할을 한다. 클래스를 구성하기 위한 껍데기 // Class class Person { constructor(region_, gender_) { this.region = region_; this.gender = gender_; } greetings(val = 'an-nyeong') { console.log(val); } } let person = new Person('Korea', 'male'); console.log(person); person.greetings(); // extends 상속 class American extends Pe..

javascript 2021.01.16
728x90
반응형
LIST