23.3.21 hello game hk만들기

HS L·2023년 3월 21일
0

만들어보기

목록 보기
1/4
import random

class You():
    hp = 300
    alive = True
    attack = random.randrange(5, 10)
    speed = random.randrange(1, 12)

    def damage(self,attack):
        self.hp = self.hp - attack
        if self.hp < 0:
            self.alive = False

    def update_status(self):
        self.attack = random.randrange(10,20)
        self.speed = random.randrange(5, 10)


class Monster():
    hp = 100
    alive = True
    attack = random.randrange(5, 10)
    speed = random.randrange(1,12)

    def damage(self, attack):
        self.hp = self.hp - attack
        if self.hp < 0:
            self.alive = False

    def update_status(self):
        self.attack = random.randrange(1, 15)
        self.speed = random.randrange(1, 15)

y = You()
m = Monster()

**#추가**
cnt = 0

**#전체 한번 더 감싸주기**
while(True):
    while(True):
        print(f'당신의 hp는 {y.hp} 입니다')
        print(f'몬스터의 hp는 {m.hp} 입니다')
        print(f'당신의 speed는 {y.speed} 입니다')
        print(f'몬스터의 speed는 {m.speed} 입니다')
        if y.speed > m.speed :
            print('당신은 공격을하고 몬스터의 공격을 피했습니다')
            print(f'당신은 몬스터에게 {y.attack}의 피해를 입혔습니다')
            m.damage(y.attack)
        elif y.speed < m.speed :
            print('몬스터는 공격을하고 당신의 공격을 피했습니다')
            print(f'몬스터는 당신에게 {m.attack}의 피해를 입혔습니다')
            y.damage(m.attack)

        y.update_status()
        m.update_status()
        if y.alive == False:
            print('당신은 몬스터에게 치명상을 입었습니다 !!!')
            print('You Died')
            break
        elif m.alive == False:
            print('축하합니다 당신은 몬스터를 쓰려트렸습니다 !!!')
            print(f'당신의 남은 hp는 {y.hp} 입니다')
            print(f'당신의 운빨 점수는 {round(y.hp/3)} 점 입니다 !')
            #회차 번호 부여
            cnt += 1
            break
    **#100점까지 강제 소생**
    if(round(y.hp/3)==100):
        print(f"{cnt}회차 100점 완료")
        break
    else:
        print(f"{cnt}회차 재시작")
        y.hp = 300
        m.hp = 100
        y.alive = True
        m.alive = True
        y.update_status()
        m.update_status()


profile
식이

0개의 댓글