文字冒险小游戏

第一个作品,希望能火。

用到了time模块

话不多说,上代码:

# @Time    : 2021 12 18 10:22
# @Author  : JeremyNot
# @FileName: Game_Chinese.py
# @Software: PyCharm
# @Mail    :[email protected]

'''--------------------嗨!直接右键单击-->选择"运行"就可以开始游戏啦!-------------------
   -----------如果遇到游戏问题,先参考"游戏说明.docx",还是无法解决的话欢迎和我联系-----------
   -----------------------------------祝游戏愉快-----------------------------------'''

import time
explosion = 0
tank2 = False

# -1. 从"医院/尖叫"选择点开始 -2. 从"电梯/楼梯"选择点开始
def flash_back1():
    choice6 = input('请选择回溯点:\n -1. 从"医院/尖叫"选择点开始\n -2. 从"电梯/楼梯"选择点开始\n>')

    if '1' in choice6:
        hospital_scream()
    elif '2' in choice6:
        hospital()
    else:
        print('(也就是说,可以回到过去的时间点吧?)')
        time.sleep(1)
        print('(要回到哪个时间点呢?输入1或2就可以了吧)')
        time.sleep(1)
        flash_back1()


# -1. 从"医院/尖叫"选择点开始 -2. 从"网吧/装甲车"选择点开始
def flash_back2():
    choice4 = input('请选择回溯点:\n -1. 从"医院/尖叫"选择点开始\n -2. 从"网吧/装甲车"选择点开始\n>')

    if '1' in choice4:
        hospital_scream()
    elif '2' in choice4:
        netbar_tank()
    else:
        print('(也就是说,可以回到过去的时间点吧?)')
        time.sleep(1)
        print('(要回到哪个时间点呢?输入1或2就可以了吧)')
        time.sleep(1)
        flash_back2()


# -1. 从"医院/求助声"选择点开始 -2. 从"帮助/走开"选择点开始
def flash_back3():
    choice5 = input('请选择回溯点:\n -1. 从"医院/求助声"选择点开始\n -2. 从"帮助/走开"选择点开始\n>')

    if '1' in choice5:
        hospital_scream()
    elif '2' in choice5:
        scream()
    else:
        print('(也就是说,可以回到过去的时间点吧?)')
        time.sleep(1)
        print('(要回到哪个时间点呢?输入1或2就可以了吧)')
        time.sleep(1)
        flash_back3()


# 1. 从"医院/尖叫"选择点开始 -2. 从"敲门/推门"选择点开始
def flash_back4():
    choice4 = input('请选择回溯点:\n -1. 从"医院/尖叫"选择点开始\n -2. 从"敲门/推门"选择点开始\n>')

    if '1' in choice4:
        hospital_scream()
    elif '2' in choice4:
        knock_open()
    else:
        print('(也就是说,可以回到过去的时间点吧?)')
        time.sleep(1)
        print('(要回到哪个时间点呢?输入1或2就可以了吧)')
        flash_back4()
        time.sleep(1)


def tank_password():
    password9 = False
    i = 0
    while password9 == False and i <= 3:
        password10 = input('来试试看吧,你输入了密码:\n>')
        i += 1
        if password10 == '19285' or password10 == 'black sheep wall':
            password9 = True
            print('密码正确!自爆程序停止')
            basement1_3()
        elif password10 == 'there is no cow level':
            password9 = True
            cheating()
        else:
            print('好像不太对,再试试看吧')
    else:
        print('3分钟到了,你还是没有解出正确的密码')
        time.sleep(1.5)
        print('你决定直接下车')
        time.sleep(1)
        print('但是已经太迟了')
        time.sleep(1)
        print('达成结局 11:什么?这就是彩蛋??'.center(80, '-'))

        flash_back2()


