Project1

标题: 关于K,先生的水果机 [打印本页]

作者: 卓越大白痴    时间: 2008-11-16 06:12
标题: 关于K,先生的水果机
http://rpg.blue/web/htm/news846.htm
这个是读取金钱
可不可以做到读取变量呢 怎莫做到呢
求解 谢谢 了

脚本在这里

  1. class Frute
  2.   def main
  3.     Audio.bgm_play("Audio/BGM/017-Theme06.mid",70,100)
  4.     @back = Sprite.new
  5.     @back.bitmap = Bitmap.new('Graphics/Pictures/back')
  6.     @light = Sprite.new
  7.     @light.bitmap = Bitmap.new('Graphics/Pictures/light')
  8.     @light.x = 276 ; @light.y = 89

  9.     @button = []
  10.    
  11.     @button[0] = Sprite.new
  12.     @button[0].bitmap = Bitmap.new('Graphics/Pictures/苹果')
  13.     @button[0].x = 451 ; @button[0].y = 210
  14.     @button[0].visible = false
  15.    
  16.     @button[1] = Sprite.new
  17.     @button[1].bitmap = Bitmap.new('Graphics/Pictures/西瓜')
  18.     @button[1].x = 487 ; @button[1].y = 210
  19.     @button[1].visible = false  
  20.    
  21.     @button[2] = Sprite.new
  22.     @button[2].bitmap = Bitmap.new('Graphics/Pictures/双星')
  23.     @button[2].x = 523 ; @button[2].y = 210
  24.     @button[2].visible = false  
  25.    
  26.     @button[3] = Sprite.new
  27.     @button[3].bitmap = Bitmap.new('Graphics/Pictures/双7')
  28.     @button[3].x = 559 ; @button[3].y = 210
  29.     @button[3].visible = false     
  30.    
  31.     @button[4] = Sprite.new
  32.     @button[4].bitmap = Bitmap.new('Graphics/Pictures/Bar')
  33.     @button[4].x = 595 ; @button[4].y = 210
  34.     @button[4].visible = false
  35.    
  36.     @button[5] = Sprite.new
  37.     @button[5].bitmap = Bitmap.new('Graphics/Pictures/铃铛')
  38.     @button[5].x = 469 ; @button[5].y = 311
  39.     @button[5].visible = false     
  40.    
  41.     @button[6] = Sprite.new
  42.     @button[6].bitmap = Bitmap.new('Graphics/Pictures/木瓜')
  43.     @button[6].x = 505 ; @button[6].y = 311
  44.     @button[6].visible = false
  45.    
  46.     @button[7] = Sprite.new
  47.     @button[7].bitmap = Bitmap.new('Graphics/Pictures/橘子')
  48.     @button[7].x = 541 ; @button[7].y = 311
  49.     @button[7].visible = false     
  50.    
  51.     @button[8] = Sprite.new
  52.     @button[8].bitmap = Bitmap.new('Graphics/Pictures/樱桃')
  53.     @button[8].x = 577 ; @button[8].y = 311
  54.     @button[8].visible = false
  55.    
  56.     $下注 = [0,0,0,0,0,0,0,0,0]
  57.     @位置 = [[276,89],[335,89],[360,89],[360,114],[360,173],[360,232],[360,291],[360,350],[360,375],
  58.     [335,375],[276,375],[217,375],[158,375],[99,375],[74,375],[74,350],[74,291],[74,232],
  59.     [74,173],[74,114],[74,89],[99,89],[158,89],[217,89]]
  60.    
  61.     @水果 = [1,9,7,2,9,0,1,9,8,6,9,4,1,9,7,3,9,0,1,9,8,6,5,10]
  62.     $分数 = 0
  63.    
  64.     @目前位置 = 0
  65.     @停止延迟 = 0
  66.     @转动中 = false
  67.     @结果计算 = false
  68.     @猜大小 = false
  69.     @bonus = Window_Bonus.new
  70.     @smbg = Window_Smbg.new
  71.     @smbg.visible = false
  72.     Graphics.transition
  73.     # 主循环
  74.     loop do
  75.       # 刷新游戏画面
  76.       Graphics.update
  77.       # 刷新输入情报
  78.       Input.update
  79.       # 刷新画面
  80.       update
  81.       # 如果画面切换的话就中断循环
  82.       if $scene != self
  83.         break
  84.       end
  85.     end
  86.     # 准备过渡
  87.     Graphics.freeze
  88.     # 释放活动块
  89.     @smbg.dispose if [email protected]?
  90.     @bonus.dispose
  91.     @back.dispose
  92.     @light.dispose
  93.     for i in 0..8
  94.       @button[i].dispose
  95.     end  
  96.   end
  97.   
  98.   
  99.   #--------------------------------------------------------------------------
  100.   # ● 刷新画面
  101.   #--------------------------------------------------------------------------
  102.   def update
  103.   mouse_x, mouse_y = Mouse.get_mouse_pos  
  104. # if Input.trigger?(Input::C)
  105. #   p mouse_x, mouse_y
  106. # end  
  107.   if @转动中
  108.   if @停止延迟 > 50
  109.   @停止延迟 -= 1  
  110.   @目前位置 += 1
  111.   @目前位置 = 0 if @目前位置 == @位置.size
  112.   @light.x = @位置[@目前位置][0] ; @light.y = @位置[@目前位置][1]
  113.   elsif @停止延迟 > 0
  114.   @停止延迟 -= 1
  115.   if @停止延迟 % 3 == 0
  116.   @目前位置 += 1
  117.   @目前位置 = 0 if @目前位置 == @位置.size
  118.   @light.x = @位置[@目前位置][0] ; @light.y = @位置[@目前位置][1]
  119.   end   
  120.   if @停止延迟 == 0
  121.   @转动中 = false
  122.   @结果计算 = true
  123.   return
  124.   end
  125.   end
  126.   end

  127.   if mouse_x > 451 and mouse_y > 210 and mouse_x < 481 and mouse_y < 234
  128.   @button[0].visible = true
  129.   else
  130.   @button[0].visible = false
  131.   end
  132.   if mouse_x > 487 and mouse_y > 210 and mouse_x < 517 and mouse_y < 234
  133.   @button[1].visible = true
  134.   else
  135.   @button[1].visible = false
  136.   end
  137.   if mouse_x > 523 and mouse_y > 210 and mouse_x < 553 and mouse_y < 234
  138.   @button[2].visible = true
  139.   else
  140.   @button[2].visible = false
  141.   end
  142.   if mouse_x > 559 and mouse_y > 210 and mouse_x < 589 and mouse_y < 234
  143.   @button[3].visible = true
  144.   else
  145.   @button[3].visible = false
  146.   end
  147.   if mouse_x > 595 and mouse_y > 210 and mouse_x < 625 and mouse_y < 234
  148.   @button[4].visible = true
  149.   else
  150.   @button[4].visible = false
  151.   end

  152.   if mouse_x > 469 and mouse_y > 311 and mouse_x < 499 and mouse_y < 335
  153.   @button[5].visible = true
  154.   else
  155.   @button[5].visible = false
  156.   end

  157.   if mouse_x > 505 and mouse_y > 311 and mouse_x < 535 and mouse_y < 335
  158.   @button[6].visible = true
  159.   else
  160.   @button[6].visible = false
  161.   end  
  162.   
  163.   if mouse_x > 541 and mouse_y > 311 and mouse_x < 571 and mouse_y < 335
  164.   @button[7].visible = true
  165.   else
  166.   @button[7].visible = false
  167.   end

  168.   if mouse_x > 577 and mouse_y > 311 and mouse_x < 607 and mouse_y < 335
  169.   @button[8].visible = true
  170.   else
  171.   @button[8].visible = false
  172.   end


  173.   
  174.   if Mouse.press?(Mouse::LEFT)
  175.   return if @停止延迟 != 0 and @转动中
  176.   if !@猜大小
  177.   @猜大小 = false ; @smbg.visible = false
  178.   if $分数 != 0
  179.     $game_party.gain_gold($分数)
  180.     $分数 = 0
  181.      @bonus.refresh
  182.    end

  183.   if mouse_x > 490 and mouse_y > 386 and mouse_x < 583 and mouse_y < 407
  184.     h = 0
  185.   for i in $下注  
  186.     h += i
  187.   end

  188.   if h == 0
  189.   if @记忆.nil?
  190.     return
  191.   else
  192.     j = 0
  193.   for i in @记忆  
  194.     j += i
  195.   end  
  196.      return if j > $game_party.gold
  197.     $下注 = @记忆.clone
  198.     $game_party.lose_gold(j)
  199.     @bonus.refresh
  200.   end
  201.   end

  202.   @转动中 = true
  203.   @停止延迟 = rand(50) + 100
  204.   end
  205.    
  206.    for i in [email protected]
  207.    if @button[i].visible
  208.      return if $下注[i] == 99 or $game_party.gold == 0
  209.      $下注[i] += 1
  210.      $game_party.lose_gold(1)
  211.      @bonus.refresh
  212.      break
  213.      end
  214.    end
  215. else
  216. if mouse_x > 460 and mouse_y > 420 and mouse_x < 523 and mouse_y < 450
  217.   @猜大小 = false
  218.   if $r < 5
  219.     $分数 *= 2
  220.     Audio.se_play("Audio/SE/056-Right02.ogg",100,100)
  221.   else
  222.     $分数 = 0
  223.     Audio.se_play("Audio/SE/058-Wrong02.ogg",100,100)
  224.   end
  225.   for i in 1..10
  226.     Graphics.update
  227.   end  
  228.   @bonus.refresh
  229.   @猜大小 = true if $分数 != 0
  230.   @smbg.visible = false if $分数 == 0
  231.   elsif mouse_x > 550 and mouse_y > 420 and mouse_x < 613 and mouse_y < 450
  232.   @猜大小 = false
  233.   if $r > 4
  234.     $分数 *= 2
  235.     Audio.se_play("Audio/SE/056-Right02.ogg",100,100)
  236.   else
  237.     $分数 = 0
  238.     Audio.se_play("Audio/SE/058-Wrong02.ogg",100,100)
  239.   end
  240.   for i in 1..20
  241.     Graphics.update
  242.   end  
  243.   @bonus.refresh
  244.   @猜大小 = true if $分数 != 0
  245.   @smbg.visible = false if $分数 == 0
  246. else
  247.    @猜大小 = false ; @smbg.visible = false
  248.   if $分数 != 0
  249.     $game_party.gain_gold($分数)
  250.     $分数 = 0
  251.      @bonus.refresh
  252.    end
  253.    
  254.   end
  255. end
  256. end


  257. if Mouse.press?(Mouse::RIGHT)
  258.   return if @停止延迟 != 0 and @转动中
  259.   k = false
  260.    for i in [email protected]
  261.    if @button[i].visible
  262.      k = true
  263.      return if $下注[i] == 0
  264.      $下注[i] -= 1
  265.      $game_party.gain_gold(1)
  266.      @bonus.refresh
  267.      break
  268.      end
  269.    end
  270.   if k == false
  271.   h = 0
  272.   for i in $下注  
  273.     h += i
  274.   end
  275.    $game_party.gain_gold(h) if h != 0
  276.    $game_party.gain_gold($分数) if $分数 != 0
  277.    Audio.bgm_stop
  278.    $scene = Scene_Map.new
  279. end
  280. end

  281.   if @结果计算
  282.   case @水果[@目前位置]
  283.   when 1
  284.     $分数 = $下注[0] * 5
  285.   when 2
  286.     $分数 = $下注[1] * 20   
  287.   when 3
  288.     $分数 = $下注[2] * 30     
  289.   when 4
  290.     $分数 = $下注[3] * 40     
  291.   when 5
  292.     $分数 = $下注[4] * 50
  293.   when 6
  294.     $分数 = $下注[5] * 20     
  295.   when 7
  296.     $分数 = $下注[6] * 15     
  297.   when 8
  298.     $分数 = $下注[7] * 10
  299.   when 9
  300.     $分数 = $下注[8] * 2
  301.   when 10
  302.     $分数 = $下注[4] * 100   
  303.   when 0
  304.     $分数 = 0
  305.     Audio.se_play("Audio/SE/061-Thunderclap01.ogg",100,100)
  306.   end
  307.   if $下注 == [0,0,0,0,0,0,0,0,0]
  308.     @记忆 = nil
  309.   else
  310.     @记忆 = $下注.clone
  311.   end
  312.   $下注 = [0,0,0,0,0,0,0,0,0]
  313.   @bonus.refresh
  314.   @结果计算 = false
  315.   if $分数 != 0
  316.   @猜大小 = true   
  317.   Audio.se_play("Audio/SE/006-System06.ogg",100,100)
  318.   end
  319.   end

  320.   if @猜大小
  321.     @smbg.visible = true
  322.     @smbg.refresh
  323.   end  

  324.    if Input.trigger?(Input::A)
  325.    p mouse_x, mouse_y
  326.   end

  327.   end
  328.   

  329.   
  330. end







  331. #==============================================================================
  332. # ■ Window_Gold
  333. #------------------------------------------------------------------------------
  334. #  显示金钱的窗口。
  335. #==============================================================================

  336. class Window_Bonus < Window_Base
  337.   #--------------------------------------------------------------------------
  338.   # ● 初始化窗口
  339.   #--------------------------------------------------------------------------
  340.   def initialize
  341.     super(440, 40, 200, 340)
  342.     self.contents = Bitmap.new(width - 32, height - 32)
  343.     self.opacity = 0
  344.     refresh
  345.   end
  346.   #--------------------------------------------------------------------------
  347.   # ● 刷新
  348.   #--------------------------------------------------------------------------
  349.   def refresh
  350.     self.contents.clear
  351.     cx = contents.text_size($data_system.words.gold).width
  352.     self.contents.font.color = normal_color
  353.     self.contents.draw_text(12, 8, 120-cx-2, 32, $game_party.gold.to_s, 2)
  354.     self.contents.draw_text(12, 44, 120-cx-2, 32, $分数.to_s, 2)
  355.     self.contents.draw_text(-4, 177, 32, 32, $下注[0].to_s, 1)   
  356.     self.contents.draw_text(32, 177, 32, 32, $下注[1].to_s, 1)
  357.     self.contents.draw_text(68, 177, 32, 32, $下注[2].to_s, 1)
  358.     self.contents.draw_text(104, 177, 32, 32, $下注[3].to_s, 1)
  359.     self.contents.draw_text(140, 177, 32, 32, $下注[4].to_s, 1)
  360.     self.contents.draw_text(14, 278, 32, 32, $下注[5].to_s, 1)
  361.     self.contents.draw_text(50, 278, 32, 32, $下注[6].to_s, 1)
  362.     self.contents.draw_text(86, 278, 32, 32, $下注[7].to_s, 1)
  363.     self.contents.draw_text(122, 278, 32, 32, $下注[8].to_s, 1)
  364.    
  365.    
  366.   end
  367. end


  368. class Window_Smbg < Window_Base
  369.   #--------------------------------------------------------------------------
  370.   # ● 初始化窗口
  371.   #--------------------------------------------------------------------------
  372.   def initialize
  373.     super(195, 300, 64, 64)
  374.     self.contents = Bitmap.new(width - 32, height - 32)
  375.     self.opacity = 0
  376.     refresh
  377.   end
  378.   #--------------------------------------------------------------------------
  379.   # ● 刷新
  380.   #--------------------------------------------------------------------------
  381.   def refresh
  382.     self.contents.clear
  383.     $r = rand(10)
  384.     self.contents.font.color = normal_color
  385.     self.contents.draw_text(0, 0, 32, 32, $r.to_s,1)  
  386.   end
  387. end











复制代码


[LINE]1,#dddddd[/LINE]版务信息:本贴由楼主自主结贴~
作者: 天圣的马甲    时间: 2008-11-16 17:10
$game_party.gold为金钱,改为$game_variables[变量编号],然后在增减金钱的$game_party.gain_gold和$game_party.lose_gold那里改为$game_variables[变量编号] += 或者 -= 就行了。 [LINE]1,#dddddd[/LINE]系统信息:本贴由楼主认可为正确答案,66RPG感谢您的热情解答~




欢迎光临 Project1 (https://rpg.blue/) Powered by Discuz! X3.1