马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?立即注册
×
本帖最后由 xccc 于 2022-1-9 15:05 编辑
抽奖功能,每次可以花100金币抽一次
功能实现方法是用 random 从奖池里随机抽取一个,然后放到背包里
问题:
点击一次抽奖会有两个物品跑到背包里,希望只有一个出现,不知道问题出在哪里,请大佬们帮忙
[RenPy] 纯文本查看 复制代码 init 0 python:
# 游戏内获得的金币
money = 1000
# 可以被抽奖抽到的东西
things = ["images/q1.png","images/q2.png","images/q3.png","images/q4.png"]
# 背包里获得的东西
bag_things = ["images/tem.png"]
###################################
# 背包
###################################
screen mybag():
fixed:
add "images/background.png"
textbutton "Voltar\n返回":
xalign 0.05 yalign 0.9
text_size 20
text_color "#000000"
text_hover_color "#4EEE94"
action Hide("mybag")
viewport:
xalign 0.5 yalign 0.5 xysize (500, 600)
scrollbars "vertical"
spacing 5
draggable True
mousewheel True
arrowkeys True
grid 3 10:
spacing 50
for i in range(0,30):
if i<len(bag_things):
imagebutton:
idle bag_things[i]
hover bag_things[i]
else:
null
###################################
# 商店
###################################
screen shop():
fixed:
add "images/background.png"
textbutton "Voltar\n返回":
xalign 0.05 yalign 0.9
text_size 20
text_color "#000000"
text_hover_color "#4EEE94"
action Hide("shop")
fixed:
xalign 0.5 yalign 0.5
xysize(700,500)
vbox:
add "images/tem.png"
textbutton "抽奖":
text_color "#000000"
text_hover_color "#4EEE94"
action Show('tip')
screen tip():
modal True
frame:
xsize 300 ysize 300
xalign 0.5 yalign 0.5
vbox:
if money >= 100 and len(things)>=1:
text"你将花100块抽奖"
hbox:
textbutton "确定":
text_color "#000000"
text_hover_color "#4EEE94"
action [SetVariable('money',money-100),Show('jiang'),Hide('tip')]
elif money >= 100 and len(things)==0:
text "没有东西可以抽奖啦"
textbutton "确定":
text_color "#000000"
text_hover_color "#4EEE94"
action Hide("tip")
else:
text "钱不够"
textbutton "确定":
text_color "#000000"
text_hover_color "#4EEE94"
action Hide("tip")
screen jiang():
modal True
$ choose = renpy.random.choice(things)
$ things.remove(choose)
$ bag_things.append(choose)
frame:
xsize 300 ysize 300
xalign 0.5 yalign 0.5
vbox:
text "恭喜你获得了:"
add choose
textbutton "确定":
text_color "#000000"
text_hover_color "#4EEE94"
action Hide('jiang')
|