-
# # station="사당"
# # print(station+"행 열차가 들어오고있습니다.")
# #print("hello")
# # url="http://naver.com"
# # my_str=url.replace("http://","")
# # #print(my_str)
# # my_str=my_str[:my_str.index(".")]
# # print(my_str)
# # password=my_str[:3]+str(len(my_str))+str(my_str.count("e"))+"!"
# # print(password)
# # print("{0}의 비밀번호는{1}입니다.".format(url,password))
# # from random import *
# # lst=[1,2,3,4,5]
# # print(lst)
# # shuffle(lst)
# # print(lst)
# # print(sample(lst,1))
# # from random import *
# # users=range(1,21)
# # #print(type(users))
# # users=list(users)
# # #print(type(users))
# # print(users)
# # shuffle(users)
# # print(users)
# # winners =sample(users,4)
# # print("당첨자발표")
# # print("치킨당첨자{0}".format(winners[0]))
# # print("커피당첨자{0}".format(winners[1:]))
# # abset=[2,5]
# # no_book=[8]
# # for student in range(1,11):
# # if student in abset:
# # continue
# # elif student in no_book:
# # print("오늘 수업 여기까지.{0}는 교무실로".format(student))
# # break
# # print("{0},책읽어봐".format(student))
# from random import *
# cnt=0
# for i in range(1,51):
# time=randrange(5,51)
# if 5<=time<15:
# print("[0] {0}번째 손님 (소요시간):{1}분)".format(i,time))
# cnt+=1
# else:
# print("[]{0}번째 손님 (소요시간):{1}분)".format(i,time))
# print("총 탑승승객:{0}분".format(cnt))
# def std_weigth(heigth,gender):
# if gender=="남자":
# return heigth*heigth*22
# else:
# return heigth*heigth*21
# heigth=160
# gender="여자"
# weigth=round(std_weigth(heigth/100,gender),2)#소수점 둘쨰자리
# print("키{0}cm{1}의 표준체중은 {2}kg입니다.".format(heigth,gender,weigth))
# import pickle
# score_file=open("score.txt","w",encoding="utf8")
# print("수학:0",file=score_file)
# print("영어:10",file=score_file)
## score_file.close()
# score_file=open("score.txt","a",encoding="utf=8")
# score_file.write("과학:80")
# score_file.write("\n코딩:100")
# score_file=open("score.txt","r",encoding="utf-8")
# print(score_file.read())
# score_file.close()
# print(score_file.readline(),end="")
#score_file=open("score.txt","r",encoding="utf-8")
# while True:
# line=score_file.readline()
# if not line:
# break
# print(line,end="")
# score_file.close()
# score_file=open("score.txt","r",encoding="utf-8")
# lines = score_file.readlines()
# for line in lines:
# print(line,end="")
# score_file.close()
#import pickle
# profile_file =open("profile.pickle","wb")
# profile = {"이름:박명수,나이:30,취미:[축구,골프,코딩]"}
# print(profile)
# pickle.dump(profile,profile_file)#profile에있는 정보를 file에저장
# profile_file.close()
# profile_file=open("profile.pickle","rb")
# profile =pickle.load(profile_file)#file에 있는 정보를 profile에 불러오기
# print(profile)
# profile_file.close()
#with open("profile.pickle","rb")as profile_file:
# print(pickle.load(profile_file))
# with open("study.txt","w",encoding="utf-8")as study_file:
# study_file.write("파이썬 공부중")
# with open("study.txt","r",encoding="utf-8") as study_file:
# print(study_file.read())
# for i in range(1,51):
# with open(str(i)+"주차.txt","w",encoding="utf-8") as report_file:
# report_file.write("{0}주차 주간보고".format(i))
# report_file.write("부서:")
# report_file.write("\n이름:")
# report_file.write("\n업무요약:")
# class Unit:
# def __init__(self,name,hp,damage): #__init__생성자
# self.name=name #멤버변수
# self.hp=hp
# 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)
# wraith1=Unit("레이스",80,5)
# print("유닛이름:{0},공격력:{1}".format(wraith1.name,wraith1.damage))
# wraith2=Unit("빼앗은 레이스",80,5)
# wraith2.clocking=True
# if wraith2.clocking==True:
# print("{0}는 현재 클로킹상태입니다.".format(wraith2.name))
#일반유닛
class Unit:
def __init__(self,name,hp,speed): #__init__생성자
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,speed,damage): #__init__생성자
Unit.__init__(self,name,hp,speed)
# self.name=name #멤버변수
# self.hp=hp
self.damage=damage
def attack(self,location):
print("{0}:{1}방향으로 적군을 공격합니다.[공격력{2}]"\
.format(self.name,location,self.damage))
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))
# firebat1=AttackUnit("파이어벳",50,16)
# firebat1.attack("5시")
# #공격두번가정
# firebat1.damaged(25)
# firebat1.damaged(25)
#드랍쉽:공중유닛,수송기. 마린/파이어벳.탱크수송.공격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 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)
# #발키지 :공중공격 유닛, 한번에 14발 미사일
# valkyie=FlyableAttackUnit("발키리",200,6,5)
# # valkyie.fly(valkyie.name,"3시")
# Vulture = AttackUnit("벌쳐",80,10,20)
# battlecruiser=FlyableAttackUnit("배틀크루져",500,25,3)
# Vulture.move("11시")
# # battlecruiser.fly(battlecruiser.name,"9시")
# battlecruiser.move("9시")
#건물
class BuildingUnit(Unit):
def __init__(self,name ,hp , location):
# pass
# #서플라이 디폿: 건물,1개건물 = 8유닛
# supply_depot=BuildingUnit("서플라이 디폿",500,"7사")
# def game_start():
# print("[알림]:새로운 게임을 시작합니다.")
# def game_over():
# pass
# game_start()
# game_over()
#Unit.__init__(self,name,hp,0)
super().__init__(name,hp,0)
self.location=location
'개인공부 > 파이썬' 카테고리의 다른 글
메소드 오버라이딩 ,예외처리 (0) 2020.05.04 미니 스타 (0) 2020.05.04