RenPy中文空间

 找回密码
 立即注册

QQ登录

只需一步,快速开始

查看: 275|回复: 1

[转载] 发一个renpy游戏里的游戏 对对碰 卡牌代码

[复制链接]
发表于 2018-5-16 15:27:46 | 显示全部楼层 |阅读模式

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

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

x
[RenPy] 纯文本查看 复制代码
init python:
max_c = 2
card_size = 48

wait = 0.5
img_mode = True
values_list = []
memoriapng = []
all_cardstm = []



for fn in renpy.list_files():
if fn.startswith("images/card_") and fn.endswith((".png")):
name = fn[12:-4]
renpy.image("card " + name, fn)
if name != "empty" and name != "back":
memoriapng.append(str(name))

#调用名字为card_*.png图片 背面是card_back.png








def cards_init():
all_cardstm = list(memoriapng)
global values_list
values_list = []
while len(values_list) + max_c <= ww * hh:
current_card = renpy.random.choice(all_cardstm)
all_cardstm.remove(current_card)
for i in range(0, max_c):
values_list.append(current_card)
renpy.random.shuffle(values_list)
while len(values_list) < ww * hh:
values_list.append('empty')

#随机取数 在文末有数组 代表几行几列
screen memo_scr:

timer 1.0 action If (memo_timer > 1, SetVariable("memo_timer", memo_timer - 1), Jump("memo_game_lose") ) repeat True


#规定个时间


grid ww hh:
align (.5, .5)




for card in cards_list:
button:
left_padding 0
right_padding 0
top_padding 0
bottom_padding 0
xmaximum 128
ymaximum 128
background None
if card["c_value"] == 'empty':
if img_mode:
add "card empty"
else:
text " " size card_size
else:
if card["c_chosen"]:
if img_mode:
add "card " + card["c_value"]
else:
text card["c_value"] size card_size
else:
if img_mode:
add "card back"
else:
text "#" size card_size

action If ( (card["c_chosen"] or not can_click), None, [SetDict(cards_list[card["c_number"]], "c_chosen", True), Return(card["c_number"]) ] )
text str(memo_timer) xalign .5 yalign 0.0 size card_size

screen finish_learning:
imagebutton align (.99,.98):
idle "images/Buttons/arrow_exit.png"
hover (im.MatrixColor("images/Buttons/arrow_exit.png",im.matrix.brightness(0.15)))
action [ Hide("finish_learning"), Jump("memo_game_lose")]

label memoria_game:

$ cards_init()
$ cards_list = []
python:
for i in range (0, len(values_list) ):
if values_list[i] == 'empty':
cards_list.append ( {"c_number":i, "c_value": values_list[i], "c_chosen":True} )
else:
cards_list.append ( {"c_number":i, "c_value": values_list[i], "c_chosen":False} )
$ memo_timer = max_time

show screen memo_scr

label memo_game_loop:
$ can_click = True
$ turned_cards_numbers = []
$ turned_cards_values = []
$ turns_left = max_c
label turns_loop:
if turns_left > 0:
$ result = ui.interact()
$ memo_timer = memo_timer
$ turned_cards_numbers.append (cards_list[result]["c_number"])
$ turned_cards_values.append (cards_list[result]["c_value"])
$ turns_left -= 1
jump turns_loop

$ can_click = False
if turned_cards_values.count(turned_cards_values[0]) != len(turned_cards_values):
$ renpy.pause (wait, hard = True)
python:
for i in range (0, len(turned_cards_numbers) ):
cards_list[turned_cards_numbers[i]]["c_chosen"] = False
else:
$ renpy.pause (wait, hard = True)
python:
for i in range (0, len(turned_cards_numbers) ):
cards_list[turned_cards_numbers[i]]["c_value"] = 'empty'
for j in cards_list:
if j["c_chosen"] == False:
renpy.jump ("memo_game_loop")
renpy.jump ("memo_game_win")
jump memo_game_loop


label memo_game_lose:
hide screen memo_scr
hide screen finish_learning
$ renpy.pause (0.1, hard = True)
if studytoday:
ggi "什么破牌."
else:
ggi "不玩了"
return


#输牌的结果

label memo_game_win:
hide screen memo_scr
hide screen finish_learning
$ renpy.pause (0.1, hard = True)
ggi "我是赌圣"
redtitle "Intellect +1 {w=2.0}{nw}" with dissolve
$ intellect += 1
$ studytoday = True
$ tired = True
if intellect > 19:
if _("Develop intellect up to 20") in spisok:
$ spisok.remove(_("Develop intellect up to 20"))
tip "[ftsk!t]Develop intellect up to 20 [ftskf!t]" with dissolve
return
#赢牌得到一些奖励和数值

label memoria:

$ renpy.free_memory()
scene lib_study with Fade(.5,0,2)
if studytoday:
ggi "努力了"
elif tired:
ggi "没力气了"
else:
ggi "再来一次"
scene lib_study1 with dissolve
if firststudy:
tip "找到相同的卡牌" with dissolve
$ firststudy = False
hide screen button_overlay
redtitle "玩牌时间!!" with dissolve

$ wwl = [4, 5, 6, 5, 6, 5, 6, 5, 6, 5, 4, 5, 6, 5, 6, 5, 6, 5, 6, 5, 6, 5,]
$ hhl = [4, 4, 4, 5, 4, 5, 5, 6, 5, 6, 7, 5, 6, 7, 6, 7, 7, 7, 5, 4,]

#$ wwl = [4, 5, 6, 5, 7, 6, 8, 7, 6, 8, 7, 9, 8, 7, 10, 9, 8, 10, 9, 10, 10]
#$ hhl = [4, 4, 4, 5, 4, 5, 4, 5, 6, 5, 6, 5, 6, 7, 5, 6, 7, 6, 7, 7, 7]

$ ww, hh = wwl[intellect - 1], hhl[intellect - 1]
if studytoday or tired:
$ max_time = int((ww * hh * 4)/1.5)
else:
$ max_time = int(ww * hh * 4)
show screen finish_learning
call memoria_game from _call_memoria_game
show screen button_overlay
$ ofade = True
$ renpy.free_memory()
return


发表于 2018-5-17 11:27:05 | 显示全部楼层
代码没有缩进唉,推荐看下这里:关于发帖上传Ren'Py代码,空格显示问题说明。
回复 支持 反对

使用道具 举报

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

本版积分规则

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

GMT+8, 2018-12-19 07:22 , Processed in 0.027029 second(s), 20 queries , File On.

Powered by Discuz! X3.4

© 2001-2017 Comsenz Inc.

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