找回密码
 立即注册

QQ登录

只需一步,快速开始

查看: 337|回复: 0

[经验] 随机线索功能(renpy进阶学习经验一)

[复制链接]
发表于 2023-10-2 20:43:02 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?立即注册

×
本帖最后由 烈林凤 于 2023-10-4 09:22 编辑

图片素材来源:明日方舟
图片素材魔改:明日方舟

10.02(20:45)因为上错图片导致今日额度没有了,图片只能等下次发了。
————————————————————————————————————————
10.02(20:46)因为升级了,所以多出了两额度,就先放出两张样例
————————————————————————————————————————
10.03(15:48)新增5张图片
————————————————————————————————————————
10.04(09:22)新增1张图片

花了几天时间捣鼓出来的东西,里面涉及到很多界面语言和python语句,当做素材/灵感来使用,也可以用作进阶学习,无所谓。
直接放代码了:
[RenPy] 纯文本查看 复制代码
## 定义线索数量
define clue_1 = 0
define clue_2 = 0
define clue_3 = 0
define clue_4 = 0
define clue_5 = 0
define clue_6 = 0
define clue_7 = 0
define numbers_list = []        ## 一个可以存放随机数的子集
define clue_lock_key = 0       ## 解锁条件

## 用于改变文本的样式
style text_style:
    size 40
    color "#39C5BB"             ## 初音色!!
    outlines [(absolute(1), "#000000", absolute(0), absolute(0))]## 黑色描边

## 初始随机数
init python:
    import random   ## 应用了随机数模块
    numbers_list = []       ## 建立一个可以存放随机数的子集
    random_numbers = (random.randint(1, 7))         ## 使R_N等于随机数
    while len(numbers_list) < 10:           ## 当随机数数量不足10时,进入循环
        if numbers_list.count(str(random_numbers)) >= 3:        ## 当“X”的数量大于3时将无法获取
            numbers_list.remove(str(random_numbers))            ## 将R_N转换为字符从子集中删去
            random_numbers = (random.randint(1, 7))             ## 使随机数再次改变
        else:
            numbers_list.append(str(random_numbers))            ## 将R_N转换为字符串加入到子集中
            random_numbers = (random.randint(1, 7))             ## 使随机数再次改变

    clue_list_1 = numbers_list.count("1")       ## 获取列表中“X”的数量
    clue_list_2 = numbers_list.count("2")
    clue_list_3 = numbers_list.count("3")
    clue_list_4 = numbers_list.count("4")
    clue_list_5 = numbers_list.count("5")
    clue_list_6 = numbers_list.count("6")
    clue_list_7 = numbers_list.count("7")

