κ·Έλ λ€,, κ³ λλ‘ λ°λΌμ³€λλ° μλ¬λλ λ―Έμ€ν 리,,
μ?
μΈμ κ° μ΄ν΄ν΄μ λλ±λλ± κ³ μΉ μ μλ λ μ€κΈΈ λ°λΌλ©°,,,,
μ€νλ λͺ¨λ₯΄κ² κ³ νμ΄μ¬λ λͺ¨λ₯΄κ² λ€~~~~~~~~~
from random import *
#μΌλ°μ
class Unit: #λΆλͺ¨ ν΄λμ€
def __init__(self, name, hp, speed):
self.name = name
self.hp = hp
self.speed = speed
print("{0} μ λμ΄ μμ±λμμ΅λλ€.".format(name))
def move(self, location):
print("[μ§μ μ λ μ΄λ]")
print("{0} : {1} λ°©ν₯μΌλ‘ μ΄λν©λλ€. [μλ {2}]"\
.format(self.name, location, self.speed))
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 AttackUnit(Unit): #μμ ν΄λμ€
def __init__(self, name, hp, speed, damage):
Unit.__init__(self, name, hp, speed)
self.damage = damage
def attack(self, location):
print("{0} : {1} λ°©ν₯μΌλ‘ μ κ΅°μ 곡격ν©λλ€. [곡격λ ₯ {2}]"\
.format(self.name, location, self.damage))
#λ§λ¦°
class Marine(AttackUnit):
def __init__(self):
AttackUnit.__init__(self, "λ§λ¦°", 40, 1, 5)
#μ€νν© : μΌμ μκ°λμ 곡격 μλμ μ¦κ°, 체λ ₯ 10 κ°μ
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, "ν±ν¬", 150, 1, 35)
set.seize_mode = False
def set_seize_mode(self):
#νμ¬ μμ¦λ³΄λκ° μλ λ --> μμ¦λͺ¨λ
if Tank.seize_developed == 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
#λ μ μλ κΈ°λ₯ κ°μ§ ν΄λμ€
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(AttackUnit, Flyable): #μ΄μ€μ
def __init__(self, name, hp, damage, flying_speed):
AttackUnit.__init__(self, name, hp, 0, damage) #μ§μ μ€νΌλλ 0μΌλ‘ μ²
Flyable.__init__(self, flying_speed)
def move(self, location):
print("[κ³΅μ€ μ λ μ΄λ]")
self.fly(self.name, location)
#λ μ΄μ€
class Wraith(FlyableAttackUnit):
def __init__(self):
FlyableAttackUnit.__init__("λ μ΄μ€", 80, 20, 5)
self.clocked = False #ν΄λ‘νΉ λͺ¨λ (ν΄μ μν)
def clocking(self):
if self.clocked == True: #ν΄λ‘νΉ λͺ¨λ --> ν΄μ
print("{0} : ν΄λ‘νΉ λͺ¨λλ₯Ό ν΄μ ν©λλ€. ".format(self.name))
self.clocked = False
def game_start():
print("[μλ¦Ό] μλ‘μ΄ κ²μμ μμν©λλ€.")
def game_over():
print("Player : gg") # good game
print("[νλ μ΄μ΄] λμ΄ κ²μμμ ν΄μ₯νμ
¨μ΅λλ€.")
#μ€μ κ²μ μ§ν
game_start()
#λ§λ¦° 3κ° μμ±
m1 = Marine()
m2 = Marine()
m3 = Marine()
#ν±ν¬ 2κ°
t1 = Tank()
t2 = Tank()
#λ μ΄μ€ 1κ°
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(unit, Marine):
unit.stimpack()
elif isinstance(unit,Tank):
unit.set_seize_mode()
elif isinstance(unit, Wraith):
unit.clocking()
#μ κ΅° 곡격
for unit in attack_units:
unit.attack("1μ")
#μ κ΅° νΌν΄
for unit in attack_units:
unit.damaged(randint(5, 21)) #곡격μ λλ€μΌλ‘ λ°μ (5~21)
game_over()
'Coding > Python' μΉ΄ν κ³ λ¦¬μ λ€λ₯Έ κΈ
[python] μμΈ μ²λ¦¬ (0) | 2021.11.04 |
---|---|
[python] ν΄λμ€ ν΄μ¦ (0) | 2021.11.03 |
[python] ν΄λμ€(pass, super) (0) | 2021.11.03 |
[python] ν΄λμ€(λ©μλ μ€λ²λΌμ΄λ©) (0) | 2021.11.03 |
[python] ν΄λμ€(λ€μ€μμ) (0) | 2021.11.03 |