def cheating():
    print('这都被你发现了!?')
    time.sleep(1)
    print('看来我的游戏没有白做嘛')
    time.sleep(1)
    print('你就是为了这个来的吧?')
    input('>')
    time.sleep(1)
    print('来,给你吧:')
    time.sleep(1)
    print('达成真结局 10.1:there is no cow level'.center(80, '-'))
    time.sleep(1)
    print('达成真结局 10.2:隐藏成就达成'.center(80, '-'))
    time.sleep(1)
    print('达成真结局 10.3:白金奖杯取得'.center(80, '-'))
    time.sleep(1)
    print('达成真结局 10.4:全成就完成'.center(81, '-'))
    time.sleep(1)
    print('取得称号:硬核玩家'.center(82, '-'))
    time.sleep(1)
    print('\n感谢游玩!\n')
    time.sleep(1)
    exit(0)


def name_character():
    global name
    name = input('勇士啊,请告诉我你的名字吧:\n>')
    while bool(name) == False:
        print('你还没有告诉我你的名字呢!!!')
        name_character()


def career_choose():
    global career
    career = input(f'{name},你心仪的职业是(请输入数字,不带标点符号):\n>')
    if career == '1':
        career = '圣骑士'
        print('圣骑士?想不到你还挺传统的嘛!最近没什么人选圣骑士啦。不过圣骑士看起来挺能打的是不是?')
        time.sleep(2)
    elif career == '2':
        career = '巫师'
        print('巫师?唔...虽然这件事不该对玩家透漏,不过这个版本巫师被削弱得很厉害...开玩笑的')
        time.sleep(2)
    elif career == '3':
        career = '盗贼'
        print('盗贼?我就知道!我已经看穿你内心的邪恶念头啦!')
        time.sleep(1.5)
    elif career == '4':
        career = '高达驾驶员'
        print('恭喜你发现隐藏职业高达驾驶员!虽然游戏里并不保证配备高达,但是能驾驶高达毕竟是一项难能可贵的技能嘛!')
        time.sleep(2)
    else:
        print('我说了只有三个职业!你在想什么!再给你一次机会吧')
        time.sleep(1.5)
        career_choose()
    return career


def control_room_password2():
    password8 = input('你在主控室的密码面板上输入了:\n -1. power overwhelming\n -2. black sheep wall \n -3. there is no cow level')
    password8 = input('请输入数字,不带标点符号\n>')
    if password8 == '1':
        print('好像失败了....')
        time.sleep(1)
        print('(该死,星际争霸果然是个老游戏了)')
        time.sleep(1.5)
        print('再回忆一下吧...')
        time.sleep(1)
        control_room_password2()

    elif password8 == '2':
        print('密码正确!')
        time.sleep(1)
        print('(这个作弊码已经很久没用过了,充满了过去的回忆)')
        time.sleep(1.5)
        basement1_4()
    elif password8 == '3':
        print('你输入了这个无敌的作弊码')
        time.sleep(1)
        cheating()
    elif password8 == 'black sheep wall':
        print('你已经深谙此道,直接输入了作弊码')
        time.sleep(1.5)
        basement1_4()
    elif password8 == 'there is no cow level':
        print('你已经深谙此道,直接输入了终极作弊码')
        time.sleep(1.5)
        cheating()
    else:
        print('你输入了一串不知名的字符,尝试打开密码门')
        time.sleep(1.5)
        print('但是失败了!')
        time.sleep(1)
        print('再试一次吧...只要输入1、2或者3就可以了')
        time.sleep(1.5)
        control_room_password2()


