-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPass.py
More file actions
85 lines (71 loc) · 5.68 KB
/
Copy pathPass.py
File metadata and controls
85 lines (71 loc) · 5.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#일반 유닛(오버로딩) 지상 유닛에 스피드 생성
class Unit:
def __init__(self, name, hp, speed): # def하고 바로 __하는게 아니라 한칸 띄우고 함. init은 다음장에서 설명함.
self.name = name # 맴버변수 : 클래스 내에서 정의된 변수. self.으로 되는 "name, hp, damage"이 맴버 변수다.
self.hp = hp
self.speed = speed
def move(self, location):
print("[지상 유닛 이동]")
print("{0} : {1} 방향으로 이동합니다. [속도는 {2}]".format(self.name, location, self.speed)) # 여기서 speed를 새로 추가했디에
# AttackUnit 클래스에도 speed를 정의해야한다.
# 그리고 맨 아래 다중 상속 클래스에서도 공중 유닛은 speed(지상 스피드)가 필요없으니 0으로 만든다.
# 공격 유닛(클래스) - 상속받아짐(Unit)
class AttackUnit(Unit):
def __init__(self, name, hp, speed, damage): # def하고 바로 __하는게 아니라 한칸 띄우고 함. init은 다음장에서 설명함.
Unit.__init__(self, name, hp, speed) # 위에 Unit 클래스에서 상속 받음
self.damage = damage # AttackUnit에서 직접 전달받음.
print("{0} 유닛이 생성 되었습니다.".format(self.name))
print("체력 : {0}, 공격력 : {1}".format(self.hp, self.damage))
# (location 메소드)
def attack(self, location): # 클래스를 사용할때는 self을 항상 사용해줘야한다.
print("{0} : {1} 방향으로 적군을 공격 합니다. [공격력 {2}]".format(self.name, location, self.damage))
# 위에 self.name, self.damage는 상단 def __init__에서 정의된 것들을 사용하는 것이고 location 값은 def attack(self, location)인,
# location에게 받는다는 뜻이다.
# (damaged 메소드)
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))
# ------------------------------------------------------------------------------------------------------------------------------------
# ------------------------------------------------------------------------------------------------------------------------------------
# ------------------------------------------------------------------------------------------------------------------------------------
# ------------------------------------------------------------------------------------------------------------------------------------
# ------------------------------------------------------------------------------------------------------------------------------------
# ------------------------------------------------------------------------------------------------------------------------------------
# ------------------------------------------------------------------------------------------------------------------------------------
# ------------------------------------------------------------------------------------------------------------------------------------
# ------------------------------------------------------------------------------------------------------------------------------------
# 다중 상속
# 드랍쉽 : 공중 유닛, 수송기. 마린 / 파이어뱃 / 탱크 등을 수송. 공격X
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 FlyableAttacUnit(AttackUnit, Flyable): # AttackUnit, Flyable 두개를 상속 받는다.
def __init__(self, name, hp, damage, flying_speed): # Attack클래스에 정의된 name, hp, damage와
# 새로 Flyable 클래스에서 정의된 flying_speed를 상속받기 위해 초기화를 진행한다.
AttackUnit.__init__(self, name, hp, 0, damage) # Attack클래스에 정의된 name, hp, damage를 상속한다.
Flyable.__init__(self, flying_speed) # Flyable 클래스에서 정의된 flying_speed를 상속한다.
def move(self, location):
print("[공중 유닛 이동]")
self.fly(self.name, location)
# ------------------------------------------------------------------------------------------------------------------------------------
# ------------------------------------------------------------------------------------------------------------------------------------
# ------------------------------------------------------------------------------------------------------------------------------------
# 건물(Pass)
class BuildingUnit(Unit):
def __init__(self, name, hp, location):
pass # 원래는 Class에 상속을 받기위해 초기화를 선언해야하지만(클래스를 적고 __init__(여기에 값을 넣고 초기화했어햐한다.)
# 사실 pass가 없고 이렇게 냅두면 선언해준것이 없으므로, 에러가 발생하지만 pass를 사용함으로서 이대로 진행시킨것이다.
# 서플라이 디폿 : 건물, 1개 건물 = 8 유닛 차지함.
supply_depot = BuildingUnit("서플라이", 500, "7시")
def game_start():
print("[알림] 새로운 게임을 시작합니다.")
def game_over():
pass
game_start()
game_over()