#==============================================================================
# ■ Roulette vol.1.02 (分割定義2)
#------------------------------------------------------------------------------
# 11/10/04
#==============================================================================
class Scene_Roulette
  include HIDE_ROULETTE
  #--------------------------------------------------------------------------
  # ■ オブジェクト初期化
  #--------------------------------------------------------------------------
  def initialize
    game_reset?
    # □マップ BGM を記憶し、BGM を停止
    $game_temp.map_bgm = $game_system.playing_bgm
    $game_system.bgm_stop
    # □ルーレット BGM を演奏
    $game_system.bgm_play(RPG::AudioFile.new(HIDE_ROULETTE::BGM))
  end
  #--------------------------------------------------------------------------
  # ■ ルーレットの初期化
  #--------------------------------------------------------------------------
  def game_reset?
    # □アニメーションフラグをOFF
    @move = false
    # □ゲーム実行中フラグをOFF
    @playing = false
  end
  #--------------------------------------------------------------------------
  # ■ メイン処理
  #--------------------------------------------------------------------------
  def main
    t = $game_temp.roulette_type
    @coin_rate = HIDE_ROULETTE::COIN[t]
    if $game_party.roulette_average[t] == nil
      $game_party.roulette_average[t] = [0]*38
    end
    if $game_party.roulette_draw[t] == nil
      $game_party.roulette_draw[t] = false
    end
    #…………………………………………………………………………………………………
    # ■bet画像を取得/画像からカラーを取得
    #…………………………………………………………………………………………………
    bet_pic = RPG::Cache.windowskin(HIDE_ROULETTE::BET)
    @select_colors = [] ; cy = 0
    for i in 0..7
      @select_colors[i] = bet_pic.get_pixel(224+1+18,49+cy)
      cy += 3
    end
    #…………………………………………………………………………………………………
    # ■ヘルプウィンドウを作成
    #…………………………………………………………………………………………………
    @help_window = []
    for i in 0..1
      @help_window[i] = Window_Help.new
      @help_window[i].opacity = 0
      @help_window[i].windowskin = Bitmap.new(1,1)
      @help_window[i].y = 480-128
      @help_window[i].x = 16
    end
    #…………………………………………………………………………………………………
    # ■ルーレットウィンドウ背景を作成
    #…………………………………………………………………………………………………
    @roulette_window_back = Window_Coin_Game_back.new(HIDE_ROULETTE::BACK,"",nil,408,406)
    #…………………………………………………………………………………………………
    # ■ルーレットウィンドウを作成
    #…………………………………………………………………………………………………
    @roulette_window = Window_Roulette.new
    #…………………………………………………………………………………………………
    # ■bet x36ウィンドウを作成
    #…………………………………………………………………………………………………
    x = 452-16 ; y = 37-16 ; w = 187+32 ; h = 32*16 ; cw = 63 ; ch = 32
    @bet_table_window = []
    @bet_table_window[0] = Picture_Selectable.new(x,y,w,h,36,3,cw,ch)
    @bet_table_window[0].help_window = @help_window[1]
    #…………………………………………………………………………………………………
    # ■bet x36(0,00)ウィンドウを作成
    #…………………………………………………………………………………………………
    @bet_table_zero = []
    @bet_table_zero[0] = Picture_Selectable.new(x,4-16,w,66,2,2,92,34,0)
    @bet_table_zero[0].help_window = @help_window[1]
    #…………………………………………………………………………………………………
    # ■bet x18(0-00) bet x12(1-0-2,0-2-00,2-00-3)ウィンドウを作成
    #…………………………………………………………………………………………………
    @bet_table_zero[1] = Picture_Selectable.new(x,4-16,w,66+30,1,1,92*2,34+30,0,0,true)
    @bet_table_zero[1].help_window = @help_window[1]
    @zero_type = nil
    #…………………………………………………………………………………………………
    # ■bet x18(縦2=33)ウィンドウを作成
    #…………………………………………………………………………………………………
    @bet_table_rows = []
    @bet_table_rows[0] = Picture_Selectable.new(x,y,w,h,33,3,cw,60,2,30,true)
    @bet_table_rows[0].help_window = @help_window[1]
    #…………………………………………………………………………………………………
    # ■bet x18(横2=24)ウィンドウを作成
    #…………………………………………………………………………………………………
    @bet_table_window[1] = Picture_Selectable.new(x,y,w+24,h,24,2,122,32,60,2,true)
    @bet_table_window[1].help_window = @help_window[1]
    #…………………………………………………………………………………………………
    # ■bet x12(横3=12)ウィンドウを作成
    #…………………………………………………………………………………………………
    @bet_table_window[2] = Picture_Selectable.new(x,y,w,h,12,1,183,32,2,2,true)
    @bet_table_window[2].help_window = @help_window[1]
    #…………………………………………………………………………………………………
    # ■bet x9(4マス)ウィンドウを作成
    #…………………………………………………………………………………………………
    @bet_table_window[3] = Picture_Selectable.new(x,y,w+24,h,22,2,122,60,60,30,true)
    @bet_table_window[3].help_window = @help_window[1]
    #…………………………………………………………………………………………………
    # ■bet x6(6マス)ウィンドウを作成
    #…………………………………………………………………………………………………
    @bet_table_window[4] = Picture_Selectable.new(x,y,w,h,11,1,183,60,2,30,true)
    @bet_table_window[4].help_window = @help_window[1]
    #…………………………………………………………………………………………………
    # ■bet x3(12マス)ウィンドウを作成
    #…………………………………………………………………………………………………
    @bet_table_window[5] = Picture_Selectable.new(x,y,w,h,3,1,183,60*2,2,0,true)
    @bet_table_window[5].help_window = @help_window[1]
    #…………………………………………………………………………………………………
    # ■bet x3(１列12箇所)ウィンドウを作成
    #…………………………………………………………………………………………………
    @bet_table_rows[1] = Picture_Selectable.new(x,y,w,h,3,3,63,60*6,2,0,true)
    @bet_table_rows[1].help_window = @help_window[1]
    #…………………………………………………………………………………………………
    # ■bet x2(18マス)ウィンドウを作成
    #…………………………………………………………………………………………………
    @bet_table_window[6] = Picture_Selectable.new(x,y,w,h,2,1,183,60*3,2,0,true)
    @bet_table_window[6].help_window = @help_window[1]
    #…………………………………………………………………………………………………
    # ■bet x2(32マス)ウィンドウを作成
    #…………………………………………………………………………………………………
    @bet_table_rows[2] = Picture_Selectable.new(x,y,w,h,1,1,183,60*6,0,0,true)
    @bet_table_rows[2].help_window = @help_window[1]
    #…………………………………………………………………………………………………
    # ■当り演出ウィンドウを作成
    #…………………………………………………………………………………………………
    @hit_window = Window_Roulette_hit.new
    #…………………………………………………………………………………………………
    # ■betウィンドウ枠/文字を作成
    #…………………………………………………………………………………………………
    @mask_window = []
    @mask_window[0] = Sprite.new(Viewport.new(0,0,640,480))
    @mask_window[0].bitmap = RPG::Cache.windowskin(HIDE_ROULETTE::TOP)
    @mask_window[0].viewport.z = @bet_table_window[0].z+2
    #…………………………………………………………………………………………………
    # ■マスクウィンドウを作成 0=EVEN(偶数) 1=RED 2=BRACK 3=ODD(奇数)
    #…………………………………………………………………………………………………
    @mask_window[1] = Sprite.new(Viewport.new(0,0,640,480))
    @mask_window[1].bitmap = Bitmap.new(640,480)
    @mask_window[1].viewport.z = @bet_table_window[0].z+2
    #…………………………………………………………………………………………………
    # ■文字装飾を取得
    #…………………………………………………………………………………………………
    s_font = HIDE_ROULETTE::S_FONT ; h_font = HIDE_ROULETTE::H_FONT
    c_font = HIDE_ROULETTE::C_FONT ; b_font = HIDE_ROULETTE::T_FONT
    #…………………………………………………………………………………………………
    # ■コイン数値ウィンドウを作成
    #…………………………………………………………………………………………………
    @coin_window = Window_digits_number.new(500,430,100,$game_party.coin,10,10,c_font)
    #…………………………………………………………………………………………………
    # ■BETコイン数値ウィンドウを作成
    #…………………………………………………………………………………………………
    @bet_coin = 0
    @total_bet_coin_window = Window_digits_number.new(172,325,100,@bet_coin,10,10,c_font)
    #…………………………………………………………………………………………………
    # ■配当コイン数値ウィンドウを作成
    #…………………………………………………………………………………………………
    @payout = 0
    @payout_coin_window = Window_digits_number.new(172-110,325+60,100,@payout,10,10,c_font)
    #…………………………………………………………………………………………………
    # ■テーブル文字(横向き)を描画
    #…………………………………………………………………………………………………
    @mask_window[0].bitmap.draw_cache_text(471,7,57,32,"0",1,b_font)
    @mask_window[0].bitmap.draw_cache_text(471+92,7,57,32,"00",1,b_font)
    # □Bet位置(n倍)のコイン描画481+3+91
    for i in 0..6
      @mask_window[0].bitmap.blt(456+i*27,431,bet_pic,Rect.new(7*32+(i%2)*16,72+(i/2)*7,16,7))
    end
    x = 454 ; y = 37 ; n = 0
    for i in 0...36
      @mask_window[0].bitmap.draw_cache_text(x+61*(i%3),y+30*(i/3),59,32,(i+1).to_s,1,b_font)
    end
    b_font.size = 22
    for i in 0..2
      @mask_window[0].bitmap.draw_cache_text(x+60*i,y+30*12,59,32,"2 to 1",1,b_font)
    end
    #…………………………………………………………………………………………………
    # ■ゲーム開始選択ウィンドウを作成
    #…………………………………………………………………………………………………
    pic = HIDE_ROULETTE::SELECT
    com = HIDE_ROULETTE::GAME_COMS
    helps = HIDE_ROULETTE::GAME_HELPS
    if HIDE_ROULETTE::AVERAGE && com.size == 3
      com.push("Average")
      helps.push("ルーレット履歴の表示をON/OFFします。")
    end
    @game_select_window = Window_Picture_Select.new(0,388+32,100*com.size,64,com,pic,s_font,helps,h_font)
    @game_select_window.help_window = @help_window[0]
    @game_select_window.index = 0
    @game_select_window.active = true
    @game_select_window.update_help
    @game_select_window.visible = true
    #…………………………………………………………………………………………………
    # ■テーブル(縦向き)ウィンドウを作成
    #…………………………………………………………………………………………………
    @mask_window[2] = Sprite.new(Viewport.new(0,0,480,480))
    @mask_window[2].bitmap = Bitmap.new(480,480)
    @mask_window[2].x = 200 ; @mask_window[2].y = 240
    #…………………………………………………………………………………………………
    # ■テーブル(縦向き)文字を描画108-172-221-290
    #…………………………………………………………………………………………………
    @mask_window[2].bitmap.draw_cache_text(40+60*0,62,58,32,"1-18",1,b_font)
    @mask_window[2].bitmap.draw_cache_text(40+60*5,62,58,32,"19-36",1,b_font)
    @mask_window[2].bitmap.draw_cache_text(40+60*0,0,118,32,"1-12",1,b_font)
    @mask_window[2].bitmap.draw_cache_text(40+60*2,0,118,32,"13-24",1,b_font)
    @mask_window[2].bitmap.draw_cache_text(40+60*4,0,118,32,"25-36",1,b_font)
    b_font.size = 18
    @mask_window[2].bitmap.draw_cache_text(40+60*1,62,58,32,"EVEN",1,b_font)
    @mask_window[2].bitmap.draw_cache_text(40+60*2,62,58,32,"RED",1,b_font)
    @mask_window[2].bitmap.draw_cache_text(40+60*3,62,58,32,"BRACK",1,b_font)
    @mask_window[2].bitmap.draw_cache_text(40+60*4,62,58,32,"ODD",1,b_font)
    @mask_window[2].viewport.z = @bet_table_window[0].z+2
    @mask_window[2].angle = 270 ; @mask_window[2].angle %= 360
    @mask_window[2].ox = 240 ; @mask_window[2].oy = 240
    #…………………………………………………………………………………………………
    # ■文字を描画
    #…………………………………………………………………………………………………
    b_font.color = HIDE_ROULETTE::S_COLOR
    @mask_window[0].bitmap.draw_cache_text(124,343,320,32,HIDE_ROULETTE::WORD2,0,b_font)
    @mask_window[0].bitmap.draw_cache_text(384,8,320,32,@coin_rate.to_s,0,b_font)
    @mask_window[0].bitmap.draw_cache_text(452,448,320,32,HIDE_ROULETTE::WORD1,0,b_font)
    @mask_window[0].bitmap.blt(344,8,bet_pic,Rect.new(7*32,0,32,24))
    b_font.color = HIDE_ROULETTE::A_COLOR
    #…………………………………………………………………………………………………
    # ■bet(配当)選択/betコイン描画ウィンドウを作成
    #…………………………………………………………………………………………………
    pic = HIDE_ROULETTE::SELECT
    com = ["x36","x18","x12","x9","x6","x3","x2","Clear"]
    helps = ["36倍の配当に賭けます。","18倍の配当に賭けます。","12倍の配当に賭けます。",
    "9倍の配当に賭けます。","6倍の配当に賭けます。","3倍の配当に賭けます。",
    "2倍の配当に賭けます。","全てのbetを戻します。"]
    b_font.size = 20
    @bet_select = [] ; @bet_coin_window = []
    for i in 0..7
      # □bet(配当)選択ウィンドウを作成
      sx = i > 3 ? 4 : 0 ; sy = i > 3 ? 32 : 0
      @bet_select[i] = Window_Picture_Select.new((i-sx)*100,388+sy,128,64,[com[i]],pic,b_font,[helps[i]],h_font)
      @bet_select[i].help_window = @help_window[0]
      @bet_select[i].index = -1
      # □betコイン描画ウィンドウを作成
      @bet_coin_window[i] = Sprite.new(Viewport.new(0,0,640,480))
      @bet_coin_window[i].bitmap = Bitmap.new(640,480)
      @bet_coin_window[i].viewport.z = @bet_table_window[0].z+2
    end
    @table_choice = []
    #…………………………………………………………………………………………………
    # ■bet x18(配当)ウィンドウを作成
    #…………………………………………………………………………………………………
    com = ["Rows","Line","0-00"]
    helps = ["縦2列を選択します。","横2列を選択します。","【緑0-緑00】を選択します。"]
    @table_choice[1] = Window_Picture_Select.new(0,388,100*3,64,com,pic,s_font,helps,h_font)
    @table_choice[1].help_window = @help_window[0]
    #…………………………………………………………………………………………………
    # ■bet x12(配当)ウィンドウを作成
    #…………………………………………………………………………………………………
    com = ["Street","1-0-2","0-2-00","2-00-3"]
    helps = ["横3列を選択します。","【赤1-緑0-黒2】を選択します。","【緑0-黒2-緑00】を選択します。",
    "【黒2-緑00-赤3】を選択します。"]
    @table_choice[2] = Window_Picture_Select.new(0,388,100*4,64,com,pic,s_font,helps,h_font)
    @table_choice[2].help_window = @help_window[0]
    #…………………………………………………………………………………………………
    # ■bet x3(配当)ウィンドウを作成
    #…………………………………………………………………………………………………
    com = ["Column","Dozen"]
    helps = ["縦1列12箇所を選択します。","12箇所を選択します。"]
    @table_choice[5] = Window_Picture_Select.new(0,388,100*2,64,com,pic,s_font,helps,h_font)
    @table_choice[5].help_window = @help_window[0]
    #…………………………………………………………………………………………………
    # ■bet x2(配当)ウィンドウを作成
    #…………………………………………………………………………………………………
    com = ["1-18","Even","Red"]
    helps = ["【赤1〜赤18】の18箇所を選択します。","偶数を選択します。","【赤】を選択します。"]
    @table_choice[6] = Window_Picture_Select.new(0,388,100*3,64,com,pic,s_font,helps,h_font)
    @table_choice[6].help_window = @help_window[0]
    com = ["19-36","Odd","Brack"]
    helps = ["【赤19〜赤36】の18箇所を選択します。","奇数を選択します。","【黒】を選択します。"]
    @table_choice[7] = Window_Picture_Select.new(0,388+32,100*3,64,com,pic,s_font,helps,h_font)
    @table_choice[7].help_window = @help_window[0]
    #…………………………………………………………………………………………………
    # □ヘルプを取得
    helps?
    # □賭け金選択肢のindex
    @bet_index = 0
    # □賭け金の初期化
    bet_clear?
    # □選択肢の文字色を初期化
    exchange_colors?
    # □ルーレットの初期化
    game_reset?
    # □払い戻しを描画
    draw_payout?
    #…………………………………………………………………………………………………
    # トランジション実行
    Graphics.transition
    # メインループ
    loop do
      # ゲーム画面を更新
      Graphics.update
      # 入力情報を更新
      Input.update
      # フレーム更新
      update
      # 画面が切り替わったらループを中断
      if $scene != self
        break
      end
    end
    # トランジション準備
    Graphics.freeze
    #…………………………………………………………………………………………………
    # ■ウィンドウを解放
    #…………………………………………………………………………………………………
    @roulette_window_back.dispose
    @coin_window.dispose
    @total_bet_coin_window.dispose
    @payout_coin_window.dispose
    @hit_window.dispose
    @game_select_window.dispose
    @help_window.each{ |a| a.dispose }
    @mask_window.each{ |a| a.viewport.dispose ; a.bitmap.dispose }
    @mask_window.each{ |a| a.dispose }
    @roulette_window.dispose
    @bet_select.each{ |a| a.dispose }
    @bet_table_window.each{ |a| a.dispose }
    @bet_coin_window.each{ |a| a.viewport.dispose ; a.bitmap.dispose }
    @bet_coin_window.each{ |a| a.dispose }
    @bet_table_zero.each{ |a| a.dispose }
    @bet_table_rows.each{ |a| a.dispose }
    @table_choice.each{ |a| if a != nil ; a.dispose ; end }
  end
  #--------------------------------------------------------------------------
  # ■ ヘルプを取得
  #--------------------------------------------------------------------------
  def helps?
    #…………………………………………………………………………………………………
    # ■ルーレットヘルプを取得(作成)
    #…………………………………………………………………………………………………
    @bet_helps = [[],[],[],[],[],[],[],[],[],[],[]]
    @table_colors = [] ; @table_numbers = [[]]
    for i in 0...@roulette_window.numbers.size
      n = @roulette_window.numbers[i][0]
      # □テーブルの色配列を取得
      @table_colors[n] = @roulette_window.numbers[i][1]
      num = n == 37 ? "00" : n.to_s
      ces = ["緑","黒","赤"]
      c = ces[@roulette_window.numbers[i][1]]
      @bet_helps[0][n] = c + num
      @table_numbers[0][n] = n
      # □bet x36ヘルプを取得
      @bet_helps[1][n] = "【"+ c + num + "】に賭けます。"
    end
    he = @bet_helps[0].delete_if { |a| a == @bet_helps[0][@bet_helps[0].size-1] }
    nm = @table_numbers[0].delete_if { |a| a == @table_numbers[0][@table_numbers[0].size-1] }
    for i in 1...he.size
      #…………………………………………………………………………………………………
      # ■ 11=x18(横2*1)
      #…………………………………………………………………………………………………
      if @bet_helps[2][(i-1)] == nil && i % 3 != 0 && he[i+1] != nil
        @bet_helps[2][(i-1)] = "【"+ he[i] + "-" + he[i+1] + "】に賭けます。"
        # □番号の組み合わせを配列化
        if @table_numbers[11] == nil
          @table_numbers[11] = [] ; n1 = 0
        end
        @table_numbers[11][n1] = [nm[i],nm[i+1]]
        n1 += 1
      end
      #…………………………………………………………………………………………………
      # ■ 10=x18(縦1*2)
      #…………………………………………………………………………………………………
      if @bet_helps[3][(i-1)] == nil && he[i+3] != nil
        @bet_helps[3][(i-1)] = "【"+ he[i] + "-" + he[i+3] + "】に賭けます。"
        # □番号の組み合わせを配列化
        if @table_numbers[10] == nil
          @table_numbers[10] = [] ; n2 = 0
        end
        @table_numbers[10][n2] = [nm[i],nm[i+3]]
        n2 += 1
      end
      #…………………………………………………………………………………………………
      # ■ 20=x12x12(横3*1)
      #…………………………………………………………………………………………………
      if @bet_helps[4][(i-1)] == nil && i % 3 == 1 && he[i+1] != nil && he[i+2] != nil
        @bet_helps[4][(i-1)] = "【"+ he[i] + "-" + he[i+1] + "-" + he[i+2] + "】に賭けます。"
        # □番号の組み合わせを配列化
        if @table_numbers[20] == nil
          @table_numbers[20] = [] ; n3 = 0
        end
        @table_numbers[20][n3] = [nm[i],nm[i+1],nm[i+2]]
        n3 += 1
      end
      #…………………………………………………………………………………………………
      # ■ 3=x9(横3*2)
      #…………………………………………………………………………………………………
      if @bet_helps[5][(i-1)] == nil && i % 3 != 0 && he[i+1] != nil && he[i+3] != nil && he[i+4] != nil
        @bet_helps[5][(i-1)] = "【"+ he[i] + "-" + he[i+1] + "-" + he[i+3] + "-" + he[i+4] + "】に賭けます。"
        # □番号の組み合わせを配列化
        if @table_numbers[3] == nil
          @table_numbers[3] = [] ; n4 = 0
        end
        @table_numbers[3][n4] = [nm[i],nm[i+1],nm[i+3],nm[i+4]]
        n4 += 1
      end
      #…………………………………………………………………………………………………
      # ■ 4=x6(横3*3)
      #…………………………………………………………………………………………………
      if @bet_helps[6][(i-1)] == nil && i % 3 == 1 && he[i+5] != nil
        @bet_helps[6][(i-1)] = "【"+ he[i] + "〜" + he[i+5] + "】の6箇所に賭けます。"
        # □番号の組み合わせを配列化
        if @table_numbers[4] == nil
          @table_numbers[4] = [] ; n5 = 0
        end
        @table_numbers[4][n5] = [nm[i],nm[i+1],nm[i+2],nm[i+3],nm[i+4],nm[i+5]]
        n5 += 1
      end
      #…………………………………………………………………………………………………
      # ■ 5=x3(横3*4)
      #…………………………………………………………………………………………………
      if @bet_helps[7][(i-1)] == nil && i % 4 != 0 && he[i+33] != nil
        @bet_helps[7][(i-1)] = "【"+ he[i] + "〜" + he[i+33] + "】の1列12箇所に賭けます。"
        # □番号の組み合わせを配列化
        if @table_numbers[5] == nil
          @table_numbers[5] = [] ; n6 = 0
        end
        b = n6*11
        @table_numbers[5][n6] = [nm[i+b],nm[i+1+b],nm[i+2+b],nm[i+3+b],nm[i+4+b],nm[i+5+b],
        nm[i+6+b],nm[i+7+b],nm[i+8+b],nm[i+9+b],nm[i+10+b],nm[i+11+b]]
        n6 += 1
      end
      #…………………………………………………………………………………………………
      # ■ 50=x3(横1*12)
      #…………………………………………………………………………………………………
      if @bet_helps[8][(i-1)] == nil && i % 12 == 1 && he[i+11] != nil
        @bet_helps[8][(i-1)] = "【"+ he[i] + "〜" + he[i+11] + "】の12箇所に賭けます。"
        # □番号の組み合わせを配列化
        if @table_numbers[50] == nil
          @table_numbers[50] = [] ; n7 = 0
        end
        b = 3 ; c = n7*11
        @table_numbers[50][n7] = [nm[i-c],nm[i+1*b-c],nm[i+2*b-c],nm[i+3*b-c],nm[i+4*b-c],
        nm[i+5*b-c],nm[i+6*b-c],nm[i+7*b-c],nm[i+8*b-c],nm[i+9*b-c],nm[i+10*b-c],nm[i+11*b-c]]
        n7 += 1
      end
    end
    @bet_helps[9] = ["【赤1〜赤18】に賭けます。","【赤19〜赤36】の18箇所に賭けます。"]
    @bet_helps[10] = ["偶数に賭けます。","【赤】に賭けます。"]
    @bet_helps[11] = ["奇数に賭けます。","【黒】に賭けます。"]
    @bet_helps.each{ |a| a.delete_if { |a| a == nil } }
    # □0-00を含む組み合わせを配列化
    @table_numbers[1] = [[0,37]]
    @table_numbers[2] = [[1,0,2],[0,2,37],[2,37,3]]
  end
  #--------------------------------------------------------------------------
  # ■ ゲームの終了
  #--------------------------------------------------------------------------
  def roulette_end
    unless @playing
      # □ルーレット開始前の BGM に戻す
      $game_system.bgm_play($game_temp.map_bgm)
      # □マップ画面に切り替え
      $scene = Scene_Map.new
      return
    end
  end
  #--------------------------------------------------------------------------
  # ■【赤】の場合trueを返す
  #--------------------------------------------------------------------------
  def red?(n)
    return @table_colors[n] == 2
  end
  #--------------------------------------------------------------------------
  # ■【黒】の場合trueを返す
  #--------------------------------------------------------------------------
  def brack?(n)
    return @table_colors[n] == 1
  end
  #--------------------------------------------------------------------------
  # ■【偶数】の場合trueを返す(0 偶数除外)
  #--------------------------------------------------------------------------
  def even?(n)
    return n % 2 == 0 && n != 0
  end
  #--------------------------------------------------------------------------
  # ■【奇数】の場合trueを返す(00=37 奇数除外)
  #--------------------------------------------------------------------------
  def odd?(n)
    return n % 2 == 1 && n != 37
  end
  #--------------------------------------------------------------------------
  # ■【1-18】の場合trueを返す(0 除外)
  #--------------------------------------------------------------------------
  def low?(n)
    return n > 0 && n < 19
  end
  #--------------------------------------------------------------------------
  # ■【19-36】の場合trueを返す(00=37 除外)
  #--------------------------------------------------------------------------
  def hi?(n)
    return n > 18 && n < 37
  end
  #--------------------------------------------------------------------------
  # ■ 配当データを取得
  #--------------------------------------------------------------------------
  def roulette_data?
    @data = []
    for i in 0..37
      numbers?(i,true)
    end
    max_data = @data.dup
    max = @data.max
    max_data.delete(max)
    max_size = @data.size - max_data.size
    a = max_size / 38.00 * 100
    n = 0
    for i in @data
      if @bet_coin < i
        n += 1
      end
    end
    return [max,a,n / 38.00 * 100]
  end
  #--------------------------------------------------------------------------
  # ■ 配当の計算
  #--------------------------------------------------------------------------
  def numbers?(n = 0,set = false)
    @set_coin = [false]*7 ; @hit_coin = [false]*8
    payout = 0 ; @payout = 0
    if @data == nil
      @data = []
    end
    for c in @bet_point.keys
      bets = @bet_point[c]
      for i in bets.keys
        bet = bets[i]
        # □bet済み判別
        if bet > 0
          index = i-1 ; pay = 0 ; hit = 8
          case c
          when 0
            index = 0 ; pay = 36 ; @set_coin[0] = true ; hit = 0
          when 1,10,11
            pay = 18 ; @set_coin[1] = true ; hit = 1
          when 2,20
            pay = 12 ; @set_coin[2] = true ; hit = 2
          when 3
            pay = 9 ; @set_coin[3] = true ; hit = 3
          when 4
            pay = 6 ; @set_coin[4] = true ; hit = 4
          when 5,50
            pay = 3 ; @set_coin[5] = true ; hit = 5
          when 6,7,8
            pay = 2 ; @set_coin[6] = true ; hit = 6
          end
          # □
          case c
          when 0
            # □1箇所に賭けた場合
            if i == n
              payout += bet * @coin_rate * pay
              @hit_coin[0] = true
            end
          when 6 #(0=1-18/1=19-36)
            if index == 0 && low?(n) or index == 1 && hi?(n)
              payout += bet * @coin_rate * pay
              @hit_coin[6] = true
            end
          when 7 #(0=EVEN/1=ODD)
            if index == 0 && even?(n) or index == 1 && odd?(n)
              payout += bet * @coin_rate * pay
              @hit_coin[6] = true
            end
          when 8 #(0=RED/1=BRACK)
            if index == 0 && red?(n) or index == 1 && brack?(n)
              payout += bet * @coin_rate * pay
              @hit_coin[6] = true
            end
          else
            # □数値に賭けた場合
            if @table_numbers[c][index].include?(n)
              payout += bet * @coin_rate * pay
              @hit_coin[hit] = true
            end
          end
        end
      end
    end
    @data.push(payout)
    # □セットコインの取得(配当の計算はしない)
    unless set
      @payout = payout
    end
  end
  #--------------------------------------------------------------------------
  # ■ 賭け金の初期化
  #--------------------------------------------------------------------------
  def bet_clear?
    @bet_coin = 0 ; @payout = 0
    @bet_point = {}
    #…………………………………………………………………………………………………
    # ■ 0=x36
    #…………………………………………………………………………………………………
    @bet_point[0] = {0=>0,1=>0,2=>0,3=>0,4=>0,5=>0,6=>0,7=>0,8=>0,9=>0,
    10=>0,11=>0,12=>0,13=>0,14=>0,15=>0,16=>0,17=>0,18=>0,19=>0,20=>0,
    21=>0,22=>0,23=>0,24=>0,25=>0,26=>0,27=>0,28=>0,29=>0,30=>0,31=>0,
    31=>0,32=>0,33=>0,34=>0,35=>0,36=>0,37=>0}
    #…………………………………………………………………………………………………
    # ■ 1=x18(0-00)
    #…………………………………………………………………………………………………
    @bet_point[1] = {0=>0}
    #…………………………………………………………………………………………………
    # ■ 10=x18(縦1*2)
    #…………………………………………………………………………………………………
    @bet_point[10] = {1=>0,2=>0,3=>0,4=>0,5=>0,6=>0,7=>0,8=>0,9=>0,
    10=>0,11=>0,12=>0,13=>0,14=>0,15=>0,16=>0,17=>0,18=>0,19=>0,20=>0,
    21=>0,22=>0,23=>0,24=>0,25=>0,26=>0,27=>0,28=>0,29=>0,30=>0,31=>0,
    31=>0,32=>0,33=>0}
    #…………………………………………………………………………………………………
    # ■ 11=x18(横2*1)
    #…………………………………………………………………………………………………
    @bet_point[11] = {1=>0,2=>0,3=>0,4=>0,5=>0,6=>0,7=>0,8=>0,9=>0,
    10=>0,11=>0,12=>0,13=>0,14=>0,15=>0,16=>0,17=>0,18=>0,19=>0,20=>0,
    21=>0,22=>0,23=>0,24=>0}
    #…………………………………………………………………………………………………
    # ■ 2=x12(1-0-2,0-2-00,2-00-3)
    #…………………………………………………………………………………………………
    @bet_point[2] = {1=>0,2=>0,3=>0}
    #…………………………………………………………………………………………………
    # ■ 20=x12(横3*1)
    #…………………………………………………………………………………………………
    @bet_point[20] = {1=>0,2=>0,3=>0,4=>0,5=>0,6=>0,7=>0,8=>0,9=>0,
    10=>0,11=>0,12=>0}
    #…………………………………………………………………………………………………
    # ■ 3=x9(横3*2)
    #…………………………………………………………………………………………………
    @bet_point[3] = {1=>0,2=>0,3=>0,4=>0,5=>0,6=>0,7=>0,8=>0,9=>0,
    10=>0,11=>0,12=>0,13=>0,14=>0,15=>0,16=>0,17=>0,18=>0,19=>0,20=>0,
    21=>0,22=>0}
    #…………………………………………………………………………………………………
    # ■ 4=x6(横3*3)
    #…………………………………………………………………………………………………
    @bet_point[4] = {1=>0,2=>0,3=>0,4=>0,5=>0,6=>0,7=>0,8=>0,9=>0,
    10=>0,11=>0}
    #…………………………………………………………………………………………………
    # ■ 5=x3(横3*4)
    #…………………………………………………………………………………………………
    @bet_point[5] = {1=>0,2=>0,3=>0}
    #…………………………………………………………………………………………………
    # ■ 50=x3(横1*12)
    #…………………………………………………………………………………………………
    @bet_point[50] = {1=>0,2=>0,3=>0}
    #…………………………………………………………………………………………………
    # ■ 6=x2(3*6)
    #…………………………………………………………………………………………………
    @bet_point[6] = {1=>0,2=>0}
    #…………………………………………………………………………………………………
    # ■ 6=x2(EVEN/ODD)
    #…………………………………………………………………………………………………
    @bet_point[7] = {1=>0,2=>0}
    #…………………………………………………………………………………………………
    # ■ 6=x2(RED/BRACK)
    #…………………………………………………………………………………………………
    @bet_point[8] = {1=>0,2=>0}
    # □@bet_coin_window[7]以外を消去
    for a in 0...@bet_coin_window.size - 1
      @bet_coin_window[a].bitmap.clear
    end
    # □選択肢の文字色を初期化
    exchange_colors?
  end
  #--------------------------------------------------------------------------
  # ■ テーブルマスクの作成 0=EVEN(偶数) 1=RED 2=BRACK 3=ODD(奇数)
  #--------------------------------------------------------------------------
  def draw_bitmap?(c=0)
    top = @mask_window[0].bitmap
    back = RPG::Cache.windowskin(HIDE_ROULETTE::BACK)
    # □Bitmapの初期化
    draw_payout?(false)
    x = 454 ; y = 39 ; cx = 59+2 ; cy = 28+2
    w = 59 ; h = 28
    draw = false
    case c
    when -1 # 初期化
      return
    when 4 # 0-00(1-2-3マスク)
      rx = x + cx*(0%3) ; ry = y + cy*(0/3)
      @mask_window[1].bitmap.blt(rx,ry,back,Rect.new(rx,ry,w,h))
      @mask_window[1].bitmap.blt(rx,ry,top,Rect.new(rx,ry,w,h))
      rx = x + cx*(1%3) ; ry = y + cy*(1/3)
      @mask_window[1].bitmap.blt(rx,ry,back,Rect.new(rx,ry,w,h))
      @mask_window[1].bitmap.blt(rx,ry,top,Rect.new(rx,ry,w,h))
      rx = x + cx*(2%3) ; ry = y + cy*(2/3)
      @mask_window[1].bitmap.blt(rx,ry,back,Rect.new(rx,ry,w,h))
      @mask_window[1].bitmap.blt(rx,ry,top,Rect.new(rx,ry,w,h))
      return
    when 5 # 1-0-2(00-3マスク)
      rx = x + cx*(2%3) ; ry = y + cy*(2/3)
      @mask_window[1].bitmap.blt(rx,ry,back,Rect.new(rx,ry,w,h))
      @mask_window[1].bitmap.blt(rx,ry,top,Rect.new(rx,ry,w,h))
      rx = x + cx*2-cx/2 ; ry = 0
      @mask_window[1].bitmap.blt(rx,ry,back,Rect.new(rx,ry,w+w/2,h+9))
      @mask_window[1].bitmap.blt(rx,ry,top,Rect.new(rx,ry,w+w/2,h+9))
      return
    when 6 # 0-2-00(1-3マスク)
      rx = x + cx*(0%3) ; ry = y + cy*(0/3)
      @mask_window[1].bitmap.blt(rx,ry,back,Rect.new(rx,ry,w,h))
      @mask_window[1].bitmap.blt(rx,ry,top,Rect.new(rx,ry,w,h))
      rx = x + cx*(2%3) ; ry = y + cy*(2/3)
      @mask_window[1].bitmap.blt(rx,ry,back,Rect.new(rx,ry,w,h))
      @mask_window[1].bitmap.blt(rx,ry,top,Rect.new(rx,ry,w,h))
      return
    when 7 # 2-00-3(1-0マスク)
      rx = x + cx*(0%3) ; ry = y + cy*(0/3)
      @mask_window[1].bitmap.blt(rx,ry,back,Rect.new(rx,ry,w,h))
      @mask_window[1].bitmap.blt(rx,ry,top,Rect.new(rx,ry,w,h))
      rx = x + cx*(0%3) ; ry = 0
      @mask_window[1].bitmap.blt(rx,ry,back,Rect.new(rx,ry,w+w/2+2,h+9))
      @mask_window[1].bitmap.blt(rx,ry,top,Rect.new(rx,ry,w+w/2+2,h+9))
      return
    end
    for i in 0...36
      rx = x + cx*(i%3) ; ry = y + cy*(i/3)
      case c
      when 0 # EVEN(偶数)
        draw = (i+1) % 2 == 0
      when 1 # RED
        draw = @table_colors[i+1] == 2
      when 2 # BRACK
        draw = @table_colors[i+1] == 1
      when 3 # ODD(奇数)
        draw = (i+1) % 2 != 0
      end
      if draw
        @mask_window[1].bitmap.blt(rx,ry,back,Rect.new(rx,ry,w,h))
        @mask_window[1].bitmap.blt(rx,ry,top,Rect.new(rx,ry,w,h))
      end
    end
  end
  #--------------------------------------------------------------------------
  # ■ 払い戻しを描画
  #--------------------------------------------------------------------------
  def draw_payout?(d = true)
    # □払い戻し数値の可視化
    @payout_coin_window.visible = d
    # □Bitmapの初期化
    @mask_window[1].bitmap.clear
    unless d
      #…………………………………………………………………………………………………
      # ■キーヘルプを描画
      #…………………………………………………………………………………………………
      pic = RPG::Cache.windowskin(HIDE_ROULETTE::BET)
      for i in 0..3
        @mask_window[1].bitmap.blt(16+i*32,456,pic,Rect.new(7*32,24*5+i*24,32,24))
      end
      return
    end
    #…………………………………………………………………………………………………
    # ■払い戻しを描画
    #…………………………………………………………………………………………………
    n_font = HIDE_ROULETTE::T_FONT
    n_font.color = HIDE_ROULETTE::S_COLOR
    n_font.size = 18
    @mask_window[1].bitmap.draw_cache_text(16,448-45,320,32,HIDE_ROULETTE::WORD3,0,n_font)
    @mask_window[1].bitmap.blt(16,448+24-45,@mask_window[0].bitmap,Rect.new(452,448+24,185,2))
    #…………………………………………………………………………………………………
    # ■スピン回数を描画
    #…………………………………………………………………………………………………
    @bet_coin_window[7].bitmap.clear
    t = $game_temp.roulette_type
    a = $game_party.roulette_average[t]
    v = 0 ; v0 = 0
    for s in a
      v += (s * 1.00) ; v0 = [v0 + s,999999].min
    end
    n_font.size = 12
    n_font.color = HIDE_ROULETTE::A_COLOR
    @bet_coin_window[7].bitmap.draw_cache_text(60,344,55,32,"spin:" + v0.to_s,0,n_font)
    #…………………………………………………………………………………………………
    # ■ポケット確立を描画
    #…………………………………………………………………………………………………
    t = $game_temp.roulette_type
    if HIDE_ROULETTE::AVERAGE && $game_party.roulette_draw[t]
      n_font.size = 10
      n_font.round = true
      line = [0]*3 ; dozen = [0]*3 ; hi_low = [0]*2 ; odd_even = [0]*2 ; red_brack = [0]*2
      for i in 0..37
        n_font.color = HIDE_ROULETTE::A_COLOR
        if a[i] == a.max && a[i] != 0
          n_font.color = HIDE_ROULETTE::H_COLOR
        elsif a[i] == a.min
          n_font.color = HIDE_ROULETTE::L_COLOR
        end
        b = a[i] == 0 ? "0.00%" : sprintf("%.2f",(a[i]/v*100)) + "%"
        case i
        when 0
          @bet_coin_window[7].bitmap.draw_cache_text(484,4,59,32,b,2,n_font)
        when 37
          @bet_coin_window[7].bitmap.draw_cache_text(484+91,4,59,32,b,2,n_font)
        else
          @bet_coin_window[7].bitmap.draw_cache_text(453+61*((i-1)%3),31+30*((i-1)/3),59,32,b,2,n_font)
          # □1列12箇所
          case i%3
          when 1
            line[0] += a[i]
          when 2
            line[1] += a[i]
          when 0
            line[2] += a[i]
          end
          # □12箇所
          case i
          when 1..12
            dozen[0] += a[i]
          when 13..24
            dozen[1] += a[i]
          when 25..36
            dozen[2] += a[i]
          end
          # □18箇所
          case i
          when 1..18
            hi_low[0] += a[i]
          when 19..36
            hi_low[1] += a[i]
          end
          # □18箇所(奇数/偶数)
          case i%2
          when 1 #奇数
            odd_even[1] += a[i]
          when 0 #偶数
            odd_even[0] += a[i]
          end
          # □18箇所(赤/黒)
          case @table_colors[i]
          when 2 #赤
            red_brack[0] += a[i]
          when 1 #黒
            red_brack[1] += a[i]
          end
        end
      end
      # □1列12箇所/12箇所
      for i in 0...3
        if line[i] == line.max && line[i] != 0
          n_font.color = HIDE_ROULETTE::H_COLOR
        elsif line[i] == line.min && line[i] != 0
          n_font.color = HIDE_ROULETTE::L_COLOR
        else
          n_font.color = HIDE_ROULETTE::A_COLOR
        end
        b = line[i] == 0 ? "0.00%" : sprintf("%.2f",(line[i]/v*100)) + "%"
        @bet_coin_window[7].bitmap.draw_cache_text(453+61*(i%3),31+30*12,59,32,b,2,n_font)
        if dozen[i] == dozen.max && dozen[i] != 0
          n_font.color = HIDE_ROULETTE::H_COLOR
        elsif dozen[i] == dozen.min && dozen[i] != 0
          n_font.color = HIDE_ROULETTE::L_COLOR
        else
          n_font.color = HIDE_ROULETTE::A_COLOR
        end
        b = dozen[i] == 0 ? "0.00%" : sprintf("%.2f",(dozen[i]/v*100)) + "%"
        @bet_coin_window[7].bitmap.draw_cache_text(453-61,31+30*(i*4),59,32,b,2,n_font)
      end
      # □18箇所/18箇所(奇数/偶数)/18箇所(赤/黒)
      for i in 0...2
        if hi_low[i] == hi_low.max && hi_low[i] != 0
          n_font.color = HIDE_ROULETTE::H_COLOR
        elsif hi_low[i] == hi_low.min
          n_font.color = HIDE_ROULETTE::L_COLOR
        else
          n_font.color = HIDE_ROULETTE::A_COLOR
        end
        b = hi_low[i] == 0 ? "0.00%" : sprintf("%.2f",(hi_low[i]/v*100)) + "%"
        @bet_coin_window[7].bitmap.draw_cache_text(453-61*2,31+30*(i*10),59,32,b,2,n_font)
        
        if odd_even[i] == odd_even.max && odd_even[i] != 0
          n_font.color = HIDE_ROULETTE::H_COLOR
        elsif odd_even[i] == odd_even.min
          n_font.color = HIDE_ROULETTE::L_COLOR
        else
          n_font.color = HIDE_ROULETTE::A_COLOR
        end
        b = odd_even[i] == 0 ? "0.00%" : sprintf("%.2f",(odd_even[i]/v*100)) + "%"
        @bet_coin_window[7].bitmap.draw_cache_text(453-61*2,31+30*(i*6)+30*2,59,32,b,2,n_font)
        
        if red_brack[i] == red_brack.max && red_brack[i] != 0
          n_font.color = HIDE_ROULETTE::H_COLOR
        elsif red_brack[i] == red_brack.min
          n_font.color = HIDE_ROULETTE::L_COLOR
        else
          n_font.color = HIDE_ROULETTE::A_COLOR
        end
        b = red_brack[i] == 0 ? "0.00%" : sprintf("%.2f",(red_brack[i]/v*100)) + "%"
        @bet_coin_window[7].bitmap.draw_cache_text(453-61*2,31+30*(i*2)+30*4,59,32,b,2,n_font)
      end
    end
    # □フォントの初期化
    n_font = HIDE_ROULETTE::T_FONT
    n_font.color = HIDE_ROULETTE::A_COLOR
    n_font.size = HIDE_ROULETTE::T_SIZE
    n_font.round = HIDE_ROULETTE::T_ROUND
  end
  #--------------------------------------------------------------------------
  # ■ コインを描画/合計betの取得
  #--------------------------------------------------------------------------
  def draw_coin?(x,y,type,index,win = @bet_index,half = 1)
    #…………………………………………………………………………………………………
    # ■ C ボタンが押された場合
    #…………………………………………………………………………………………………
    if Input.repeat?(Input::C)
      update_draw_coin?(x,y,type,index,1,nil,win,half)
    end
    #…………………………………………………………………………………………………
    # ■ A ボタンが押された場合
    #…………………………………………………………………………………………………
    if Input.repeat?(Input::A)
      update_draw_coin?(x,y,type,index,-1,nil,win,half)
    end
    #…………………………………………………………………………………………………
    # ■ R ボタンが押された場合
    #…………………………………………………………………………………………………
    if Input.trigger?(Input::R)
      update_draw_coin?(x,y,type,index,nil,5,win,half)
    end
    #…………………………………………………………………………………………………
    # ■ L ボタンが押された場合
    #…………………………………………………………………………………………………
    if Input.trigger?(Input::L)
      update_draw_coin?(x,y,type,index,nil,0,win,half)
    end
  end
  #--------------------------------------------------------------------------
  # ■ コインを描画/合計betの更新
  #--------------------------------------------------------------------------
  def update_draw_coin?(x,y,type,index,n,max = nil,win = @bet_index,half = 1)
    point = @bet_point[type][index] ; old_point = @bet_point[type][index]
    max_n = [HIDE_ROULETTE::MAX_BET,15].min
    a = @bet_point ; i0 = max_n
    # □bet計算有りの場合
    if half == 1
      case max
      when nil # ±1
        point += n
        if point > max_n or point < 0
          point = 0
        end
      when 0 # 初期化
        point = 0
      when 5 # Max賭け
        i0 = ($game_party.coin - @bet_coin)/@coin_rate
        point = i0 > max_n ? max_n : i0
      end
      a[type][index] = point
      b = bet_coin?(a)
      # □所持コインより多い場合
      if b > $game_party.coin
        point -= i0
        if point > i0 or point < 0
          point = 0
        end
        a[type][index] = point
      end
      if old_point == point
        # □ブザーを演奏
        $game_system.se_play(RPG::AudioFile.new(HIDE_ROULETTE::BUZZER_SE))
      else
        # □SEを演奏
        $game_system.se_play(RPG::AudioFile.new(HIDE_ROULETTE::BED_SE))
      end
      @bet_point = a
      @bet_coin = bet_coin?(@bet_point)
      # □選択肢の色更新(Spin)
      exchange_colors?
    end
    # □透明に塗りつぶし
    @bet_coin_window[win].bitmap.fill_rect(Rect.new(x,y,32,24),Color.new(0,0,0,0))
    pic = RPG::Cache.windowskin(HIDE_ROULETTE::BET)
    @bet_coin_window[win].bitmap.blt(x,y,pic,Rect.new(@bet_index*32,24 * (point-1),32,24/half))
    # □ルーレット勝率を取得
    max = roulette_data?
    # □透明に塗りつぶし
    i = @bet_index
    @bet_coin_window[0].bitmap.fill_rect(Rect.new(180,324-16,120,32+16),Color.new(0,0,0,0))
    @bet_coin_window[0].bitmap.fill_rect(Rect.new(455+i*27,431+8,17,14),Color.new(0,0,0,0))
    # □ルーレット勝率を描画
    if @bet_coin > 0 && HIDE_ROULETTE::HELP
      n_font = HIDE_ROULETTE::T_FONT
      n_font.size = 12
      text = "Max:" + max[0].to_s + "  " + sprintf("%.2f",max[1]) + "%"
      @bet_coin_window[0].bitmap.draw_cache_text(180,324,120,32,text,2,n_font)
      text = "Win:" + sprintf("%.2f",max[2]) + "%"
      @bet_coin_window[0].bitmap.draw_cache_text(180,324-16,120,32,text,2,n_font)
      n_font.size = HIDE_ROULETTE::T_SIZE
    end
    # □コインの描画
    numbers?(0,true)
    if @set_coin[i]
      # □コインの描画
      @bet_coin_window[0].bitmap.blt(455+i*27,431+8,pic,Rect.new(7*32,34,17,14))
    end
  end
  #--------------------------------------------------------------------------
  # ■ 合計betの取得
  #--------------------------------------------------------------------------
  def bet_coin?(bet_point)
    bet_coin = 0
    for bets in bet_point.values
      for bet in bets.values
        bet_coin += (bet * @coin_rate)
      end
    end
    return bet_coin
  end
  #--------------------------------------------------------------------------
  # ■ 選択肢の色更新
  #--------------------------------------------------------------------------
  def exchange_colors?
    @game_select_window.colors[0] = $game_party.coin < @coin_rate
    @game_select_window.colors[1] = @bet_coin == 0
    @game_select_window.refresh
  end
  #--------------------------------------------------------------------------
  # ■ フレーム更新(賭け開始)
  #--------------------------------------------------------------------------
  def bet_select_update
    #…………………………………………………………………………………………………
    # ■ C ボタンが押された場合
    #…………………………………………………………………………………………………
    if Input.trigger?(Input::C)
      # □決定SEを演奏
      $game_system.se_play(RPG::AudioFile.new(HIDE_ROULETTE::DECISION_SE))
      @bet_select[@bet_index].active = false
      case @bet_index
      when 0,3,4 # x36,x9,x6
        @bet_table_window[@bet_index].index = 0
        @bet_table_window[@bet_index].visible = true
        @bet_table_window[@bet_index].active = true
        @bet_table_zero[0].draw_color(@select_colors[@bet_index])
        @bet_table_window[@bet_index].draw_color(@select_colors[@bet_index])
      when 1,2,5,6 # x18,x12,x3,x2(選択肢)
        @table_choice[@bet_index].index = 0
        @table_choice[@bet_index].visible = true
        @table_choice[@bet_index].active = true
        @table_choice[7].visible = @bet_index == 6
        @bet_select.each{ |a| a.index = -1 }
        @bet_select.each{ |a| a.visible = false }
      when 7 # リセット
        # □決定SEを演奏
        $game_system.se_play(RPG::AudioFile.new(HIDE_ROULETTE::DECISION_SE))
        bet_clear?
        @bet_select[@bet_index].active = true
        @bet_select[@bet_index].update_help
      end
    end
    #…………………………………………………………………………………………………
    # ■ 上下 ボタンが押された場合
    #…………………………………………………………………………………………………
    if Input.repeat?(Input::UP) or Input.repeat?(Input::DOWN)
      $game_system.se_play($data_system.cursor_se)
      if @bet_index > 3
        @bet_index -= 4
      else
        @bet_index += 4
      end
      bet_select_reset?
    end
    #…………………………………………………………………………………………………
    # ■ 右が押された場合
    #…………………………………………………………………………………………………
    if Input.repeat?(Input::RIGHT)
      $game_system.se_play($data_system.cursor_se)
      if @bet_index == 3
        @bet_index = 0
      elsif @bet_index == 7
        @bet_index = 4
      else
        @bet_index += 1
      end
      bet_select_reset?
    end
    #…………………………………………………………………………………………………
    # ■ 左が押された場合
    #…………………………………………………………………………………………………
    if Input.repeat?(Input::LEFT)
      $game_system.se_play($data_system.cursor_se)
      if @bet_index == 0
        @bet_index = 3
      elsif @bet_index == 4
        @bet_index = 7
      else
        @bet_index -= 1
      end
      bet_select_reset?
    end
    #…………………………………………………………………………………………………
    # ■ B ボタンが押された場合
    #…………………………………………………………………………………………………
    if Input.trigger?(Input::B)
      unless @roulette_window.angle
        # □キャンセルSEを演奏
        $game_system.se_play(RPG::AudioFile.new(HIDE_ROULETTE::CANCEL_SE))
        @bet_select.each{ |a| a.index = -1 }
        @bet_select.each{ |a| a.active = false }
        @bet_select.each{ |a| a.visible = false }
        @bet_index = 0
        @game_select_window.update_help
        @game_select_window.active = true
        @game_select_window.visible = true
        # □払い戻しを描画
        draw_payout?
      end
      return
    end
  end
  #--------------------------------------------------------------------------
  # ■ 賭け金選択の初期化
  #--------------------------------------------------------------------------
  def bet_select_reset?
    @bet_select.each{ |a| a.index = -1 }
    @bet_select.each{ |a| a.active = false }
    @bet_select[@bet_index].index = 0
    @bet_select[@bet_index].active = true
  end
  #--------------------------------------------------------------------------
  # ■ フレーム更新(ゲーム開始)
  #--------------------------------------------------------------------------
  def update_select
    #…………………………………………………………………………………………………
    # ■ C ボタンが押された場合
    #…………………………………………………………………………………………………
    if Input.trigger?(Input::C)
      unless @move
        case @game_select_window.index
        when 0 # □賭け金を設定
          unless @roulette_window.angle
            if $game_party.coin < @coin_rate
              # □ブザーを演奏
              $game_system.se_play(RPG::AudioFile.new(HIDE_ROULETTE::BUZZER_SE))
              return
            end
            # □決定SEを演奏
            $game_system.se_play(RPG::AudioFile.new(HIDE_ROULETTE::DECISION_SE))
            @game_select_window.active = false
            @game_select_window.visible = false
            @bet_select.each{ |a| a.index = -1 }
            @bet_select.each{ |a| a.active = false }
            @bet_select.each{ |a| a.visible = true }
            @bet_select.each{ |a| a.update_help }
            @old_help = nil
            @bet_select[0].active = true
            @bet_select[0].index = 0
            @bet_select[0].update_help
            # □払い戻しを消去
            draw_payout?(false)
          end
        when 1 # □ゲーム開始(ルーレット回転)
          # □コインが足りない/betが0の場合
          if @bet_coin == 0 or $game_party.coin < @coin_rate
            # □ブザーを演奏
            $game_system.se_play(RPG::AudioFile.new(HIDE_ROULETTE::BUZZER_SE))
            return
          end
          # □コインを減らす
          $game_party.lose_coin(@bet_coin)
          # □選択肢の文字色を初期化
          exchange_colors?
          # □配当金の初期化
          @payout = 0
          @game_select_window.update
          # □決定SEを演奏
          $game_system.se_play(RPG::AudioFile.new(HIDE_ROULETTE::DECISION_SE))
          @roulette_step = 0
          @game_select_window.active = false
          # □ルーレット回転の開始
          @roulette_window.refresh
          @roulette_window.angle = true
        when 2 # □終了
          unless @roulette_window.angle
            # □決定SEを演奏
            $game_system.se_play(RPG::AudioFile.new(HIDE_ROULETTE::DECISION_SE))
            roulette_end
          end
        when 3 # □履歴の表示
          # □決定SEを演奏
          $game_system.se_play(RPG::AudioFile.new(HIDE_ROULETTE::DECISION_SE))
          t = $game_temp.roulette_type
          $game_party.roulette_draw[t] ^= true
          draw_payout?
        end
      end
      return
    end
    #…………………………………………………………………………………………………
    # ■ B ボタンが押された場合
    #…………………………………………………………………………………………………
    if Input.trigger?(Input::B)
      unless @roulette_window.angle
        # □キャンセルSEを演奏
        $game_system.se_play(RPG::AudioFile.new(HIDE_ROULETTE::CANCEL_SE))
        roulette_end
      end
      return
    end
  end
end