#==============================================================================
# ■ SicBo vol.1.20
#------------------------------------------------------------------------------
# ※『Window_digits_number 5.90以上』(必須)
# ※『Picture_Blink_Cursor 1.60以上』(必須)
# ※『Window_Play_Cards 1.00以上』(必須)
# ※『Coin_Base 5.00以上』(必須)より下に挿入
# 12/04/22
#==============================================================================
module HIDE_SICBO
  #==============================================================================
  # ■ デバッグ(開発者用)
  #==============================================================================
  DEBUG = false                    # [true/false]
  DEBUG_DICE = [5,5,5]
  #==============================================================================
  # ■ イベントコマンド『スクリプト』に以下を追加
  #------------------------------------------------------------------------------
  #   make_sicbo(type)
  #------------------------------------------------------------------------------
  #   type=シックボータイプの設定を参照
  #==============================================================================
  # ■ ゲーム設定
  #==============================================================================
  MAX_BET = 15                     # 一箇所に賭けられるコイン最大数(1〜15)
  HELP = true                      # 勝率と最大配当を表示する[true/false]
  AVERAGE = true                   # ポケット確率を描画する[true/false]
  WORD0 = "Average"
  A_HELP = "シックボー履歴の表示をON/OFFします。"
  #==============================================================================
  # ■ グラフィック設定 ※Windowskinsフォルダ内のファイル名を指定
  #==============================================================================
  BACK = "coin_background1"        # シックボーの背景画像
  TOP = "sicbo_table"              # シックボーの背景画像
  NUMBER1 = "number_image1"        # シックボー数値画像(小)
  NUMBER2 = "number_image2"        # シックボー数値画像(大)
  BET = "bet_coin"                 # コイン画像
  SELECT = "cursor_back"           # カーソル画像
  CURSOR = "cursor_anim"           # カーソルアイコン画像
  #==============================================================================
  # ■ 選択肢とヘルプの設定
  #==============================================================================
  GAME_COMS = ["Bet","Spin","End"]
  GAME_HELPS = ["賭け金を決めます。","ダイスを振ります。","ゲームを終了します。"]
  #==============================================================================
  # ■ 音の設定 ※ファイル名を指定 ※Audioフォルダ内 #()のファイル名
  #==============================================================================
  BGM = "019-Field02"              # シックボー実行中のBGM(BGM)
  DECISION_SE = "002-System02"     # 決定キーの効果音(SE)
  CANCEL_SE = "003-System03"       # キャンセルキーの効果音(SE)
  BUZZER_SE = "004-System04"       # ブザー音の効果音(SE)
  HIT_ME_MAX = "009-Fanfare03"     # 大当りの効果音(ME)
  HIT_ME = "007-Fanfare01"         # 当りの効果音(ME)
  BED_SE = "006-System06"          # コインを賭けた効果音(SE)
  
  ME_MAX_TIME = 12                 # 大当りの待ち時間(HIT_ME_MAXの演奏時間(秒))
  ME_TIME = 4                      # 当りの待ち時間(HIT_MEの演奏時間(秒))
  #==============================================================================
  # ■ シックボータイプの設定(COIN,RATE,ME_RATE_MAX)
  # COIN[n] = value　※n=タイプ番号($game_temp.sicbo_type から参照される)
  #==============================================================================
  COIN = [] # value=消費コイン数(賭けるコイン枚数)
  COIN[0] = 30 #30枚賭け
  COIN[1] = 15
  COIN[2] = 5
  #--------------------------------------------------------------------------
  # ■ 配当 小数第一位まで(掛け金は戻すので-1)
  #--------------------------------------------------------------------------
  # □全て同じ 配当
  SAME = {1=>35}
  # □サイコロ数字(トリプル) 1〜6 配当
  TRIPLE = {1=>215,2=>215,3=>215,4=>215,5=>215,6=>215}
  # □サイコロ数字(ダブル) 1〜6 配当
  DOUBLE = {1=>12.5,2=>12.5,3=>12.5,4=>12.5,5=>12.5,6=>12.5}
  # □合計 4〜17 配当
  TOTAL = {1=>71,2=>35,3=>20.6,4=>13.4,5=>9.3,6=>7.6,7=>7,8=>7,9=>7.6,
  10=>9.3,11=>13.4,12=>20.6,13=>35,14=>71}
  # □ペア 1-2 〜 5-6 配当
  PAIR = {1=>5,2=>5,3=>5,4=>5,5=>5,6=>5,7=>5,8=>5,9=>5,
  10=>5,11=>5,12=>5,13=>5,14=>5,15=>5}
  # □サイコロ数字(シングル) 1個当り/2個/3個 配当
  SINGLE = {1=>1,2=>2.3,3=>13.3}
  # □ small/big 配当
  SIZE = {1=>1,2=>1}
  # ※デフォルト倍率は控除率を排除した倍率です
  #--------------------------------------------------------------------------
  # □大当りの効果音(HIT_ME_MAX)を演奏する獲得コイン数(n以上)
  ME_RATE_MAX = []
  ME_RATE_MAX[0] = 6000
  ME_RATE_MAX[1] = 3000
  ME_RATE_MAX[2] = 1000
  #==============================================================================
  # ■ 文字色設定
  #==============================================================================
  A_COLOR = Color.new(255,255,255,255)     # 通常色
  B_COLOR = Color.new(0,0,0,255)           # 影色
  S_COLOR = Color.new(255,255,0,255)       # システム色
  N_COLOR = Color.new(100,100,100,255)     # 無効色
  #--------------------------------------------------------------------------
  # 選択肢 の文字設定
  #--------------------------------------------------------------------------
  S_SIZE = 22                              # 文字サイズ
  S_BOLD = true                            # 太文字フラグ[true/false]
  S_ITALIC = false                         # 斜め文字フラグ[true/false]
  S_SHADOW = true                          # 影文字フラグ[true/false]
  S_ROUND = false                          # 囲み文字フラグ[true/false]
  S_NAME = ["Georgia","ＭＳ ゴシック"]     # フォント名
  #--------------------------------------------------------------------------
  # Help の文字設定
  #--------------------------------------------------------------------------
  H_SIZE = 16                              # 文字サイズ
  H_BOLD = false                           # 太文字フラグ[true/false]
  H_ITALIC = false                         # 斜め文字フラグ[true/false]
  H_SHADOW = false                         # 影文字フラグ[true/false]
  H_ROUND = false                          # 囲み文字フラグ[true/false]
  H_NAME = ["ＭＳ ゴシック"]               # フォント名
  #--------------------------------------------------------------------------
  # コイン の文字設定
  #--------------------------------------------------------------------------
  C_SIZE = 26                              # 文字サイズ
  C_BOLD = true                            # 太文字フラグ[true/false]
  C_ITALIC = false                         # 斜め文字フラグ[true/false]
  C_SHADOW = false                         # 影文字フラグ[true/false]
  C_ROUND = false                          # 囲み文字フラグ[true/false]
  C_NAME = ["Arial","ＭＳ ゴシック"]       # フォント名
  #--------------------------------------------------------------------------
  # システム の文字設定
  #--------------------------------------------------------------------------
  T_SIZE = 18                              # 文字サイズ
  T_BOLD = true                            # 太文字フラグ[true/false]
  T_ITALIC = false                         # 斜め文字フラグ[true/false]
  T_SHADOW = false                         # 影文字フラグ[true/false]
  T_ROUND = false                          # 囲み文字フラグ[true/false]
  T_NAME = ["Arial","ＭＳ ゴシック"]       # フォント名
  #==============================================================================
  
  #==============================================================================
  S_FONT = Copy_Font.new(S_SIZE,S_BOLD,S_ITALIC,S_SHADOW,S_ROUND,S_NAME,A_COLOR,B_COLOR)
  C_FONT = Copy_Font.new(C_SIZE,C_BOLD,C_ITALIC,C_SHADOW,C_ROUND,C_NAME,A_COLOR,B_COLOR)
  H_FONT = Copy_Font.new(H_SIZE,H_BOLD,H_ITALIC,H_SHADOW,H_ROUND,H_NAME,A_COLOR,B_COLOR)
  T_FONT = Copy_Font.new(T_SIZE,T_BOLD,T_ITALIC,T_SHADOW,T_ROUND,T_NAME,S_COLOR,B_COLOR)
  A_FONT = Copy_Font.new(18,true,false,false,false,["Georgia","ＭＳ ゴシック"],S_COLOR,B_COLOR)
  M_FONT = Copy_Font.new(18,true,false,false,false,["Arial","ＭＳ ゴシック"],A_COLOR,B_COLOR)
