23.3.28 game

HS L·2023년 3월 28일
0

만들어보기

목록 보기
3/4
"""
파일이름: game.py
작성자: 이현식
작성일: 2023년 3월 28일

처음 실행시 Player명을 입력합니다.
생성 후 처음 위치는 마을이며 각각의 input값에 의해 게임이 진행됩니다.
게임오버시 hp = 0인상태로 마을로 귀환, 휴식을 통해 hp를 회복하지 않으면 사냥하기 진행 불가
input()
1.사냥하기
    필드로 나가 Monster그룹중 랜덤으로 생성되는 객체와 만납니다.
    객체와 마주친 후 input입력값을 받아올 수 있는 창이 뜨고 해당 값에 따라 게임이 진행됩니다.
    -input()
    1.싸운다
        Monster와 전투 실행
        Player와 Monster의 speed값 판단, 높은 순으로 선/후공 진행(선공 후 타겟의 hp값에따라 후공진행여부 결정)
        input()
        1.일반공격 - Player의 power값에서 랜덤성부여, 횟수 제한 없음
        2.마법공격 - Player의 mp 10 소모 일반공격보다 높은 damage, mp가 0일때 사용불가 메세지 띄움
        3.회복 - Player의 hp/mp 회복기능 회복 시 공격기회 없음. Monster의 공격은 진행
        4.도망가기 - 전투에서 물러남.(기존 전투중이었던 Monster와 마주친상태로 돌아감)
    2.도망친다
        기존 Monster와 다른 Monster를 새로 생성
    3.마을로 돌아가기
        필드를 벗어나 처음 마을 위치로 되돌아감

2.휴식하기
    마을귀환 또는 Game Over후 hp=0인상태일때 휴식하기를 통해 hp/mp를 max까지 채워준다.

3.종료하기
    마을에서 게임종료시 사용되는 input
"""
import random
import time

# 미구현 리스트 = ['상점','카운트 유지기능','돈','경험치','레벨']


# 플레이어, 몬스터 super class
class Character:

    def __init__(self, name, hp, mp, power, speed, alive):
        self.name = name
        self.max_hp = hp
        self.hp = hp
        self.max_mp = mp
        self.mp = mp
        self.power = power
        self.speed = speed
        self.atkspeed = speed
        self.alive = alive
        self.alive_st = alive

    def attack(self, other):
        damage = random.randint(self.power - 2, self.power + 2)
        other.hp = max(other.hp - damage, 0)
        print(f"{self.name}의 몽통박치기! {other.name}에게 {damage}의 데미지를 입혔습니다.")
        if other.hp == 0:
            print(f"{other.name}이(가) 쓰러졌습니다.")

    def m_attack(self, other):
        damage = random.randint(self.power + 10, self.power + 20)
        p.mp = max(p.mp - 10, 0)
        other.hp = max(other.hp - damage, 0)
        print(f"{self.name}의 스피드스타! {other.name}에게 {damage}의 데미지를 입혔습니다.")
        if other.hp == 0:
            print(f"{other.name}이(가) 쓰러졌습니다.")

    def atk_speed(self):
        self.atkspeed = random.randint(self.speed - 10, self.speed + 10)

    def show_status(self):
        print(
            f"{self.name}의 상태:\nHP {self.hp}/{self.max_hp}\nMP {self.mp}/{self.max_mp}")

    def st_alive(self):
        if self.hp > 0:
            self.alive_st = True
        else:
            self.alive_st = False

    def heal_hp(self):
        self.hp += 50
        if self.hp > self.max_hp:
            self.hp = self.max_hp

    def heal_mp(self):
        self.mp += 50
        if self.mp > self.max_mp:
            self.mp = self.max_mp


# 플레이어
class player(Character):
    def __init__(self, name, hp=100, mp=100, power=20, speed=20):
        super().__init__(name, hp, mp, power, speed, alive=True)
        print('-'*40, '\n', f'캐릭터 {self.name} 생성 완료!')


# 몬스터
class monster_one(Character):
    def __init__(self, name, hp=50, mp=0, power=10, speed=15):
        super().__init__(name, hp, mp, power, speed, alive=True)


class monster_two(Character):
    def __init__(self, name, hp=70, mp=0, power=15, speed=15):
        super().__init__(name, hp, mp, power, speed, alive=True)


class monster_three(Character):
    def __init__(self, name, hp=100, mp=0, power=20, speed=15):
        super().__init__(name, hp, mp, power, speed, alive=True)


class monster_boss(Character):
    def __init__(self, name, hp=300, mp=0, power=30, speed=20):
        super().__init__(name, hp, mp, power, speed, alive=True)


# 몬스터 이름
name_list_one = ['피카츄', '이상해씨', '파이리', '꼬부기', '꼬렛',
                 '이브이', '구구', '뿔충이', '캐터피', '깨비참', '꼬마돌']

name_list_two = ['라이츄', '이상해풀', '리자드', '어니부기', '레트라',
                 '피죤', '딱충이', '단데기', '데구리']

