注册会员 登录
Project1 返回首页

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

日志

【脚本】猜数字

热度 10已有 2396 次阅读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 个评论)

回复 david_ng223 2014-6-3 17:12
為什麼我在事件中的脚本指令里输入caishuzi(20).測試遊戲時,允许玩家猜测的次数是10的???
回复 david_ng223 2014-6-3 17:13
caishuzi(20,1234)也是一樣的情況
回复 喵呜喵5 2014-6-3 18:05
david_ng223: caishuzi(20,1234)也是一樣的情況
因为最大就支持到10次,超过10次以后我还没有想好下方的记录窗口要怎么显示
回复 david_ng223 2014-6-3 23:06
喵呜喵5: 因为最大就支持到10次,超过10次以后我还没有想好下方的记录窗口要怎么显示
剛剛為此看了看wiki,有以下這段:"根據最嚴謹的計算,任何數字可以在7次之內猜出。而有些地方把次數限制為6次或更少,則會導致有些數可能猜不出來。而有些地方考慮到人的邏輯思維難以達到計算機的那麼嚴謹,故設置為8次甚至10次。"
好吧............我承認我猜10幾次也猜不中......0______0......
所以請您把這問題當作我沒問過.....麻煩了您,抱歉.
回复 喵呜喵5 2014-6-3 23:47
david_ng223: 剛剛為此看了看wiki,有以下這段:&quot;根據最嚴謹的計算,任何數字可以在7次之內猜出。而有些地方把次數限制為6次或更少,則會導致有些數可能猜不出來。而有些地 ...
其实多玩几遍摸出窍门的话就好猜了(∩_∩),之后我再加一个失败后公布答案的功能吧
回复 喵呜喵5 2014-6-5 14:00
david_ng223: 剛剛為此看了看wiki,有以下這段:&quot;根據最嚴謹的計算,任何數字可以在7次之內猜出。而有些地方把次數限制為6次或更少,則會導致有些數可能猜不出來。而有些地 ...
猜数字和猜数字解答器脚本都进行了更新,简化了一些算法,修正了几处BUG,增加了一些功能
回复 david_ng223 2014-6-5 14:08
喵呜喵5: 猜数字和猜数字解答器脚本都进行了更新,简化了一些算法,修正了几处BUG,增加了一些功能
好的,謝謝您~
回复 lanxuanbaby 2015-7-6 12:56
请问怎么设置猜对和猜错出现的情况呢?
回复 喵呜喵5 2015-7-6 13:28
lanxuanbaby: 请问怎么设置猜对和猜错出现的情况呢?
你想设置成什么样?
回复 lanxuanbaby 2015-7-6 16:41
喵呜喵5: 你想设置成什么样?
嗯,就是例如猜对了就打开门,猜错了就进入战斗这样。
回复 喵呜喵5 2015-7-6 16:59
lanxuanbaby: 嗯,就是例如猜对了就打开门,猜错了就进入战斗这样。
脚本设定部分的第一个设定
回复 lanxuanbaby 2015-7-6 17:36
喵呜喵5: 脚本设定部分的第一个设定
呃,具体要怎么设定呢~~0v0
回复 喵呜喵5 2015-7-6 17:41
lanxuanbaby: 呃,具体要怎么设定呢~~0v0
条件分支 如果开关打开 如果开关关闭
回复 lanxuanbaby 2015-7-6 17:56
喵呜喵5: 条件分支 如果开关打开 如果开关关闭
再打扰下,条件分支之后的开关在哪里设置呢?
回复 喵呜喵5 2015-7-6 18:05
lanxuanbaby: 再打扰下,条件分支之后的开关在哪里设置呢?
假设你在这个脚本设置部分设置的开关为1,那么猜数字成功后1号开关会自动打开,失败后1号开关会自动关闭,接下来你要做的只是判断1号开关是开启还是关闭而已,这和脚本完全没关系,是非常简单的事件操作
回复 lanxuanbaby 2015-7-6 18:18
喵呜喵5: 假设你在这个脚本设置部分设置的开关为1,那么猜数字成功后1号开关会自动打开,失败后1号开关会自动关闭,接下来你要做的只是判断1号开关是开启还是关闭而已,这 ...
还是不太明白呢···········可以发个范例工程吗?拜托了0v0
回复 喵呜喵5 2015-7-6 18:30
lanxuanbaby: 还是不太明白呢···········可以发个范例工程吗?拜托了0v0
自己看图 http://r.loli.io/NZV32u.png
回复 lanxuanbaby 2015-7-6 18:34
喵呜喵5: 自己看图 http://r.loli.io/NZV32u.png
瞬间懂了。谢谢喵大~~~!
回复 lanxuanbaby 2015-7-6 18:41
喵呜喵5: 自己看图 http://r.loli.io/NZV32u.png
呃·····但是猜错了的惩罚怎么弄呢?
还有如果设置多个猜数字小游戏怎么设置?
不好意思啊~0v0
回复 喵呜喵5 2015-7-6 19:30
lanxuanbaby: 呃·····但是猜错了的惩罚怎么弄呢?
还有如果设置多个猜数字小游戏怎么设置?
不好意思啊~0v0
结束猜数字游戏后,退出时开关如果是关闭就代表猜错了

什么叫设置多个猜数字?
12下一页

facelist doodle 涂鸦笔

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

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

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

GMT+8, 2024-4-29 13:41

Powered by Discuz! X3.1

© 2001-2013 Comsenz Inc.

返回顶部