## 线索墙
screen Wall_of_clues:
    button:
        xsize 1120
        ysize 720
        action [Hide("menu_clues"), Show("Wall_of_clues")]      ## 透明的关闭按钮
    
    button:
        xpos 0.02
        ypos 0.9
        text "随机"
        action Jump("compute")      ## 随机按钮

    if clue_lock_key == 7:
        button:
            xpos 0.02
            ypos 0.8
            text "{size=30}解锁"
            action MainMenu(confirm=True)       ## 解锁按钮(此处作用为回到标题)

    if clue_1 == 0:             ## 等待放置的线索槽位
        button:
            add "images/clue_lock.png"
            xpos 0.1
            ypos 0.05
            action Show("menu_clues")       ## 打开待收取列表
    elif clue_1 >= 1:                       ## 展示已知的线索
        button:
            add "images/clue_1.png"
            text "{i}[clue_list_1]" style "text_style":         ## 使用到了"text_style"样式
                xpos 0.15
                ypos 0.35
            xpos 0.1
            ypos 0.05
            action [SetVariable("clue_1", clue_1-1), SetVariable("clue_lock_key", clue_lock_key-1)]## 使已收线索减1,使key加1
    
    if clue_2 == 0:
        button:
            add "images/clue_lock.png"
            xpos 0.3
            ypos 0.05
            action Show("menu_clues")
    elif clue_2 >= 1:
        button:
            add "images/clue_2.png"
            text "{i}[clue_list_2]" style "text_style":
                xpos 0.15
                ypos 0.35
            xpos 0.3
            ypos 0.05
            action [SetVariable("clue_2", clue_2-1), SetVariable("clue_lock_key", clue_lock_key-1)]

    if clue_3 == 0:
        button:
            add "images/clue_lock.png"
            xpos 0.5
            ypos 0.05
            action Show("menu_clues")
    elif clue_3 >= 1:
        button:
            add "images/clue_3.png"
            text "{i}[clue_list_3]" style "text_style":
                xpos 0.15
                ypos 0.35
            xpos 0.5
            ypos 0.05
            action [SetVariable("clue_3", clue_3-1), SetVariable("clue_lock_key", clue_lock_key-1)]

    if clue_4 == 0:
        button:
            add "images/clue_lock.png"
            xpos 0.7
            ypos 0.05
            action Show("menu_clues")
    elif clue_4 >= 1:
        button:
            add "images/clue_4.png"
            text "{i}[clue_list_4]" style "text_style":
                xpos 0.15
                ypos 0.35
            xpos 0.7
            ypos 0.05
            action [SetVariable("clue_4", clue_4-1), SetVariable("clue_lock_key", clue_lock_key-1)]

    if clue_5 == 0:
        button:
            add "images/clue_lock.png"
            xpos 0.1
            ypos 0.5
            action Show("menu_clues")
    elif clue_5 >= 1:
        button:
            add "images/clue_5.png"
            text "{i}[clue_list_5]" style "text_style":
                xpos 0.15
                ypos 0.35
            xpos 0.1
            ypos 0.5
            action [SetVariable("clue_5", clue_5-1), SetVariable("clue_lock_key", clue_lock_key-1)]
    
    if clue_6 == 0:
        button:
            add "images/clue_lock.png"
            xpos 0.3
            ypos 0.5
            action Show("menu_clues")
    elif clue_6 >= 1:
        button:
            add "images/clue_6.png"
            text "{i}[clue_list_6]" style "text_style":
                xpos 0.15
                ypos 0.35
            xpos 0.3
            ypos 0.5
            action [SetVariable("clue_6", clue_6-1), SetVariable("clue_lock_key", clue_lock_key-1)]

    if clue_7 == 0:
        button:
            add "images/clue_lock.png"
            xpos 0.5
            ypos 0.5
            action Show("menu_clues")
    elif clue_7 >= 1:
        button:
            add "images/clue_7.png"
            text "{i}[clue_list_7]" style "text_style":
                xpos 0.15
                ypos 0.35
            xpos 0.5
            ypos 0.5
            action [SetVariable("clue_7", clue_7-1), SetVariable("clue_lock_key", clue_lock_key-1)]

