=begin
===============================================================================
猜数字 By喵呜喵5
===============================================================================
【说明】
简单的猜数字迷你游戏
在事件中的脚本指令里输入
caishuzi(允许玩家猜测的次数)
即可进入猜数字界面
你也可以输入
caishuzi(允许玩家猜测的次数,正确答案)
来定制猜数字的答案
其中正确答案必须为由1到9组成的4位数,不能有重复的数字,否则将被视为无效
因为只是随便写的,目前可供定制的内容并不多
如果要问这个脚本有什么实际意义…………脱衣猜数字?(被踹)
=end
$m5script = {} if $m5script.nil?
$m5script["M5_Mini_Num"] = true
module M5_Mini_Num
#==============================================================================
# 设定部分
#==============================================================================
RESULT = 1
#用来获取迷你游戏最终结果的开关ID,游戏胜利则开关开启,否则开关关闭
#不需要的话,填写0就好了
TIMES = 1
#用来获取迷你游戏最终结果的变量ID,游戏结束时该ID的值变为剩余的猜测次数
#不需要的话,填写0就好了
ME1 = "Audio/ME/Fanfare1"
ME2 = "Audio/ME/Gag"
SE1 = "Audio/SE/Applause1"
SE2 = "Audio/SE/Crow"
#游戏结束时播放的音效和声效,1表示胜利时,2表示失败时
#==============================================================================
# 脚本部分
#==============================================================================
end
class Window_M5_Mini_Num1 < Window_Base
def initialize
super(0, 0, Graphics.width,Graphics.height/5)
@index = 0
@digits_max = 4
@number = [0] * @digits_max
@handler = {}
create_contents
refresh
end
def start
@index = 0
@number = [0] * @digits_max
create_contents
refresh
end
def cursor_right
@index = (@index + 1) % @digits_max
end
def cursor_left
@index = (@index + @digits_max - 1) % @digits_max
end
def update
super
return unless active
process_cursor_move
process_digit_change
process_handling
update_cursor
end
def process_cursor_move
last_index = @index
cursor_right if Input.repeat?(:RIGHT)
cursor_left if Input.repeat?(:LEFT)
Sound.play_cursor if @index != last_index
end
def process_digit_change
if Input.repeat?(:UP) || Input.repeat?(:DOWN)
Sound.play_cursor
n = @number[@index]
if Input.repeat?(:UP)
else
end
@number[@index] = n
refresh
end
end
def process_handling
return process_ok if Input.trigger?(:C)
return process_cancel if Input.trigger?(:B)
return process_exit if Input.trigger?(:A)
end
def process_ok
if @number.include?(0)
Sound.play_buzzer
else
Sound.play_ok
call_handler(:ok)
start
end
end
def process_exit
Sound.play_cancel
call_handler(:lose)
end
def process_cancel
Sound.play_cancel
start
end
def item_rect(index)
width = (self.width - @hintx - 10 - standard_padding * 2)/@digits_max
x = @hintx + 10 + index * width
y = self.height / 2 - line_height - standard_padding/2
Rect.new(x, y, width, line_height)
end
def refresh
contents.clear
@hintx = text_size("输入数字:").width
change_color(system_color)
draw_text(10,self.height / 2 - line_height - standard_padding/2,
@hintx * 2,line_height,"输入数字:")
change_color(normal_color)
@digits_max.times do |i|
rect = item_rect(i)
rect.x += 1
text = @number[i] == 0 ? "*" : @number[i]
draw_text(rect, text, 1)
end
y = self.height - standard_padding*1.5 - line_height
make_font_smaller
draw_text(0,y,self.width-line_height - standard_padding,line_height,
"Z确定,X重置,SHIFT认输", 2)
reset_font_settings
end
def update_cursor
cursor_rect.set(item_rect(@index))
end
def set_handler(symbol, method)
@handler[symbol] = method
end
def call_handler(symbol)
@handler[symbol].call
end
def result(answer)
result1 = ""
result2 = result3 = 0
@digits_max.times {|i| result3 += 1 if answer.include?(@number[i])}
@digits_max.times {|i| result2 += 1 if answer[i] == @number[i]}
call_handler(:win) if result2 == @digits_max
result3 -= result2
@digits_max.times {|i| result1 += "#{@number[i]}"}
@result_window.draw_result(result1,result2,result3)
end
def result_window=(result_window)
@result_window = result_window
end
end
class Window_M5_Mini_Num2 < Window_Base
def initialize(y,times)
super(0, y, Graphics.width,line_height+standard_padding*2)
create_contents
refresh(times)
end
def refresh(times)
contents.clear
color = normal_color
color = crisis_color if times < 4
color = knockout_color if times < 1
change_color(color)
draw_text(0,0,self.width-standard_padding*2,self.height-standard_padding*2,
"剩余次数:#{times}次", 1)
end
end
class Window_M5_Mini_Num3 < Window_Base
def initialize(y)
super(0,y, Graphics.width,Graphics.height - y)
create_contents
refresh
@index = 1
end
def draw_result(result1,result2,result3)
color = @index % 2 == 1 ? crisis_color : normal_color
change_color(color)
y = @index * line_height
draw_text(0,y,self.width-standard_padding*2,line_height,"#{result1}")
draw_text(0,y,self.width-standard_padding*3,line_height,"#{result2}",1)
draw_text(0,y,self.width-standard_padding*2,line_height,"#{result3}",2)
@index += 1
end
def refresh
contents.clear
change_color(system_color)
draw_text(0,0,self.width-standard_padding*2,line_height,"数字")
draw_text(0,0,self.width-standard_padding*3,line_height,"完全正确",1)
draw_text(0,0,self.width-standard_padding*2,line_height,"只有数字正确",2)
end
end
class Window_M5_Mini_Num4 < Window_Base
include M5_Mini_Num
def initialize
super(0, 0,Graphics.width,fitting_height(1))
update_placement
create_contents
self.openness = 0
end
def update_placement
self.x = (Graphics.width - self.width)/2
self.y = (Graphics.height - self.height)/2
end
def draw_reslut(content,answer=1234)
contents.clear
change_color(normal_color)
draw_text(0,0,self.width-standard_padding*2,self.height-standard_padding*2,
"恭喜你,猜对了!", 1) if content == 0
draw_text(0,0,self.width-standard_padding*2,self.height-standard_padding*2,
"遗憾!正确答案是#{answer}!", 1) if content == 1
open
me_name = content == 0 ? ME1 : ME2
se_name = content == 0 ? SE1 : SE2
Audio.me_play(me_name)
Audio.se_play(se_name)
update until self.openness == 255
loop do
Graphics.update
Input.update
break if Input.repeat?(:C)
end
end
end
class Scene_M5_Mini_Num < Scene_Base
include M5_Mini_Num
def start
super
create_background
create_command_window
end
def prepare(times,answer)
@times = times
@max = 4
@answer = [[answer/1000,9].min,answer%1000/100,answer%100/10,answer%10]
@answer.uniq!
if @answer.size < @max || @answer.include?(0)
@answer = [1,2,3,4,5,6,7,8,9].sample(@max)
end
p @answer
end
def create_command_window
@command_window = Window_M5_Mini_Num1.new
@hint_window = Window_M5_Mini_Num2.new(@command_window.height,@times)
@result_window = Window_M5_Mini_Num3.new(@hint_window.height + @hint_window.y)
@last_window = Window_M5_Mini_Num4.new
@command_window.result_window = @result_window
@command_window.set_handler(:ok, method(:judge))
@command_window.set_handler(:win, method(:win))
@command_window.set_handler(:lose, method(:lose))
end
def judge
@times -= 1
@hint_window.refresh(@times)
@command_window.result(@answer)
lose if @times <= 0
end
def win
@last_window.draw_reslut(0)
$game_switches[RESULT] = true
$game_variables[TIMES] = 10 - @times
@times = 10
return_scene
end
def lose
answer = ""
@answer.size.times {|i| answer += "#{@answer[i]}"}
@last_window.draw_reslut(1,answer)
$game_switches[RESULT] = false
$game_variables[TIMES] = 0
return_scene
end
def terminate
super
dispose_background
end
def create_background
@background_sprite = Sprite.new
@background_sprite.bitmap = SceneManager.background_bitmap
@background_sprite.color.set(16, 16, 16, 128)
end
def dispose_background
@background_sprite.dispose
end
end
class Game_Interpreter
def caishuzi(times = 10,answer = 0)
SceneManager.call(Scene_M5_Mini_Num)
SceneManager.scene.prepare([[1,times].max,10].min,answer)
end
end