def basement1_2():
    turn_off = input('要按下关闭按钮吗?\n1. 按下去吧\n2. 果然还是别按了\n>')
    time.sleep(1.5)
    if turn_off == '2':
        print('(莫名其妙的按钮按下去可能很危险,还是别去碰比较好)')
        time.sleep(1.5)
        print('这么想着,你离开了主控室')
        time.sleep(1.5)
        print('\n(接下来去哪里好呢...)')
        time.sleep(1.5)
        print('你在基地里漫无目的地游荡')
        input('>')
        time.sleep(1.5)
        print('(感觉越来越饿了...)')
        time.sleep(1.5)
        print('你的意识开始模糊,耳畔传来尖锐的耳鸣')
        time.sleep(1.5)
        print('(啊,食物的味道...)')
        input('>')
        time.sleep(1.5)
        print('你扑向了那个看起来有些熟悉的身影')
        time.sleep(1.5)
        print('达成结局 9:是我...杀了我...?'.center(80, '-'))
        time.sleep(1.5)
        print('正在回溯时间.....')
        input('>')
        time.sleep(1.5)
        print('一看你就没有看支线任务的内容吧?')
        time.sleep(1.5)
        print('待会儿记得去网吧看看吧')
        time.sleep(1.5)
        print('但是我们不需要从那么久远的地方重新开始...')
        time.sleep(1.5)
        print('你回到了"OFF"按钮前')
        basement1_2()
    elif turn_off == '1':
        print('也许按下按钮,关闭的通道会形成巨大的能量缺口,吞噬一切')
        time.sleep(1.5)
        print('但就算这样,也比这个崩坏的世界要好')
        time.sleep(1.5)
        print('你毅然决然地按下了按钮')
        input('>')
        time.sleep(1.5)
        print('身边的一切似乎开始逐渐消失了')
        time.sleep(1.5)
        print('耳边传来系统的声音:')
        time.sleep(1.5)
        print(f'"{name},【门 1:循环的世界】任务完成"')
        input('>')
        time.sleep(1.5)
        print('达成真结局 10:时间旅行者'.center(80, '-'))
        time.sleep(1.5)
        print('感谢游玩!')
        exit(0)
    else:
        print('你在原地纠结了好一会儿...最终还是决定:')
        basement1_2()


def basement1_3():
    print('你成功解除了自爆程序')
    time.sleep(1)
    print('这时你才发现,前方不远处有一只长相抽象、好像蜥蜴、蛇与蟑螂融合体的生物"')
    time.sleep(2)
    print('它黄色的眼睛眯成了一条细缝,示威似的盯着你')
    input('>')
    time.sleep(1.5)
    print('拥有一辆装甲车的你丝毫不慌,准备直接把对面轰成碎片')
    time.sleep(1.5)
    print('这时你发现,这辆装甲车已经备有弹药了')
    input('>')
    time.sleep(1.5)
    print('(...........靠)')
    time.sleep(1)
    print('(不能就这样坐以待毙下去),你想')
    time.sleep(1.5)
    print('稍加思索,你在控制台上输入了:')
    time.sleep(1.5)
    print('''[Capital 77777777]  04070000 005352A0 04A2CB71''')
    input('>')
    time.sleep(1)
    print('''[Player Inf HP]   04070000 00535300 A9017BFD''')
    input('>')
    time.sleep(1)
    print('''[Change EN Max]   04070000 00316740 2A0003E8''')
    input('>')
    time.sleep(1)
    print('''[Change MP Max]   04070000 003171F0 2A0003E8''')
    input('>')
    time.sleep(1)
    print('''[Check Pilot AP Max]   04070000 00228A30 B9001E69''')
    input('>')
    time.sleep(1)
    print('''[Pilot Upgrade 999]   04070000 0053528C 00009528''')
    input('>')
    time.sleep(1)
    print('你驾驶装甲车自信满满地炸死了面前的奇怪生物')
    time.sleep(1.5)
    print('(原来开金手指是这样的感觉啊)')
    input('>')
    time.sleep(1)
    print('装甲车上的导航系统显示出主控室的位置')
    time.sleep(1.5)
    print('看来主控室在地下,是一个类似防空洞之类的避难处')
    time.sleep(1.5)
    print('你下了车,往地下避难处走去')
    input('>')
    time.sleep(1)
    print('来到主控室面前,主控室的玻璃门紧闭,旁边有一个密码面板')
    time.sleep(1.5)
    print('\n(又是密码,去他妈的密码)')
    time.sleep(1)
    print('不过,你现在有了其他的想法')

    control_room_password2()


def basement1_4():
    print('你成功进入了主控室')
    time.sleep(1.5)
    print('主控室内,上百台各式各样的设备同时运转,发出"嗡嗡"的蜂鸣声')
    time.sleep(2)
    print('这里一尘不染,看起来没有遭到入侵')
    time.sleep(1.5)
    print('\n(废话...这么绕的密码提示,谁能解得开)')
    time.sleep(1.5)
    print('(也就只有像我这种...)')
    time.sleep(1.5)
    print('在无数个黑色机箱的映衬下,墙上的红色"OFF"按钮显得格外醒目')
    time.sleep(1)
    basement1_2()