end
#==============================================================================
# ■ Scene_SicBo
#==============================================================================
class Scene_SicBo
  include HIDE_SICBO
  #--------------------------------------------------------------------------
  # ■ オブジェクト初期化
  #--------------------------------------------------------------------------
  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_SICBO::BGM))
  end
  #--------------------------------------------------------------------------
  # ■ 競合対策(初期化)
  #--------------------------------------------------------------------------
  def format?
    if $game_party.sicbo_average == nil
      $game_party.sicbo_average = []
    end
    if $game_party.sicbo_draw == nil
      $game_party.sicbo_draw = []
    end
  end
  #--------------------------------------------------------------------------
  # ■ シックボーの初期化
  #--------------------------------------------------------------------------
  def game_reset?
    @sicbo_step = 0
    # □ゲーム実行中フラグをOFF
    @playing = false
  end
  #--------------------------------------------------------------------------
  # ■ メイン処理
  #--------------------------------------------------------------------------
  def main
    # □タイプを取得
    t = $game_temp.sicbo_type
    # □競合対策(初期化)
    format?
    # □初期化
    if $game_party.sicbo_average[t] == nil
      $game_party.sicbo_average[t] = [0]*19
    end
    if $game_party.sicbo_draw[t] == nil
      $game_party.sicbo_draw[t] = false
    end
    # □掛け金を取得
    @coin_rate = HIDE_SICBO::COIN[t]
    #…………………………………………………………………………………………………
    # ■bet画像を取得
    #…………………………………………………………………………………………………
    @bet_pic = RPG::Cache.windowskin(HIDE_SICBO::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
    #…………………………………………………………………………………………………
    # ■文字装飾を取得
    #…………………………………………………………………………………………………
    s_font = HIDE_SICBO::S_FONT ; h_font = HIDE_SICBO::H_FONT
    c_font = HIDE_SICBO::C_FONT ; t_font = HIDE_SICBO::T_FONT
    @a_font = HIDE_SICBO::A_FONT ; @m_font = HIDE_SICBO::M_FONT
    b_font = HIDE_SICBO::T_FONT
    #…………………………………………………………………………………………………
    # ■シックボーウィンドウ背景を作成
    #…………………………………………………………………………………………………
    @sicbo_window_back = Picture_Blink_Cursor.new(RPG::Cache.windowskin(HIDE_SICBO::BACK))
    #…………………………………………………………………………………………………
    # ■当たり演出ウィンドウを作成
    #…………………………………………………………………………………………………
    @sicbo_window_under = Picture_Blink_Cursor.new
    @sicbo_window_under.start(100)
    #…………………………………………………………………………………………………
    # ■シックボーウィンドウ背景(上)を作成
    #…………………………………………………………………………………………………
    bitmap = Bitmap.new(640,480)
    pic = RPG::Cache.windowskin(HIDE_SICBO::TOP)
    bitmap.blt(0,0,pic,Rect.new(0,0,640,360+18))
    bitmap.fill_rect(Rect.new(640-216,358,216,16+10),Color.new(0,0,0,0))
    # □BET/PAY/COIN
    bitmap.blt(640-216,480-120,pic,Rect.new(640-216,360,216,120))
    image = RPG::Cache.windowskin(HIDE_SICBO::NUMBER1)
    bitmap.draw_numbers(558+68,55,0,8,8,image,@coin_rate,2,0,-1,0)
    bitmap.blt(558,41,@bet_pic,Rect.new(7*32,0,32,24))
    @sicbo_window_top = Picture_Blink_Cursor.new(bitmap)
    @sicbo_window_top.z = 100+2
    #…………………………………………………………………………………………………
    # ■betコイン描画ウィンドウを作成
    #…………………………………………………………………………………………………
    @bet_coin_window = Picture_Blink_Cursor.new(Bitmap.new(640,480))
    @bet_coin_window.z = 100+2
    #…………………………………………………………………………………………………
    # ■スコアウィンドウを作成
    #…………………………………………………………………………………………………
    bitmap = Bitmap.new(640,480)
    pic = RPG::Cache.windowskin(HIDE_SICBO::TOP)
    bitmap.blt(0,380-1,pic,Rect.new(0,380-1,640-216,55))
    @sicbo_score_window = Picture_Blink_Cursor.new(bitmap)
    @sicbo_score_window.z = 100+2
    @sicbo_score_window.visible = false
    #…………………………………………………………………………………………………
    # ■ダイス画像の抽出
    #…………………………………………………………………………………………………
    @image = Bitmap.new(21*7,22)
    @image.blt(0,0,pic,Rect.new(0,480-21,21*7,22))
    #…………………………………………………………………………………………………
    # ■コイン数値ウィンドウを作成
    #…………………………………………………………………………………………………
    @coin_window = Window_digits_number.new(492,427,100,$game_party.coin,10,10,c_font)
    #…………………………………………………………………………………………………
    # ■BETコイン数値ウィンドウを作成
    #…………………………………………………………………………………………………
    @bet_coin = 0
    @total_bet_coin_window = Window_digits_number.new(492,427-79,100,@bet_coin,10,10,c_font)
    #…………………………………………………………………………………………………
    # ■配当コイン数値ウィンドウを作成
    #…………………………………………………………………………………………………
    @payout = 0
    @payout_coin_window = Window_digits_number.new(492,325+60,100,@payout,10,10,c_font)
    #…………………………………………………………………………………………………
    # ■ゲーム開始選択ウィンドウを作成
    #…………………………………………………………………………………………………
    select = RPG::Cache.windowskin(HIDE_SICBO::SELECT)
    icon = RPG::Cache.windowskin(HIDE_SICBO::CURSOR)
    com = HIDE_SICBO::GAME_COMS
    helps = HIDE_SICBO::GAME_HELPS
    if HIDE_SICBO::AVERAGE && com.size == 3
      com.push(HIDE_SICBO::WORD0)
      helps.push(HIDE_SICBO::A_HELP)
    end
    @game_select_window = Picture_Blink_Cursor.new(16,420+16,96,32,2,0,helps.size,helps.size)
    @game_select_window.key = 0
    @game_select_window.draw_cursor(select,nil,nil,icon)
    @game_select_window.draw_item(com,s_font)
    @game_select_window.start
    # □ヘルプウィンドウの関連付け
    @game_select_window.make_helps(16+4,356+16+32,helps,h_font)
    #…………………………………………………………………………………………………
    # ■bet(配当)選択/betコイン描画ウィンドウを作成
    #…………………………………………………………………………………………………
    com = ["Same","Triple","Double","Total","Pair","Single","Size","Clear"]
    helps = ["3個の賽が全て同じ数字の場合に賭けます。",
    "3個の賽が全て同じ1つの数字である事に賭けます。",
    "3個の賽のうち2個が1つの数字である事に賭けます。",
    "3個の賽の合計に賭けます。",
    "3個の賽のうち2個以上の賽の組み合わせに賭けます。",
    "賽に出る1つの数字に賭けます。",
    "3個の賽の合計が高い/低いに賭けます。","全てのbetを戻します。"]
    @bet_select_window = Picture_Blink_Cursor.new(16,420+16-32,96,32,2,0,8,4)
    @bet_select_window.key = 0
    @bet_select_window.draw_cursor(select,nil,nil,icon)
    @bet_select_window.draw_item(com,s_font)
    # □ヘルプウィンドウの関連付け
    @bet_select_window.make_helps(16+4,420+16-64,helps,h_font)
    #…………………………………………………………………………………………………
    # ■DICEを作成
    #…………………………………………………………………………………………………
    @play_dice = []
    for i in 0...3
      @play_dice[i] = Window_Play_Dice.new(16+i*69,354,100+5)
      @play_dice[i].active = true
      @play_dice[i].turn(0,1)
      @play_dice[i].active = false
      @play_dice[i].visible = true
      # □デバッグ(サイコロ数字を直接指定)
      if HIDE_SICBO::DEBUG
        @play_dice[i].debug = HIDE_SICBO::DEBUG
        @play_dice[i].debug_number = HIDE_SICBO::DEBUG_DICE[i]
      end
    end
    # □Pair配列を取得
    @pair_nums = [[1,2],[1,3],[1,4],[1,5],[1,6],
    [2,3],[2,4],[2,5],[2,6],[3,4],[3,5],[3,6],[4,5],[4,6],[5,6]]    
    # □SICBO履歴の描画
    average?
    # □賭け金の初期化
    bet_clear?
    # □倍率を描画
    draw_rate
    # □初期化
    refresh
    # □選択肢の文字色を初期化
    exchange_colors?
    # トランジション実行
    Graphics.transition
    # メインループ
    loop do
      # ゲーム画面を更新
      Graphics.update
      # 入力情報を更新
      Input.update
      # フレーム更新
      update
      # 画面が切り替わったらループを中断
      if $scene != self
        break
      end
    end
    # トランジション準備
    Graphics.freeze
    # ウィンドウを解放
    @sicbo_window_back.dispose
    @sicbo_window_top.dispose
    @sicbo_window_under.dispose
    @sicbo_score_window.dispose
    @game_select_window.dispose
    @bet_select_window.dispose
    @coin_window.dispose
    @total_bet_coin_window.dispose
    @bet_coin_window.dispose
    @payout_coin_window.dispose
    if @average_window != nil
      @average_window.dispose
    end
    @play_dice.each{|a| a.dispose }
  end
  #--------------------------------------------------------------------------
  # ■ 倍率を描画
  #--------------------------------------------------------------------------
  def draw_rate
    image = RPG::Cache.windowskin(HIDE_SICBO::NUMBER1)
    #…………………………………………………………………………………………………
    # ■ Same
    #…………………………………………………………………………………………………
    @sicbo_window_top.bitmap.draw_numbers(285,39-10,69,8,8,image,@rate[1][1],1,1,-1,0,1,0,[13])
    #…………………………………………………………………………………………………
    # ■ Triple
    #…………………………………………………………………………………………………
    @sicbo_window_top.bitmap.draw_numbers(210,38,72,8,8,image,@rate[2][1],1,2,-1,0,1,0,[13])
    @sicbo_window_top.bitmap.draw_numbers(358,38,72,8,8,image,@rate[2][1],1,2,-1,0,1,0,[13])
    #…………………………………………………………………………………………………
    # ■ Double
    #…………………………………………………………………………………………………
    @sicbo_window_top.bitmap.draw_numbers(90,38,116,8,8,image,@rate[3][1],1,3,-1,0,1,0,[13])
    @sicbo_window_top.bitmap.draw_numbers(433,38,116,8,8,image,@rate[3][1],1,3,-1,0,1,0,[13])
    #…………………………………………………………………………………………………
    # ■ Total
    #…………………………………………………………………………………………………
    for i in 0...14
      @sicbo_window_top.bitmap.draw_numbers(27+i*42,173-10,38,8,8,image,@rate[4][i+1],1,4,-1,0,1,0,[13])
    end
    #…………………………………………………………………………………………………
    # ■ Pair
    #…………………………………………………………………………………………………
    for i in 0...15
      @sicbo_window_top.bitmap.draw_numbers(7+i*42,228-10,38,8,8,image,@rate[5][i+1],1,5,-1,0,1,0,[13])
    end
    #…………………………………………………………………………………………………
    # ■ Single(on1 2 3)
    #…………………………………………………………………………………………………
    for i in 0...3
      @sicbo_window_top.bitmap.draw_numbers(140+i*196,319-10,0,8,8,image,@rate[8][i+1],0,6,-1,0,1,0,[13])
    end
    #…………………………………………………………………………………………………
    # ■ Size
    #…………………………………………………………………………………………………
    @sicbo_window_top.bitmap.draw_numbers(7,68,79,8,8,image,@rate[7][1],1,7,-1,0,1,0,[13])
    @sicbo_window_top.bitmap.draw_numbers(553,68,79,8,8,image,@rate[7][2],1,7,-1,0,1,0,[13])
  end
  #--------------------------------------------------------------------------
  # ■ 初期化
  #--------------------------------------------------------------------------
  def refresh
    @sicbo_step = 0
    @move = false
  end
  #--------------------------------------------------------------------------
  # ■ 賭け金の初期化
  #--------------------------------------------------------------------------
  def bet_clear?
    @old_n1 = nil ; @old_n2 = nil
    @old_min = nil ; @old_max = nil
    @old_s = nil ; @old_b = nil
    @bet_coin = 0 ; @payout = 0
    @bet_point = {}
    @rate = {}
    #…………………………………………………………………………………………………
    # ■ Same
    #…………………………………………………………………………………………………
    @bet_point[1] = {1=>0}
    @rate[1] = HIDE_SICBO::SAME
    #…………………………………………………………………………………………………
    # ■ Triple
    #…………………………………………………………………………………………………
    @bet_point[2] = {1=>0,2=>0,3=>0,4=>0,5=>0,6=>0}
    @rate[2] = HIDE_SICBO::TRIPLE
    #…………………………………………………………………………………………………
    # ■ Double
    #…………………………………………………………………………………………………
    @bet_point[3] = {1=>0,2=>0,3=>0,4=>0,5=>0,6=>0}
    @rate[3] = HIDE_SICBO::DOUBLE
    #…………………………………………………………………………………………………
    # ■ Total
    #…………………………………………………………………………………………………
    @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,12=>0,13=>0,14=>0}
    @rate[4] = HIDE_SICBO::TOTAL
    #…………………………………………………………………………………………………
    # ■ Pair
    #…………………………………………………………………………………………………
    @bet_point[5] = {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}
    @rate[5] = HIDE_SICBO::PAIR
    #…………………………………………………………………………………………………
    # ■ Single
    #…………………………………………………………………………………………………
    @bet_point[6] = {1=>0,2=>0,3=>0,4=>0,5=>0,6=>0}
    @rate[8] = HIDE_SICBO::SINGLE
    s = @rate[8][1]
    @rate[6] = {1=>s,2=>s,3=>s,4=>s,5=>s,6=>s}
    #…………………………………………………………………………………………………
    # ■ Size
    #…………………………………………………………………………………………………
    @bet_point[7] = {1=>0,2=>0}
    @rate[7] = HIDE_SICBO::SIZE
    @bet_coin_window.bitmap.clear
    # □選択肢の文字色を初期化
    exchange_colors?
  end
  #--------------------------------------------------------------------------
  # ■ 選択肢の色更新
  #--------------------------------------------------------------------------
  def exchange_colors?
    @game_select_window.exchange[0] = $game_party.coin < @coin_rate
    @game_select_window.exchange[1] = @bet_coin == 0
    @game_select_window.refresh
  end
  #--------------------------------------------------------------------------
  # ■ キーヘルプを描画
  #--------------------------------------------------------------------------
  def draw_key?(d = true)
    pic = RPG::Cache.windowskin(HIDE_SICBO::BET)
    for i in 0..3
      @bet_coin_window.bitmap.fill_rect(Rect.new(16+i*32,456,32,24),Color.new(0,0,0,0))
      if d
        @bet_coin_window.bitmap.blt(16+i*32,456,pic,Rect.new(7*32,24*5+i*24,32,24))
      end
    end
  end
  #--------------------------------------------------------------------------
  # ■ ゲームの終了
  #--------------------------------------------------------------------------
  def sicbo_end
    unless @playing
      # □シックボー開始前の BGM に戻す
      $game_system.bgm_play($game_temp.map_bgm)
      # マップ画面に切り替え
      $scene = Scene_Map.new
      return
    end
  end
  #--------------------------------------------------------------------------
  # ■ ウィンドウを作成
  #--------------------------------------------------------------------------
  def make_b_window
    if @make_b_window
      return
    end
    icon = RPG::Cache.windowskin(HIDE_SICBO::CURSOR)
    #…………………………………………………………………………………………………
    # ■文字装飾を取得
    #…………………………………………………………………………………………………
    h_font = HIDE_SICBO::H_FONT
    @bet_table_window = [] ; helps = []
    #…………………………………………………………………………………………………
    # ■ Same
    #…………………………………………………………………………………………………
    @bet_table_window[0] = Picture_Blink_Cursor.new(285,32+7,69,123,0,0,1,1)
    helps[0] = ["3個の賽が全て同じ数字を選択します。"]
    #…………………………………………………………………………………………………
    # ■Triple
    #…………………………………………………………………………………………………
    @bet_table_window[1] = Picture_Blink_Cursor.new(210,48,72,35,38,2,6,2)
    helps[1] = [] ; nums = [1,4,2,5,3,6]
    for i in 0...6
      helps[1].push("3個の賽が全て【" + nums[i].to_s + "】を選択します。")
    end
    #…………………………………………………………………………………………………
    # ■Double
    #…………………………………………………………………………………………………
    @bet_table_window[2] = Picture_Blink_Cursor.new(90,48,116,35,113.5,2,6,2)
    helps[2] = []
    for i in 0...6
      helps[2].push("3個の賽のうち【" + nums[i].to_s + "】が2個以上を選択します。")
    end
    #…………………………………………………………………………………………………
    # ■Total
    #…………………………………………………………………………………………………
    @bet_table_window[3] = Picture_Blink_Cursor.new(27,173,38,43,2,0,14,14)
    helps[3] = []
    for i in 0...14
      helps[3].push("3個の賽の合計が" + (i+4).to_s + "の場合を選択します。")
    end
    #…………………………………………………………………………………………………
    # ■Pair
    #…………………………………………………………………………………………………
    @bet_table_window[4] = Picture_Blink_Cursor.new(7,228,38,79,2,0,15,15)
    helps[4] = []
    for i in 0...15
      helps[4].push("数字の【" + @pair_nums[i][0].to_s + "】" + 
      "＆【" + @pair_nums[i][1].to_s + "】の組み合わせを選択します。")
    end
    #…………………………………………………………………………………………………
    # ■Single
    #…………………………………………………………………………………………………
    @bet_table_window[5] = Picture_Blink_Cursor.new(27,319,94,35,2,0,6,6)
    helps[5] = []
    for i in 0...6
      helps[5].push("【" + (i+1).to_s + "】の数字を選択します。")
    end
    #…………………………………………………………………………………………………
    # ■Size
    #…………………………………………………………………………………………………
    @bet_table_window[6] = Picture_Blink_Cursor.new(7,78,79,82,233.5,0,2,2)
    helps[6] = ["3個の賽の合計が4〜10の場合を選択します。",
    "3個の賽の合計が11〜17の場合を選択します。"]
    for i in 0...@bet_table_window.size
      @bet_table_window[i].draw_icon_cursor(icon,10)
      @bet_table_window[i].cz = 2
      @bet_table_window[i].draw_color_cursor(@select_colors[i])
      # □ヘルプウィンドウの関連付け
      @bet_table_window[i].make_helps(16+4,420+16-64,helps[i],h_font)
    end
    @make_b_window = true
  end
  #--------------------------------------------------------------------------
  # ■ SICBO履歴の描画
  #--------------------------------------------------------------------------
  def average?
    t = $game_temp.sicbo_type
    if @average_window == nil
      @average_window = Picture_Blink_Cursor.new(Bitmap.new(640,480))
      @average_window.z = 100+2
    end
    @average_window.visible = true
    #…………………………………………………………………………………………………
    # ■スピン回数を描画
    #…………………………………………………………………………………………………
    t = $game_temp.sicbo_type
    a = $game_party.sicbo_average[t]
    v = [a[0],999999].min
    image = RPG::Cache.windowskin(HIDE_SICBO::NUMBER1)
    @sicbo_window_top.bitmap.draw_numbers(80,55,0,8,8,image,v,2,0,-1,0)
    if @sicbo_step == 2
      return
    end
    #…………………………………………………………………………………………………
    # ■確率を描画
    #…………………………………………………………………………………………………
    @average_window.bitmap.clear
    @average = [[],[],[]]
      # □確率を取得
    if $game_party.sicbo_draw[t]
      for i in 1...$game_party.sicbo_average[t].size
        c = i-1
        e = $game_party.sicbo_average[t][i]
        s = $game_party.sicbo_average[t][0]
        n = s == 0 ? 0 : ((e * 100.00 / s) * 100).floor / 100.00
        @average[c/6][c%6] = n
      end
      # □確率を描画
      for i in 1...$game_party.sicbo_average[t].size
        c = i-1
        n = @average[c/6][c%6]
        d = (n == 100) ? 1 : 2
        color = 0
        if n == @average[c/6].max && @average[c/6] != [0]*6
          color = 9
        elsif n == @average[c/6].min && @average[c/6] != [0]*6
          color = 8
        end
        @average_window.bitmap.draw_numbers(67+(c%6)*98,319+(c/6)*8,60,8,8,image,n,2,color,-1,0,d,d,[],[15])
      end
    end
    #…………………………………………………………………………………………………
    # ■1.2.3/合計を描画
    #…………………………………………………………………………………………………
    image2 = RPG::Cache.windowskin(HIDE_SICBO::NUMBER2)
    for i in 0...@play_dice.size
      n = @play_dice[i].stop ? @play_dice[i].number : 0
      @sicbo_score_window.bitmap.draw_numbers(268+i*42-14,416,0,12,12,image2,n,2,0,0,1)
      @sicbo_score_window.bitmap.fill_rect(Rect.new(246+i*42-14,394,21,22),Color.new(0,0,0,0))
      @sicbo_score_window.draw_picture(@image,246+i*42-14,394,Rect.new(n*21,0,21,22))
    end
    total = @play_dice[i].stop ? @play_dice[0].number + @play_dice[1].number + @play_dice[2].number : 0
    @sicbo_score_window.bitmap.draw_numbers(268+42*3+14,416,0,12,12,image2,total,2,0,0,1)
  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
  #--------------------------------------------------------------------------
  # ■ コインを描画/合計betの取得
  #--------------------------------------------------------------------------
  def draw_coin?(n)
    t = $game_temp.sicbo_type
    max_n = [HIDE_SICBO::MAX_BET,15].min
    a = @bet_point
    i0 = max_n
    i = @bet_select_window.index + 1
    index = @bet_table_window[i-1].index + 1
    old_point = @bet_point[i][index]
    point = @bet_point[i][index]
      case n
      when 1,-1 # ±1
        point = point + n
        if point > max_n or point < 0
          point = 0
        end
      when 0 # 初期化
        point = 0
      when 15 # Max賭け
        i0 = ($game_party.coin - @bet_coin)/@coin_rate
        point = i0 > max_n ? max_n : i0
      end
      a[i][index] = point
      b = bet_coin?(a)
      # □所持コインより多い場合
      if b > $game_party.coin
        point -= i0
        if point > i0 or point < 0
          point = 0
        end
        a[i][index] = point
      end
      if old_point == point
        # □ブザーを演奏
        $game_system.se_play(RPG::AudioFile.new(HIDE_SICBO::BUZZER_SE))
      else
        # □SEを演奏
        $game_system.se_play(RPG::AudioFile.new(HIDE_SICBO::BED_SE))
      end
      @bet_point = a
      @bet_coin = bet_coin?(@bet_point)
      # □選択肢の色更新(Spin)
      exchange_colors?
      x = @bet_table_window[i-1].window_x(index-1)
      y = @bet_table_window[i-1].window_y(index-1)
      w = @bet_table_window[i-1].width
      h = @bet_table_window[i-1].height
      x += (w/2)
      y += (h/2)
    case i
    when 1
      y -= 14
    when 2,3
      y -= 2
    when 4
      y -= 5
    when 5
      y -= 13
    when 6
      x += 11
      y -= 3
    end
    # □透明に塗りつぶし
    @bet_coin_window.bitmap.fill_rect(Rect.new(x-16,y-12,32,24),Color.new(0,0,0,0))
    pic = RPG::Cache.windowskin(HIDE_SICBO::BET)
    @bet_coin_window.bitmap.blt(x-16,y-12,pic,Rect.new((i-1)*32,24 * (point-1),32,24))
    if HIDE_SICBO::HELP
      # □Max/Minの取得
      win = win?
      max = win[0] ; min = win[3]
      max_win = win[2] ; min_win = win[5]
      # □獲得COINが0の場合、非表示
      if max.max == 0
        @bet_coin_window.bitmap.fill_rect(Rect.new(268,358,160,16),Color.new(0,0,0,0))
        @old_n1 = nil ; @old_n2 = nil
        @old_min = nil ; @old_max = nil
        @old_s = nil ; @old_b = nil
        return
      end
      image = RPG::Cache.windowskin(HIDE_SICBO::NUMBER1)
      # □Min獲得COIN
      n = ((min_win * 100.00 / 216) * 100).floor / 100.00
      if @old_min != min && n != 0
        @bet_coin_window.bitmap.draw_numbers(272+76,358,80,8,8,image,min.min,2,0,-1,0)
        @old_min = min
      else
        @old_min = min
        @bet_coin_window.bitmap.fill_rect(Rect.new(272,358,160,8),Color.new(0,0,0,0))
      end
      # □Min勝率
      if @old_n1 != n && n != 0
        @bet_coin_window.bitmap.draw_numbers(272+138,358,40,8,8,image,n,2,8,-1,0,2,2,[],[15])
        @old_n1 = n
      else
        @old_n1 = n
      end
      # □Max獲得COIN
      n = ((max_win * 100.00 / 216) * 100).floor / 100.00
      if @old_max != max
        @bet_coin_window.bitmap.draw_numbers(272+76,358+8,80,8,8,image,max.max,2,0,-1,0)
        @old_max = max
      end
      # □Max勝率
      if @old_n2 != n
        @bet_coin_window.bitmap.draw_numbers(272+138,358+8,40,8,8,image,n,2,9,-1,0,2,2,[],[15])
        @old_n2 = n
      end
    end
  end
  #--------------------------------------------------------------------------
  # ■ Max/Minの取得
  #--------------------------------------------------------------------------
  def win?
    num = [] ; win = [] ; @old_abc = []
    for a in 1..6
      for b in 1..6
        for c in 1..6
          abc = [a,b,c].sort
          if @old_abc.include?(abc)
            index = @old_abc.index(abc)
            n = win[index]
          else
            n = sicbo_hit(abc,true)
          end
          @old_abc.push(abc)
          win.push(n)
          num.push(abc[0]*100+abc[1]*10+abc[2])
        end
      end
    end
    max_num = [] ; min_num = [] ; max = [] ; min = []
    for i in 0...win.size
      if win[i] == win.max
        max.push(win[i])
        max_num.push(num[i])
      end
      if win[i] != win.max && win[i] != 0
        min.push(win[i])
        min_num.push(num[i])
      end
    end
    t = max.size + min.size
    s = 0
    for i in 0...min.size
      if min[i] == min.min
        s += 1
      end
    end
    b = max.size
    return [max.uniq,max_num.uniq,b,min.uniq,min_num.uniq,s,t]
  end
  #--------------------------------------------------------------------------
  # ■ 更新
  #--------------------------------------------------------------------------
  def coin_update?
    # □ 回転数値の更新(所持コイン)の更新
    @coin_window.update($game_party.coin)
    # □配当コイン数値ウィンドウの更新
    @payout_coin_window.refresh(@payout)
    # □BETコイン数値ウィンドウの更新
    @total_bet_coin_window.refresh(@bet_coin)
    # □ダイスの更新
    @play_dice.each{|a| a.turn }
    @play_dice.each{|a| a.update }
  end
  #--------------------------------------------------------------------------
  # ■ フレーム更新
  #--------------------------------------------------------------------------
  def update
    @play_dice.each{|a| a.visible = @game_select_window.visible }
    @sicbo_score_window.visible = @game_select_window.visible == true && 
    @game_select_window.index == 1
    #…………………………………………………………………………………………………
    # ■ 更新
    #…………………………………………………………………………………………………
    coin_update?
    #…………………………………………………………………………………………………
    # ■ 当りの演出を更新
    #…………………………………………………………………………………………………
    @sicbo_window_under.update
    #…………………………………………………………………………………………………
    # ■ BET選択ウィンドウの更新
    #…………………………………………………………………………………………………
    if @make_b_window && @bet_select_window.index != 7
      i = @bet_select_window.index
      if @bet_table_window[i].active
        @bet_table_window[i].update
        update_bet
        return
      end
    end
    #…………………………………………………………………………………………………
    # ■ BETカテゴリー選択の更新
    #…………………………………………………………………………………………………
    if @bet_select_window.active
      @bet_select_window.update
      update_bet_select
      return
    end
    #…………………………………………………………………………………………………
    # ■ ゲーム開始ウィンドウの更新
    #…………………………………………………………………………………………………
    if @game_select_window.active
      @game_select_window.update
      update_select
      return
    end
    #…………………………………………………………………………………………………
    # ■ ゲームの流れ
    #…………………………………………………………………………………………………
    case @sicbo_step
    when 1
      # □コインを減らす(賭け金)
      if $game_party.coin >= @bet_coin
        $game_party.lose_coin(@bet_coin)
        # □カード選択色を変更
        exchange_colors?
        @playing = true
        @sicbo_step = 2
        return
      else
        # □ブザー SE を演奏
        $game_system.se_play(RPG::AudioFile.new(HIDE_SICBO::BUZZER_SE))
        @sicbo_step = 0
        @playing = false
        return
      end
    when 2
      t = $game_temp.sicbo_type
      $game_party.sicbo_average[t][0] += 1
      @play_dice.each{|a| a.reset }
      average?
      @play_dice.each{|a| a.active = true }
      @time = 30 + rand(3)
      @sicbo_step = 3
      return
    when 3
      # □待ち時間
      while @time > 0
        # ゲーム画面を更新
        coin_update? ; Graphics.update
        @time -= 1
      end
      @play_dice[0].stop = true
      @sicbo_step = 4
      return
    when 4
      unless @play_dice[0].active
        n = @play_dice[0].number
        t = $game_temp.sicbo_type
        $game_party.sicbo_average[t][n] += 1
        @time = 8 + rand(3)
        @sicbo_step = 5
        return
      end
    when 5
      # □待ち時間
      while @time > 0
        # ゲーム画面を更新
        coin_update? ; Graphics.update
        @time -= 1
      end
      @play_dice[1].stop = true
      @sicbo_step = 6
      return
    when 6
      unless @play_dice[1].active
        n = @play_dice[1].number + 6
        t = $game_temp.sicbo_type
        $game_party.sicbo_average[t][n] += 1
        @time = 8 + rand(3)
        @sicbo_step = 7
        return
      end
    when 7
      # □待ち時間
      while @time > 0
        # ゲーム画面を更新
        coin_update? ; Graphics.update
        @time -= 1
      end
      @play_dice[2].stop = true
      @sicbo_step = 8
      return
    when 8
      unless @play_dice[2].active
        n = @play_dice[2].number + 12
        t = $game_temp.sicbo_type
        $game_party.sicbo_average[t][n] += 1
        average?
        @time = 12
        @sicbo_step = 9
        return
      end
    when 9
      # □当たりの処理
      sicbo_hit
      return
    when 10
      @play_dice.each{|a| a.stop = false }
      @game_select_window.active = true
      # □シックボーの初期化
      sicbo_reset?
      return
    end
  end
  #--------------------------------------------------------------------------
  # ■ サイコロのグループ化
  #--------------------------------------------------------------------------
  def triple?(numbers)
    group = {0=>false,1=>0,2=>0,3=>0,4=>0,5=>0,6=>0}
    for i in numbers
      unless group[i].is_a?(Numeric)
        p "Error!" ;Error!
      end
      group[i] += 1
      if group[i] == 3
        group[0] = true
      end
    end
    return group
  end
  #--------------------------------------------------------------------------
  # ■ 当たりの点滅を描画
  #--------------------------------------------------------------------------
  def hit_color?(i,n,type,win = false)
    if win
      return
    end
    c = type ? @select_colors[i] : Color.new(255,255,255,255)
    x = @bet_table_window[i].window_x(n)
    y = @bet_table_window[i].window_y(n)
    w = @bet_table_window[i].width
    h = @bet_table_window[i].height
    @sicbo_window_under.bitmap.fill_rect(Rect.new(x,y,w,h),c)
  end
  #--------------------------------------------------------------------------
  # ■ 当たりの処理(WINの取得)
  #--------------------------------------------------------------------------
  def sicbo_hit(numbers = [@play_dice[0].number,@play_dice[1].number,@play_dice[2].number],win = false)
    unless win
      # □当たりの出たレートを点滅
      @sicbo_window_under.bitmap.clear
    end
    @payout = 0
    gain = 0 ; rate = 0
    total = numbers[0] + numbers[1] + numbers[2]
    group = triple?(numbers)
    numbers = numbers.uniq
    for i in @bet_point.keys
      for n in @bet_point[i].keys
        type = @bet_point[i][n] > 0
        case i # Same
        when 1
          if group[0]
            hit_color?(i-1,n-1,type,win)
            gain += (@bet_point[i][n] * @coin_rate * (@rate[i][n] + 1))
          end
        when 2 # Triple
          if numbers.include?(n) && group[n] == 3
            # □カーソルindexの位置補正
            b = [0,2,4,1,3,5]
            n2 = b[n-1] + 1
            type = @bet_point[i][n2] > 0
            hit_color?(i-1,b[n-1],type,win)
            gain += (@bet_point[i][n2] * @coin_rate * (@rate[i][n2] + 1))
          end
        when 3 # Double
          if numbers.include?(n) && (group[n] == 2 or group[n] == 3)
            # □カーソルindexの位置補正
            b = [0,2,4,1,3,5]
            n2 = b[n-1] + 1
            type = @bet_point[i][n2] > 0
            hit_color?(i-1,b[n-1],type,win)
            gain += (@bet_point[i][n2] * @coin_rate * (@rate[i][n2] + 1))
          end
        when 4 # Total
          if total == n + 3
            hit_color?(i-1,n-1,type,win)
            gain += (@bet_point[i][n] * @coin_rate * (@rate[i][n] + 1))
          end
        when 5 # Pair
          a = numbers.sort
          a = a.uniq
          b = @pair_nums[n-1]
          if (a & b).size == (b & b).size
            hit_color?(i-1,n-1,type,win)
            gain += (@bet_point[i][n] * @coin_rate * (@rate[i][n] + 1))
          end
        when 6 # Single
          if numbers.include?(n)
            if group[n] == 3
                hit_color?(i-1,n-1,type,win)
                gain += (@bet_point[i][n] * @coin_rate * (@rate[8][3] + 1))
              elsif group[n] == 2
                hit_color?(i-1,n-1,type,win)
                gain += (@bet_point[i][n] * @coin_rate * (@rate[8][2] + 1))
              else
                hit_color?(i-1,n-1,type,win)
                gain += (@bet_point[i][n] * @coin_rate * (@rate[i][n] + 1))
              end
            end
        when 7 # Size
          case n
          when 1
            if total >=4 && total <=10
              hit_color?(i-1,n-1,type,win)
              gain += (@bet_point[i][n] * @coin_rate * (@rate[i][n] + 1))
            end
          when 2
            if total >=11 && total <=17
              hit_color?(i-1,n-1,type,win)
              gain += (@bet_point[i][n] * @coin_rate * (@rate[i][n] + 1))
            end
          end
        end
      end
    end
    # □整数化
    gain = gain.floor
    payout = [gain - @bet_coin,0].max
    if win
      return payout
    end
    @payout = gain
    @payout_coin_window.refresh(@payout)
    #…………………………………………………………………………………………………
    # ■ 所持コインを増やす
    #…………………………………………………………………………………………………
    $game_party.gain_coin(gain)
    time_up = 2
    if @payout > 0 && @payout > @bet_coin
      # □大当たりの場合
      if payout >= HIDE_SICBO::ME_RATE_MAX[$game_temp.sicbo_type]
        $game_system.me_play(RPG::AudioFile.new(HIDE_SICBO::HIT_ME_MAX))
        # □次のゲーム開始まで待つ(MEの演奏時間)
        time_up = HIDE_SICBO::ME_MAX_TIME
      else
        $game_system.me_play(RPG::AudioFile.new(HIDE_SICBO::HIT_ME))
        # □次のゲーム開始まで待つ(MEの演奏時間)
        time_up = HIDE_SICBO::ME_TIME
      end
    end
    #…………………………………………………………………………………………………
    # ■ 所持コインがBETを下回った場合初期化
    #…………………………………………………………………………………………………
    if $game_party.coin < @bet_coin
      # □賭け金の初期化
      bet_clear?
      @bet_coin = 0
    end
    #…………………………………………………………………………………………………
    # ■ 次の開始まで待つ
    #…………………………………………………………………………………………………
    @sicbo_window_under.blink_start
    time = 0
    while @sicbo_window_under.blink_active
      # □ゲーム画面を更新
      coin_update? ; Graphics.update
      # □回転数値の更新(所持コイン)
      @coin_window.update($game_party.coin)
      # □当りの演出を更新
      if time < time_up
        if @sicbo_window_under.count?
          time += 1
        end
        @sicbo_window_under.update
      else
        @sicbo_window_under.blink_end
      end
    end
    # □選択色を変更
    exchange_colors?
    @sicbo_step = 10
  end
  #--------------------------------------------------------------------------
  # ■ フレーム更新(BET選択)
  #--------------------------------------------------------------------------
  def update_bet
    #…………………………………………………………………………………………………
    # ■ C ボタンが押された場合
    #…………………………………………………………………………………………………
    if Input.repeat?(Input::C)
      draw_coin?(1)
    end
    #…………………………………………………………………………………………………
    # ■ A ボタンが押された場合
    #…………………………………………………………………………………………………
    if Input.repeat?(Input::A)
      draw_coin?(-1)
    end
    #…………………………………………………………………………………………………
    # ■ R ボタンが押された場合
    #…………………………………………………………………………………………………
    if Input.trigger?(Input::R)
      draw_coin?(15)
    end
    #…………………………………………………………………………………………………
    # ■ L ボタンが押された場合
    #…………………………………………………………………………………………………
    if Input.trigger?(Input::L)
      draw_coin?(0)
    end
    #…………………………………………………………………………………………………
    # ■ B ボタンが押された場合
    #…………………………………………………………………………………………………
    if Input.trigger?(Input::B)
      i = @bet_select_window.index
      # □キャンセルSEを演奏
      $game_system.se_play(RPG::AudioFile.new(HIDE_SICBO::CANCEL_SE))
      @bet_table_window[i].active = false
      @bet_table_window[i].visible = false
      @bet_select_window.active = true
      @bet_select_window.visible = true
      draw_key?(false)
      return
    end
  end
  #--------------------------------------------------------------------------
  # ■ フレーム更新(BETカテゴリー選択)
  #--------------------------------------------------------------------------
  def update_bet_select
    #…………………………………………………………………………………………………
    # ■ C ボタンが押された場合
    #…………………………………………………………………………………………………
    if Input.trigger?(Input::C)
      unless @move
        # □決定SEを演奏
        $game_system.se_play(RPG::AudioFile.new(HIDE_SICBO::DECISION_SE))
        i = @bet_select_window.index
        make_b_window
        @bet_table_window.each{|a| a.active = false }
        @bet_table_window.each{|a| a.visible = false }
        # □Clear
        if i == 7
          # □賭け金の初期化
          bet_clear?
          @bet_coin = 0
        else
          @bet_select_window.active = false
          @bet_table_window[i].active = true
          @bet_table_window[i].visible = true
          @bet_table_window[i].start(100+1)
          draw_key?
        end
      end
    end
    #…………………………………………………………………………………………………
    # ■ B ボタンが押された場合
    #…………………………………………………………………………………………………
    if Input.trigger?(Input::B)
      unless @move
        # □キャンセルSEを演奏
        $game_system.se_play(RPG::AudioFile.new(HIDE_SICBO::CANCEL_SE))
        @bet_select_window.active = false
        @bet_select_window.visible = false
        @game_select_window.active = true
        @game_select_window.visible = true
      end
      return
    end
  end
  #--------------------------------------------------------------------------
  # ■ フレーム更新(ゲーム開始)
  #--------------------------------------------------------------------------
  def update_select
    #…………………………………………………………………………………………………
    # ■ C ボタンが押された場合
    #…………………………………………………………………………………………………
    if Input.trigger?(Input::C)
      unless @move
        case @game_select_window.index
        when 0 #□賭け金を設定
          if $game_party.coin < @coin_rate
            # □ブザー SE を演奏
            $game_system.se_play(RPG::AudioFile.new(HIDE_SICBO::BUZZER_SE))
            return
          end
          # □決定SEを演奏
          $game_system.se_play(RPG::AudioFile.new(HIDE_SICBO::DECISION_SE))
          @game_select_window.active = false
          @game_select_window.visible = false
          @bet_select_window.index = 0
          @bet_select_window.active = true
          @bet_select_window.visible = true
          return
        when 1 #□ゲーム開始
          # □コインが足りない/betが0の場合
          if @bet_coin == 0 or $game_party.coin < @coin_rate
            # □ブザーを演奏
            $game_system.se_play(RPG::AudioFile.new(HIDE_SICBO::BUZZER_SE))
            return
          end
          # □決定SEを演奏
          $game_system.se_play(RPG::AudioFile.new(HIDE_SICBO::DECISION_SE))
          @game_select_window.active = false
          @payout = 0
          average?
          @sicbo_step = 1
        when 2 # □終了
          # □決定SEを演奏
          $game_system.se_play(RPG::AudioFile.new(HIDE_SICBO::DECISION_SE))
          sicbo_end
        when 3 # □履歴の表示
          # □決定SEを演奏
          $game_system.se_play(RPG::AudioFile.new(HIDE_SICBO::DECISION_SE))
          t = $game_temp.sicbo_type
          $game_party.sicbo_draw[t] ^= true
          average?
        end
      end
      return
    end
    #…………………………………………………………………………………………………
    # ■ B ボタンが押された場合
    #…………………………………………………………………………………………………
    if Input.trigger?(Input::B)
      # □キャンセルSEを演奏
      $game_system.se_play(RPG::AudioFile.new(HIDE_SICBO::CANCEL_SE))
      @playing = false
      sicbo_end
      return
    end
  end
  #--------------------------------------------------------------------------
  # ■ シックボーの初期化
  #--------------------------------------------------------------------------
  def sicbo_reset?
    if $game_party.coin < @bet_coin
      # □賭け金の初期化
      bet_clear?
      @bet_coin = 0
    end
    # □選択肢の文字色を初期化
    exchange_colors?
    # □初期化
    refresh
    @sicbo_step = 0
    @playing = false
    @game_select_window.active = true
  end
end