name_list_three = ['이상해꽃', '리자몽', '거북왕', '샤미드',
                   '쥬피썬더', '부스터', '피죤투', '독침붕', '버터풀', '깨비드릴죠', '딱구리']

name_list_boss = ['칠색조', '루기아']


# 필드 입장
def fight():
    catch = 0
    field = True

    while field == True:
        print('몬스터를 찾는중...')
        time.sleep(1)

        # 몬스터 생성
        class_list = [monster_one, monster_two, monster_three, monster_boss]
        random_class = random.choice(class_list)
        if random_class == monster_one:
            mon = random_class(name=str(random.sample(name_list_one, 1)))
        elif random_class == monster_two:
            mon = random_class(name=str(random.sample(name_list_two, 1)))
        elif random_class == monster_three:
            mon = random_class(name=str(random.sample(name_list_three, 1)))
        elif random_class == monster_boss:
            mon = random_class(name=str(random.sample(name_list_boss, 1)))

        # 몬스터 발견
        while p.alive_st == True:
            time.sleep(1)
            select = input(
                f'\n야생의 {mon.name}이(가) 나타났다!\n무엇을 하시겠습니까?\n1.싸운다 2.도망친다 3.마을로 돌아가기\n')

            if select == '2':  # 도망가기
                print('-'*40, '\n호다닥..호다닥..')
                break

            elif select == '3':  # 마을로 가기
                field = False
                break

            elif select == '1':  # 전투시작
                print('-'*40, '\n')
                p.show_status()
                mon.show_status()
                # 전투 시작
                while True:
                    if p.hp > 0:  # player 생존
                        print('-'*40, '\n')
                        choice = input(
                            '어떤 행동을 하시겠습니까?\n1.일반공격 2.마법공격 3.회복 4.도망친다\n')

                        if choice == '1':  # 일반공격
                            print('-'*40, '\n')
                            p.atk_speed()
                            mon.atk_speed()
                            print('공격속도\n', p.name, ':', p.atkspeed,
                                  '\t', mon.name, ':', mon.atkspeed)

                            # 내공속 > 몹공속
                            if ((p.atkspeed) >= (mon.atkspeed)):
                                p.attack(mon)
                                if mon.hp > 0:
                                    mon.attack(p)
                                    p.show_status()
                                    mon.show_status()
                                    if p.hp == 0:
                                        print('Game Over...')
                                        field = False
                                        p.alive_st = False
                                        break
                                else:  # 승리 후 다음 몬스터 랜덤생성
                                    print(mon.name, '을 헤치웠다!')
                                    catch += 1
                                    class_list = [
                                        monster_one, monster_two, monster_three, monster_boss]
                                    random_class = random.choice(class_list)

                                    if random_class == monster_one:
                                        mon = random_class(
                                            name=str(random.sample(name_list_one, 1)))

                                    elif random_class == monster_two:
                                        mon = random_class(
                                            name=str(random.sample(name_list_two, 1)))

                                    elif random_class == monster_three:
                                        mon = random_class(
                                            name=str(random.sample(name_list_three, 1)))
                                    elif random_class == monster_boss:
                                        mon = random_class(
                                            name=str(random.sample(name_list_boss, 1)))
                                    print('잡은 횟수:', catch)

                                    break

                            # 몹공속 > 내공속
                            elif ((p.atkspeed) < (mon.atkspeed)):
                                mon.attack(p)
                                if p.hp > 0:
                                    p.attack(mon)
                                    p.show_status()
                                    mon.show_status()
                                    if mon.hp == 0:  # 승리 후 다음 몬스터 랜덤생성
                                        print(mon.name, '을 헤치웠다!')
                                        catch += 1
                                        class_list = [
                                            monster_one, monster_two, monster_three, monster_boss]
                                        random_class = random.choice(
                                            class_list)

                                        if random_class == monster_one:
                                            mon = random_class(
                                                name=str(random.sample(name_list_one, 1)))

                                        elif random_class == monster_two:
                                            mon = random_class(
                                                name=str(random.sample(name_list_two, 1)))

                                        elif random_class == monster_three:
                                            mon = random_class(
                                                name=str(random.sample(name_list_three, 1)))
                                        elif random_class == monster_boss:
                                            mon = random_class(
                                                name=str(random.sample(name_list_boss, 1)))
                                        print('잡은 횟수:', catch)
                                        break
                                else:
                                    print('Game Over...')
                                    field = False
                                    p.alive_st = False
                                    break

                            if mon.hp > 0 and p.hp > 0:
                                continue

                        elif choice == '2':  # 마법공격
                            if p.mp >= 10:
                                print('-'*40, '\n')
                                p.atk_speed()
                                mon.atk_speed()
                                print('공격속도\n', p.name, ':', p.atkspeed,
                                      '\t', mon.name, ':', mon.atkspeed)

                                # 내공속 > 몹공속
                                if ((p.atkspeed) >= (mon.atkspeed)):
                                    p.m_attack(mon)
                                    if mon.hp > 0:
                                        mon.attack(p)
                                        p.show_status()
                                        mon.show_status()
                                        if p.hp == 0:
                                            print('Game Over...')
                                            field = False
                                            p.alive_st = False
                                            break
                                    else:  # 승리 후 다음 몬스터 랜덤생성
                                        print(mon.name, '을 헤치웠다!')
                                        catch += 1
                                        class_list = [
                                            monster_one, monster_two, monster_three, monster_boss]
                                        random_class = random.choice(
                                            class_list)

                                        if random_class == monster_one:
                                            mon = random_class(
                                                name=str(random.sample(name_list_one, 1)))

                                        elif random_class == monster_two:
                                            mon = random_class(
                                                name=str(random.sample(name_list_two, 1)))

                                        elif random_class == monster_three:
                                            mon = random_class(
                                                name=str(random.sample(name_list_three, 1)))
                                        elif random_class == monster_boss:
                                            mon = random_class(
                                                name=str(random.sample(name_list_boss, 1)))
                                        print('잡은 횟수:', catch)
                                        break

                            # 몹공속 > 내공속
                                elif ((p.atkspeed) < (mon.atkspeed)):
                                    mon.attack(p)
                                    if p.hp > 0:
                                        p.m_attack(mon)
                                        p.show_status()
                                        mon.show_status()
                                        if mon.hp == 0:  # 승리 후 다음 몬스터 랜덤생성
                                            print(mon.name, '을 헤치웠다!')
                                            catch += 1
                                            class_list = [
                                                monster_one, monster_two, monster_three, monster_boss]
                                            random_class = random.choice(
                                                class_list)

                                            if random_class == monster_one:
                                                mon = random_class(
                                                    name=str(random.sample(name_list_one, 1)))

                                            elif random_class == monster_two:
                                                mon = random_class(
                                                    name=str(random.sample(name_list_two, 1)))

                                            elif random_class == monster_three:
                                                mon = random_class(
                                                    name=str(random.sample(name_list_three, 1)))
                                            elif random_class == monster_boss:
                                                mon = random_class(
                                                    name=str(random.sample(name_list_boss, 1)))
                                            print('잡은 횟수:', catch)
                                            break
                                    else:
                                        print('Game Over...')
                                        field = False
                                        p.alive_st = False
                                        break
                            else:
                                print('-'*40, '\nmp가 부족합니다!')
                                continue

                            if mon.hp > 0 and p.hp > 0:
                                continue

                        elif choice == '3':  # 회복
                            print('-'*40, '\n1.hp회복 2.mp회복')
                            sel = int(input())

                            if sel == 1:
                                print('빨간포션을 사용하여 hp가 50 회복됐습니다!')
                                p.heal_hp()
                                p.show_status()
                                print('-'*40, '\n')
                                time.sleep(1)
                                print(mon.name, '의 기습 몸통박치기!')
                                mon.attack(p)
                                p.show_status()
                                mon.show_status()
                                continue

                            elif sel == 2:
                                print('파란포션을 사용하여 mp가 50 회복됐습니다!')
                                p.heal_mp()
                                p.show_status()
                                print('-'*40, '\n')
                                time.sleep(1)
                                print(mon.name, '의 기습 몸통박치기!')
                                mon.attack(p)
                                p.show_status()
                                mon.show_status()
                                continue

                        elif choice == '4':  # 도망가기
                            print('-'*40, '\n호다닥..호다닥..')
                            break

                        else:
                            print(
                                '-*40\n잘못된 입력입니다.')
                            continue

                    else:
                        False  # p 죽음

            else:
                print('-'*40, '\n잘못된 입력입니다.')
                continue


# 플레이어 생성
print('"플레이 할 이름을 적어주세요"')
p = player(input())


# 생성완료 후, 마을 선택지
while True:
    print('-'*40, '\n')
    select = input('무엇을 하시겠습니까?\n1.사냥하기 2.휴식하기 3.종료하기\n')
    if select == '1':
        if p.hp == 0:
            print('-'*40, '\nhp가 0입니다! 휴식을 통해 회복해주세요!')
            continue
        print('-'*40, '\n사냥필드로 이동합니다')
        fight()
        print('-'*40, '\n마을로 이동했습니다.')
    elif select == '2':
        print('-'*40, '\n마을 휴식으로 hp, mp를 모두 회복하였습니다!')
        p.hp = p.max_hp
        p.mp = p.max_mp
        p.alive_st = True
        p.show_status()
    elif select == '3':
        print('-'*40, '\n')
        shutdown = input('정말로 종료하시겠습니까?\n[ y / n ]\n')
        if shutdown == 'y' or shutdown == 'Y' or shutdown == 'ㅛ' or shutdown == 'ㅜ':
            print('종료')
            break
        else:
            continue
    else:
        print('-'*40, '\n잘못된 입력입니다.')
        continue
profile
식이

0개의 댓글