def control_room_password():
    print('''以下10道单选题只有唯一解,请问10题的答案各是什么?
    Q1:第一个答案为B的問題是哪一个问题?
        (A)2 (B)3 (C)4 (D)5 (E)6

    Q2:唯一连续两个有相同答案的问题是:
        (A)2,3 (B)3,4 (C)4,5 (D)5,6 (E)6,7

    Q3:本问题的答案和哪一和问题的答案相同?
        (A)1 (B)2 (C)4 (D)7 (E)6

    Q4:答案是A的问题的个数是:
        (A)0 (B)1 (C)2 (D)3 (E)4

    Q5:本问题的答案和哪一个问题的答案相同?
        (A)10 (B)9 (C)8 (D)7 (E)6

    Q6:答案A的个数和答案什么的个数相同?
        (A)B (B)C  (C)D (D)E (E)以上皆非

    Q7:按字母順序,本问题的答案和下一个问题的答案相差几个字母?(A和B相差1)
        (A)4 (B)3 (C)2 (D)1 (E)0

    Q8:答案为母音字母的问题有几个?(母音字母:AE)
        (A)2 (B)3 (C)4 (D)5 (E)6

    Q9:答案为子音字母的个数为:(子音字母:BCD)
        (A)质数 (B)阶乘数 (C)平方数 (D)立方数 (E)5的倍数

    Q10:本问题的答案是:
        (A)A (B)B (C)C (D)D (E)E''')
    time.sleep(2)
    print('密码为10个大写字母,不带标点符号'.center(80, '-'))
    time.sleep(1.5)
    control_room_password = False
    if career == '盗贼':
        print('你想像前几次一样直接打开密码锁')
        time.sleep(1)
        print('可主控室的安全等级很高,你无法破解')
        time.sleep(1.5)
        print('没办法,只好尝试着解题了')
        time.sleep(1.5)
    while control_room_password == False:
        password6 = input('经过一番缜密的思考,你输入了:\n>')
        if password6 == 'CDEBEEDCBA' or password6 == 'black sheep wall':
            control_room_password = True
            print('密码正确!')
            time.sleep(1)
            basement1_4()
        elif password6 == 'there is no cow level':
            cheating()
        else:
            print('密码错误')
            time.sleep(1)
            print('我的答案不对吗?再好好想想吧')


def glass_door():
    password2 = False
    print('在密码面板旁边,你们看到了密码提示:')
    time.sleep(1)
    print('''一天晚上,赵先生和赵太太邀請钱先生、钱太太、孙先生、孙太太到家里吃饭,
             饭后他们一起打牌聊天。一聊之下,发现其中有一位最近中了彩券,乐不可支。

             从他们当晚的互动,已知以下內容:

                -中奖者的配偶在当晚打牌输了
                -赵先生有心脏疾病,不能剧烈运动
                -钱太太当晚和另一位太太聊得起敬,都沒有一起打牌
                -钱先生和孙太太当晚初次见面,才认识的
                -赵先生打牌贏了,赵太太却打输了
                -钱先生上周才和中奖者一起参加马拉松比赛
             请问,那位幸运的中奖者是谁?''')
    time.sleep(2)
    print('密码为3个中文字符'.center(80, '-'))
    time.sleep(1.5)
    print('\n(哪家科研机构会把密码提示贴在门边啊????)')
    time.sleep(1.5)
    print('(你们活该被入侵好吧??)\n')
    time.sleep(1.5)
    while password2 == False:
        if head == True:
            print('你突然想起了背包里的"死不瞑目的看门人头颅"')
            time.sleep(1.5)
            print('你将头颅靠近密码密码面板')
            time.sleep(1.5)
            print('"虹膜识别成功"')
            time.sleep(1)
            print('门开了')
            time.sleep(1)
            password2 = True
        elif career == '盗贼':
            print('(不过,我的职业是盗贼,应该对密码类很擅长吧?)')
            time.sleep(1.5)
            print(f'"系统提示:{name}使用主动技能"即使是中世纪的盗贼,也能开27世纪的密码锁"!')
            time.sleep(2)
            print('"系统提示:密码破解成功!"')
            time.sleep(1)
            print('\n(...等等,那个主动技能名字叫什么来着??)\n')
            time.sleep(1.5)
            password2 = True
        else:
            print('还是思考一下吧...')
            time.sleep(1.5)
            password2 = input('几经思考,你输入了:\n>')
            time.sleep(1.5)
            if password2 == '钱太太' or password2 == 'black sheep wall':
                print('密码正确!\n门开了')
                time.sleep(1.5)
            elif password2 == 'there is no cow level':
                cheating()
            else:
                print('密码错误')
                time.sleep(1.5)