## 待收取的线索
screen menu_clues:
    frame:
        xsize 160
        ysize 720
        xcenter 1200
        ycenter 0.5
        viewport:
            xinitial 0.0
            yinitial 0.0
            mousewheel True
            draggable True
            side_yfill True
            vbox:
                spacing 10
                if "1" in numbers_list and clue_1 < 1:      ## 如果“X”包含在列表中,并且线索数量小于1时,展示线索
                    for clue_list_1 in range(1,numbers_list.count("1")+1):      ## 遍历,循环次数为“列表中‘X’的数量”
                        button:
                            add "images/clue_1.png":
                                xsize 115
                                ysize 165
                            action [SetVariable("clue_1", clue_1+1), SetVariable("clue_lock_key", clue_lock_key+1)]## 使已收取线索加1,使key加1

                if "2" in numbers_list and clue_2 < 1:
                    for clue_list_2 in range(1,numbers_list.count("2")+1):
                        button:
                            add "images/clue_2.png":
                                xsize 115
                                ysize 165
                            action [SetVariable("clue_2", clue_2+1), SetVariable("clue_lock_key", clue_lock_key+1)]

                if "3" in numbers_list and clue_3 < 1:
                    for clue_list_3 in range(1,numbers_list.count("3")+1):
                        button:
                            add "images/clue_3.png":
                                xsize 115
                                ysize 165
                            action [SetVariable("clue_3", clue_3+1), SetVariable("clue_lock_key", clue_lock_key+1)]

                if "4" in numbers_list and clue_4 < 1:
                    for clue_list_4 in range(1,numbers_list.count("4")+1):
                        button:
                            add "images/clue_4.png":
                                xsize 115
                                ysize 165
                            action [SetVariable("clue_4", clue_4+1), SetVariable("clue_lock_key", clue_lock_key+1)]

                if "5" in numbers_list and clue_5 < 1:
                    for clue_list_5 in range(1,numbers_list.count("5")+1):
                        button:
                            add "images/clue_5.png":
                                xsize 115
                                ysize 165
                            action [SetVariable("clue_5", clue_5+1), SetVariable("clue_lock_key", clue_lock_key+1)]

                if "6" in numbers_list and clue_6 < 1:
                    for clue_list_6 in range(1,numbers_list.count("6")+1):
                        button:
                            add "images/clue_6.png":
                                xsize 115
                                ysize 165
                            action [SetVariable("clue_6", clue_6+1), SetVariable("clue_lock_key", clue_lock_key+1)]

                if "7" in numbers_list and clue_7 < 1:
                    for clue_list_7 in range(1,numbers_list.count("7")+1):
                        button:
                            add "images/clue_7.png":
                                xsize 115
                                ysize 165
                            action [SetVariable("clue_7", clue_7+1), SetVariable("clue_lock_key", clue_lock_key+1)]

## 随机按钮跳转到这里,进行随机
label compute:
    ## 后面的内容和init python里的内容差不多
    python:
        clue_1 = 0              ## 重置已经搜集到的线索
        clue_2 = 0
        clue_3 = 0
        clue_4 = 0
        clue_5 = 0
        clue_6 = 0
        clue_7 = 0
        numbers_list.clear()    ## 清除列表
        random_numbers = (random.randint(1, 7))
        while len(numbers_list) < 10:
            if numbers_list.count(str(random_numbers)) >= 3:
                numbers_list.remove(str(random_numbers))
                random_numbers = (random.randint(1, 7))
            else:
                numbers_list.append(str(random_numbers))
                random_numbers = (random.randint(1, 7))

        clue_list_1 = numbers_list.count("1")       ## 重新获取列表中“X”的数量
        clue_list_2 = numbers_list.count("2")
        clue_list_3 = numbers_list.count("3")
        clue_list_4 = numbers_list.count("4")
        clue_list_5 = numbers_list.count("5")
        clue_list_6 = numbers_list.count("6")
        clue_list_7 = numbers_list.count("7")
        clue_lock_key = 0                           ## 重置key的数量
    hide screen menu_clues          ## 很重要!!不加这句会导致部分bug产生!!
    call screen Wall_of_clues       ## 再次启动

## 游戏开始
label start:
    call screen Wall_of_clues

    return

这些代码肉眼可见得可以优化,比如说用面向对象或者def什么的,但是优化这个代码的功夫都够我开启下一篇课题的学习了,我就不进行优化了,如果有能人异士能来优化一下那就最好不过了。
这个系列我之后应该还会更新,主要就是为了分享我在renpy进阶学习上的一些经验,希望能帮助到比我还萌新的萌新。
希望各位用得愉快!!(下一篇估计得半个月之后了)







clue_1

clue_1

clue_lock

clue_lock

clue_2

clue_2

clue_3

clue_3

clue_4

clue_4

clue_5

clue_5

clue_6

clue_6

clue_7

clue_7

评分

参与人数 1干货 +2 收起 理由
ZYKsslm + 2 有待加强

查看全部评分

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|RenPy中文空间 ( 苏ICP备17067825号|苏公网安备 32092302000068号 )

GMT+8, 2024-5-14 10:48 , Processed in 0.095131 second(s), 31 queries .

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表