Practice : Starcraft Project
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('{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)
def stimpack(self):
if self.hp > 10:
self.hp -= 10
print('{0} : 스팀팩 사용 (-10hp)'.format(self.name))
else:
print('{0} : 체력 부족'.format(self.name))
class Tank(AttackUnit):
seize_developed = False
def __init__(self):
AttackUnit.__init__(self, '탱크', 150, 1, 35)
self.seize_mode = False
def set_seize_mode(self):
if Tank.seize_developed == False:
return
if self.seize_mode == 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)
Flyable.__init__(self, flying_speed)
def move(self, location):
self.fly(self.name, location)
class Wraith(FlyableAttackUnit):
def __init__(self):
FlyableAttackUnit.__init__(self, '레이스', 80, 20, 5)
self.clocked = False
def clocking(self):
if self.clocked == True:
print('{0} : 클로킹 해제'.format(self.name))
self.clocked = False
else:
print('{0} : 클로킹 모드'.format(self.name))
self.clocked = True
def game_start():
print('[알림] 새로운 게임을 시작')
def game_over():
print('Lilmeow : gg')
print('[Lilmeow] 님이 게임에서 퇴장함')
game_start()
m1 = Marine()
m2 = Marine()
m3 = Marine()
t1 = Tank()
t2 = Tank()
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, 20))
game_over()
Quiz
class House:
def __init__(self, location, house_type, deal_type, price, completion_year):
self.location = location
self.house_type = house_type
self.deal_type = deal_type
self.price = price
self.completion_year = completion_year
def show_detail(self):
print('{0} {1} {2} {3} {4}'.format(self.location, self.house_type, self.deal_type, self.price, self.completion_year))
h1 = House('강남', '아파트', '매매', '10억', '2010년')
h2 = House('마포', '오피스텔', '전세', '5억', '2007년')
h3 = House('송파', '빌라', '월세', '500/50', '2000년')
h1.show_detail()
h2.show_detail()
h3.show_detail()