def giant_spider():
    global head
    head = False
    print('你们拔出了武器')
    time.sleep(1.5)
    if career == '圣骑士':
        print('你刚拔出圣剑,准备大战一场,耳边突然传来了系统提示:')
        time.sleep(1.5)
        print('系统提示:圣骑士从不欺凌弱小,哪怕是一只小小的蜘蛛')
        time.sleep(1.5)
        print('\n(合着职业设定就是用来干这事儿的?????\n(你TM觉得这是一只小小的蜘蛛???))\n')
        time.sleep(2)
        print('但是无关紧要,高达驾驶员手中的武器显然非同小可,三两下就搞定了这只丑陋的生物')
        time.sleep(2)
    elif career == '巫师':
        print('(说起来,我是攻击型巫师还是辅助型巫师啊...)')
        time.sleep(1.5)
        print('但是无关紧要,高达驾驶员手中的武器显然非同小可,三两下就搞定了这只丑陋的生物')
        time.sleep(2)
        print('在蜘蛛腹部,你发现了未消化的人类头颅')
        input('>')
        time.sleep(1.5)
        print(f'系统提示:玩家{name}发现"死不瞑目的看门人头颅"')
        time.sleep(1.5)
        print('\n(怎么觉得有点慎得慌...)\n')
        time.sleep(1.5)
        head = True
    else:
        print(f'作为{career},你没有直接攻击能力')
        time.sleep(1.5)
        print('但是无关紧要,高达驾驶员手中的武器显然非同小可,三两下就搞定了这只丑陋的生物')
        time.sleep(2)


