注册会员 登录
Project1 返回首页

喵呜喵5的树洞 https://rpg.blue/?291206 [收藏] [复制] [分享] [RSS]

日志

【脚本】猜数字

热度 10已有 2411 次阅读2014-6-2 15:37 |个人分类:脚本

=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)
        n = (n + 1) % 10 until n != 0 && [email protected]?(n)
      else
        n = (n + 9) % 10 until n != 0 && [email protected]?(n)
      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
1

鸡蛋
1

鲜花

刚表态过的朋友 (2 人)

发表评论 评论 (27 个评论)

回复 lanxuanbaby 2015-7-6 20:44
喵呜喵5: 结束猜数字游戏后,退出时开关如果是关闭就代表猜错了

什么叫设置多个猜数字?
就是有多个猜数字的游戏,每个游戏的数字是固定的,但是不一样,这样。
但是不猜数字的话那个开关本来就是关闭的啊。
回复 喵呜喵5 2015-7-6 20:50
lanxuanbaby: 就是有多个猜数字的游戏,每个游戏的数字是固定的,但是不一样,这样。
但是不猜数字的话那个开关本来就是关闭的啊。 ...
一旦退出猜数字界面时那个开关是关闭的,说明玩家【必定失败了】,没进入猜数字界面时那个开关又不会变,在每次猜数字结束后判断一次这个开关不就好了?
你要制定多个猜数字的话看脚本说明写的很明白了啊:输入 caishuzi(允许玩家猜测的次数,正确答案) 即可,你在事件1把正确答案设置为1234,在事件2把正确答案设置为5678,在事件3把正确答案设置为9012,不就是多个了
回复 lanxuanbaby 2015-7-7 00:01
喵呜喵5: 一旦退出猜数字界面时那个开关是关闭的,说明玩家【必定失败了】,没进入猜数字界面时那个开关又不会变,在每次猜数字结束后判断一次这个开关不就好了?
你要制 ...
不好意思啊,打扰了那么久~谢谢喵大的耐心解答~~
回复 是〢昔 2016-6-22 02:47
感觉遇到一个BUG,在同一事件进行第一次猜数字后,将对应开关关闭,进行第2到第n次成功后对应开关似乎不会打开。如图,第一次猜数字后会显示“胜利”字样,但第二次猜数字成功后仍然会显示“失败”字样。http://pan.baidu.com/s/1sl27msl
回复 喵呜喵5 2016-6-22 09:02
是〢昔: 感觉遇到一个BUG,在同一事件进行第一次猜数字后,将对应开关关闭,进行第2到第n次成功后对应开关似乎不会打开。如图,第一次猜数字后会显示“胜利”字样,但第 ...
关闭开关后等待一帧,由于RM本身事件执行的机制,你那个开关关闭的指令如果没加等待一帧的话,会在猜数字结束之后才执行(而不是在猜数字之前执行)

实际上,你不需要手动去关闭该开关,猜数字失败时该开关会自动开启或关闭
回复 是〢昔 2016-6-22 14:23
喵呜喵5: 关闭开关后等待一帧,由于RM本身事件执行的机制,你那个开关关闭的指令如果没加等待一帧的话,会在猜数字结束之后才执行(而不是在猜数字之前执行)

实际上,你 ...
谢谢!
回复 是〢昔 2016-6-22 14:23
喵呜喵5: 关闭开关后等待一帧,由于RM本身事件执行的机制,你那个开关关闭的指令如果没加等待一帧的话,会在猜数字结束之后才执行(而不是在猜数字之前执行)

实际上,你 ...
谢谢!
12

facelist doodle 涂鸦笔

您需要登录后才可以评论 登录 | 注册会员

拿上你的纸笔,建造一个属于你的梦想世界,加入吧。
 注册会员
找回密码

站长信箱:[email protected]|手机版|小黑屋|无图版|Project1游戏制作

GMT+8, 2024-5-15 11:21

Powered by Discuz! X3.1

© 2001-2013 Comsenz Inc.

返回顶部