def basement1():
    print('基地内部依然光亮整洁,看来没有遭到入侵')
    time.sleep(1.5)
    print('但深入基地不久,你们就看到了身穿白衣的工作人员的尸体')
    input('>')
    time.sleep(1.5)
    print('尸体看上去没有变异的现象,但皮肤奇怪地干瘪,身体毫无水分')
    time.sleep(2)
    print('走廊一路延伸,消失在黑暗的尽头...')
    input('>')
    time.sleep(1.5)
    print('继续往前,走廊里弥漫着血腥味')
    time.sleep(1.5)
    print('走廊尽头传来密集快速的响声,听着不像是丧尸,更不是人类的脚步声')
    time.sleep(2)
    print('一只覆盖棕黑色斑纹与绒毛的巨型蜘蛛冲来,八条近两米长的腿断了三条,面对你们,张开了巨大的口器')
    time.sleep(2)
    giant_spider()
    print('蜘蛛不再是威胁,你们成功地来到走廊尽头')
    time.sleep(1.5)
    print('走廊尽头的玻璃门紧闭着,上有代表机密出入通道的密码面板 ')
    input('>')
    time.sleep(1.5)
    glass_door()
    print('你们成功进入了1号电子通道基地的科研室')
    time.sleep(1.5)
    print('科研室的设备都还在正常运作')
    time.sleep(1.5)
    print('地上散落着四五具身穿白衣的科研人员尸体,身上布满了白色粘液')
    time.sleep(1.5)
    print('通风管道的滤门大开,看起来刚才的巨型蜘蛛可能是从那里进入了科研室,杀光了工作人员')
    time.sleep(2)
    print('不过既然已经解决掉它了,应该不会再有危险')
    input('>')
    time.sleep(1.5)
    print('你们走近了正在运行的电脑')
    time.sleep(1.5)
    print('电脑屏幕上显示着"电子通道1正常运行中"')
    time.sleep(1.5)
    print('桌上有许多文件,你正要看看能不能找到关于这个研究室的线索,上方的通风管道突然传来了轻快密集的脚步声')
    input('>')
    time.sleep(2)
    print('一条细长的舌头从管道口伸了出来,一把将你卷入了腹内')
    time.sleep(1.5)
    print('舌头主人的腹腔里又湿又热,你听到外界传来机枪扫射的声音')
    time.sleep(1.5)
    print('随后是一阵天旋地转,你不知被这怪物带去了哪里')
    input('>')
    time.sleep(1.5)
    print('枪声一路追随着你,你知道这是队友在尝试救你')
    time.sleep(1.5)
    print('但枪声听起来越来越远了,舌头的主人可能已经逃进了通风管道')
    input('>')
    time.sleep(1.5)
    print('皮肤传来灼烧感,胃酸开始腐蚀你的身体了')
    time.sleep(1.5)
    print('更要命的是,这里的氧气严重不足,你已经无法清醒地思考了...')
    time.sleep(1.5)
    if explosion == True:
        print('朦胧间,你听到了爆炸声')
        time.sleep(1.5)
        print('但由于没有直接遭受冲击,你并没有受严重的伤')
        time.sleep(2)
        print('反倒是把你吞下肚的怪物似乎一命呜呼了')
        input('>')
        time.sleep(2)
        print('你从令人作呕的腥臭胃液中爬了出来')
        time.sleep(2)
        print('在不远处,你看到了高达驾驶员的尸体')
        time.sl
  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
好的,以下是一个简单的 C++ 文字冒险小游戏的代码,供你参考: ```cpp #include <iostream> #include <string> #include <cstdlib> #include <ctime> using namespace std; // 定义魔法属性枚举类型 enum MagicType { FIRE, ICE, LIGHTNING }; // 定义魔法师类 class Wizard { public: Wizard(string name, MagicType magicType) { this->name = name; this->magicType = magicType; this->level = 1; this->exp = 0; this->gold = 0; } // 获取魔法师名字 string getName() { return this->name; } // 获取魔法属性 MagicType getMagicType() { return this->magicType; } // 获取魔法师等级 int getLevel() { return this->level; } // 获取魔法师经验值 int getExp() { return this->exp; } // 获取魔法师金币 int getGold() { return this->gold; } // 增加经验值 void addExp(int exp) { this->exp += exp; if (this->exp >= this->level * 10) { levelUp(); } } // 增加金币 void addGold(int gold) { this->gold += gold; } private: string name; // 魔法师名字 MagicType magicType; // 魔法属性 int level; // 魔法师等级 int exp; // 魔法师经验值 int gold; // 魔法师金币 // 升级 void levelUp() { this->level++; this->exp = 0; cout << "恭喜你升级了!当前等级为:" << this->level << endl; } }; // 定义场景枚举类型 enum SceneType { START, FOREST, CAVE, TOWN, BOSS }; // 定义场景类 class Scene { public: Scene(string name, SceneType sceneType) { this->name = name; this->sceneType = sceneType; } // 获取场景名字 string getName() { return this->name; } // 获取场景类型 SceneType getSceneType() { return this->sceneType; } // 进入场景 void enter(Wizard& wizard) { cout << "进入" << this->name << "场景" << endl; switch (this->sceneType) { case START: cout << "欢迎来到魔法世界!" << endl; break; case FOREST: cout << "你来到一片森林,里面有许多魔法怪物,要小心!" << endl; battle(wizard); break; case CAVE: cout << "你来到了一个山洞,里面似乎有什么宝藏!" << endl; explore(wizard); break; case TOWN: cout << "你来到了一个小镇,可以购买装备和药品!" << endl; shop(wizard); break; case BOSS: cout << "你来到了最终Boss的巢穴,准备好战斗了吗?" << endl; battle(wizard, true); break; default: break; } } private: string name; // 场景名字 SceneType sceneType; // 场景类型 // 进行战斗 void battle(Wizard& wizard, bool isBoss = false) { int enemyHp = rand() % 10 + 1; int playerHp = 10; int round = 1; cout << "敌人出现了!它的生命值为:" << enemyHp << endl; while (enemyHp > 0 && playerHp > 0) { int playerDamage = rand() % 3 + 1; int enemyDamage = rand() % 3 + 1; if (isBoss) { playerDamage += wizard.getLevel(); enemyDamage += wizard.getLevel(); } cout << "第" << round << "回合:你使用了魔法攻击,造成了" << playerDamage << "点伤害!" << endl; enemyHp -= playerDamage; if (enemyHp <= 0) { cout << "你战胜了敌人!获得了" << wizard.getLevel() << "点经验值和10个金币!" << endl; wizard.addExp(wizard.getLevel()); wizard.addGold(10); break; } cout << "敌人使用了魔法攻击,造成了" << enemyDamage << "点伤害!" << endl; playerHp -= enemyDamage; if (playerHp <= 0) { cout << "你被敌人打败了!" << endl; break; } round++; } } // 探索宝藏 void explore(Wizard& wizard) { int gold = rand() % 10 + 1; cout << "你发现了一些金币,共" << gold << "个!" << endl; wizard.addGold(gold); } // 商店购买 void shop(Wizard& wizard) { int choice; while (true) { cout << "请选择购买项目:" << endl; cout << "1. 魔法药品(10金币/个)" << endl; cout << "2. 魔法装备(50金币/个)" << endl; cout << "3. 离开商店" << endl; cin >> choice; if (choice == 1) { if (wizard.getGold() < 10) { cout << "你的金币不足!" << endl; } else { wizard.addGold(-10); cout << "购买成功!你的金币还剩下:" << wizard.getGold() << endl; } } else if (choice == 2) { if (wizard.getGold() < 50) { cout << "你的金币不足!" << endl; } else { wizard.addGold(-50); cout << "购买成功!你的金币还剩下:" << wizard.getGold() << endl; } } else if (choice == 3) { break; } else { cout << "选择无效!" << endl; } } } }; int main() { srand(time(nullptr)); // 初始化随机数种子 string name; int magicTypeChoice; cout << "欢迎来到魔法世界!请输入你的名字:" << endl; cin >> name; cout << "请选择你的魔法属性:" << endl; cout << "1. 火" << endl; cout << "2. 冰" << endl; cout << "3. 雷" << endl; cin >> magicTypeChoice; MagicType magicType; switch (magicTypeChoice) { case 1: magicType = FIRE; break; case 2: magicType = ICE; break; case 3: magicType = LIGHTNING; break; default: magicType = FIRE; break; } Wizard wizard(name, magicType); Scene startScene("起始之地", START); Scene forestScene("森林", FOREST); Scene caveScene("山洞", CAVE); Scene townScene("小镇", TOWN); Scene bossScene("最终Boss巢穴", BOSS); Scene* currentScene = &startScene; // 当前场景 while (true) { currentScene->enter(wizard); if (currentScene->getSceneType() == BOSS && wizard.getExp() >= wizard.getLevel() * 100) { cout << "恭喜你通关了!" << endl; break; } int choice; cout << "请选择下一步:" << endl; cout << "1. 前往森林" << endl; cout << "2. 前往山洞" << endl; cout << "3. 前往小镇" << endl; if (currentScene->getSceneType() == BOSS) { cout << "4. 再次挑战最终Boss" << endl; } cin >> choice; if (choice == 1) { currentScene = &forestScene; } else if (choice == 2) { currentScene = &caveScene; } else if (choice == 3) { currentScene = &townScene; } else if (choice == 4 && currentScene->getSceneType() == BOSS) { currentScene = &bossScene; } else { cout << "选择无效!" << endl; } } return 0; } ``` 注意:这只是一个简单的示例代码,实际的游戏可能需要更多的功能和优化。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值