#==============================================================================
# ■ Poker_Game vol.6.00
#------------------------------------------------------------------------------
# ※『Window_digits_number 5.90以上』(必須)
# ※『Picture_Blink_Cursor 1.40以上』(必須)
# ※『Window_Play_Cards 1.00以上』(必須)
# ※『Coin_Base 1.00以上』(必須)より下に挿入
# 12/03/03
#==============================================================================
module HIDE_POKER
  #==============================================================================
  # ■ デバッグ(開発者用)
  #==============================================================================
  DEBUG = false                    # [true/false]
  DEBUG_CARD =  {}                 # {0=>1,1=>0,2=>11,3=>12,4=>13}
  #==============================================================================
  # ■ イベントコマンド『スクリプト』に以下を追加
  #------------------------------------------------------------------------------
  #   make_poker(type)
  #------------------------------------------------------------------------------
  #   type=ポーカータイプの設定を参照
  #==============================================================================
  # ■ ゲーム設定
  #==============================================================================
  RAISE = 1.8                      # レイズした場合のレート倍率
  #==============================================================================
  # ■ グラフィック設定 ※Windowskinsフォルダ内のファイル名を指定
  #==============================================================================
  BACK = "coin_background1"        # ポーカーの背景画像
  SELECT = "cursor_back"           # カーソル画像
  CURSOR = "cursor_anim"           # カーソルアイコン画像
  POKER_HIT = "flash_yellow"       # 当たり効果画像
  FRAME1 = ""          # ウィンドウ枠画像(ヘルプ)frame_emboss
  FRAME2 = "frame_line3"           # ウィンドウ枠画像(所持コイン)
  FRAME3 = "frame_line2"           # ウィンドウ枠画像(役)
  FRAME4 = "frame_line2"           # ウィンドウ枠画像(掛け金)
  #==============================================================================
  # ■ 選択肢とヘルプの設定
  #==============================================================================
  GAME_COMS = ["Deal", "End"]
  GAME_HELPS = ["ゲームを開始します。", "ゲームを終了します。"]
  CHANGE_COMS = ["Draw","Raise","Fold"]
  CHANGE_HELPS = ["現在のカードで勝負します。",
  "賭け金を倍に増やします。",
  "賭け金の半額を払い、ゲームを降ります。"]
  CARD_COMS = ["Card1","Card2","Card3","Card4","Card5"]
  CARD_HELPS = ["Card1をHOLDします。","Card2をHOLDします。",
  "Card3をHOLDします。","Card4をHOLDします。",
  "Card5をHOLDします。"]
  CARD_HELPS2 = ["Card1をDRAWします。","Card2をDRAWします。",
  "Card3をDRAWします。","Card4をDRAWします。",
  "Card5をDRAWします。"]
  #==============================================================================
  # ■ 音の設定 ※ファイル名を指定 ※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)
  
  ME_MAX_TIME = 12                 # 大当りの待ち時間(HIT_ME_MAXの演奏時間(秒))
  ME_TIME = 4                      # 当りの待ち時間(HIT_MEの演奏時間(秒))
  #==============================================================================
  # ■ ポーカータイプの設定(COIN,JOKER,RATE,ME_RATE_MAX)
  # COIN[n] = value　※n=タイプ番号($game_temp.poker_type から参照される)
  #==============================================================================
  COIN = [] # value=消費コイン数(賭けるコイン枚数)&レイズで上乗せするコイン数
  COIN[0] = 100 #100枚賭け
  COIN[1] = 100
  COIN[2] = 10
  #--------------------------------------------------------------------------
  # FIVE_JOKER[n] = a
  # n=タイプ番号($game_temp.poker_type から参照される)
  # a= true false(ジョーカーを5枚使うフラグ)
  #--------------------------------------------------------------------------
  FIVE_JOKER = []
  FIVE_JOKER[0] = false
  FIVE_JOKER[1] = true # ※『ワイルドポーカー』…レートを低くする？
  FIVE_JOKER[2] = false
  #--------------------------------------------------------------------------
  # NAME[n] = [a,b,c,d,e,f,g,h,i,j]
  # n=タイプ番号($game_temp.poker_type から参照される)
  # a,b,c,d,e...=役の名前
  #--------------------------------------------------------------------------
  NAME = []
  NAME[0] = ["Royal Flush","5 of a Kind","Straight Flush","4 of a Kind","Full House",
  "Flush","Straight","3 of a Kind","2 Pair","Joker or 1 Pair"]
  NAME[1] = ["Royal Flush","5 of a Kind","Straight Flush","4 of a Kind","Full House",
  "Flush","Straight","3 of a Kind","2 Pair","Joker or 1 Pair"]
  NAME[2] = ["Royal Flush","5 of a Kind","Straight Flush","4 of a Kind","Full House",
  "Flush","Straight","3 of a Kind","2 Pair","Joker or 1 Pair"]
  #--------------------------------------------------------------------------
  # RATE[n] = [a,b,c,d,e,f,g,h,i,j]
  # n=タイプ番号($game_temp.poker_type から参照される)
  # a=NAME[n][a] の役が揃った場合の獲得コイン数(ロイヤル.Ｓ.Ｆ)
  # b=NAME[n][b] の役が揃った場合の獲得コイン数(５カード)
  # c,d,e...
  #--------------------------------------------------------------------------
  RATE = [] # □value=獲得コイン数(役が揃う)
  RATE[0] = [15000,5000,3000,2000,1200,800,600,400,300,200]
  RATE[1] = [10000,3000,2400,1200,800,600,400,250,200,150]
  RATE[2] = [1500,500,300,200,120,80,60,40,30,20]
  # □大当りの効果音(HIT_ME_MAX)を演奏する獲得コイン数(n以上)
  ME_RATE_MAX = []
  ME_RATE_MAX[0] = 2000
  ME_RATE_MAX[1] = 1200
  ME_RATE_MAX[2] = 200
  #==============================================================================
  # ■ 文字色設定
  #==============================================================================
  A_COLOR = Color.new(255,255,255,255)     # 通常色
  B_COLOR = Color.new(0,0,0,255)           # 影色
  S_COLOR = Color.new(255,255,0,255)       # システム色
  C_COLOR = Color.new(0,128,255,255)       # カード交換色
  #==============================================================================
  # ■ メニュー文字設定
  #==============================================================================
  WORD1 = "Ante"
  WORD2 = "Poker Hand"
  WORD3 = "WILD POKER"
  WORD4 = "FIVE JOKERS POKER"
  WORD5 = "Jacks or Better"
  WORD6 = "Coin"
  #--------------------------------------------------------------------------
  # 選択肢 の文字設定
  #--------------------------------------------------------------------------
  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","ＭＳ ゴシック"]       # フォント名
  #--------------------------------------------------------------------------
  # NAME の文字設定
  #--------------------------------------------------------------------------
  N_SIZE = 20                              # 文字サイズ
  N_BOLD = true                            # 太文字フラグ[true/false]
  N_ITALIC = false                         # 斜め文字フラグ[true/false]
  N_SHADOW = false                         # 影文字フラグ[true/false]
  N_ROUND = false                          # 囲み文字フラグ[true/false]
  N_NAME = ["Arial","ＭＳ ゴシック"]       # フォント名
  #--------------------------------------------------------------------------
  # RATE の文字設定
  #--------------------------------------------------------------------------
  R_SIZE = 20                              # 文字サイズ
  R_BOLD = true                            # 太文字フラグ[true/false]
  R_ITALIC = false                         # 斜め文字フラグ[true/false]
  R_SHADOW = false                          # 影文字フラグ[true/false]
  R_ROUND = false                          # 囲み文字フラグ[true/false]
  R_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)
  N_FONT = Copy_Font.new(N_SIZE,N_BOLD,N_ITALIC,N_SHADOW,N_ROUND,N_NAME,A_COLOR,B_COLOR)
  R_FONT = Copy_Font.new(R_SIZE,R_BOLD,R_ITALIC,R_SHADOW,R_ROUND,R_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)
  M_FONT = Copy_Font.new(28,true,false,false,false,["Georgia","ＭＳ ゴシック"],A_COLOR,B_COLOR)
  M2_FONT = Copy_Font.new(16,true,false,false,false,["Arial","ＭＳ ゴシック"],A_COLOR,B_COLOR)
end
#==============================================================================
# ■ Window_Poker
#==============================================================================
class Window_Poker < Window_Play_Cards
  include HIDE_POKER
  #--------------------------------------------------------------------------
  # ■ オブジェクト初期化
  #--------------------------------------------------------------------------
  def initialize(size = 1,joker = false,five = false)
    super
    @first_draw = false
    card_reset
    #…………………………………………………………………………………………………
    # ■カード座標を指定
    #…………………………………………………………………………………………………
    for i in 0...@size
      x = 32*(i+1)+96*i-16
      y = 192
      @play_card[i].visible = true
      position(i,x,y)
    end
    @five = five
    # □最初のドローでは、マークジョーカーは除外する
    @cards = [0,14,28,42]
    card_select?
  end
  #--------------------------------------------------------------------------
  # ■ カードの選択(既に引いたカードを除外)
  #--------------------------------------------------------------------------
  def card_select?(nums = @select)
    # □フラッシュ確率UP(5ジョーカーの場合)
    if @first_draw && @five
      @max_mark = rand(14) + @mark.index(@mark.max)*14
    end
    for i in nums.keys
      if nums[i] == 8
        @card[i] = nil
      end
      while @card[i] == nil
        c = rand(57)
        if ! @cards.include?(c)
          @cards.push(c)
          @card[i] = c
        # □フラッシュ確率UP(5ジョーカーの場合)
        elsif @max_mark != nil && @five
          unless @cards.include?(@max_mark)
            @cards.push(@max_mark)
            @card[i] = @max_mark
          end
        end
        # □既に引いたカードのループ
        if @cards.size >= 57
          @cards = @cards.reverse
          cards = [0,14,28,42]
          for n in 0...@size
            cards.push(@cards[n])
          end
          @cards = cards
        end
      end
    end
    # □最初のドローでは、マークジョーカーは除外する
    unless @first_draw
      @max_mark = nil
      if @five
        @cards = [@card[0],@card[1],@card[2],@card[3],@card[4]]
      end
      # □デバッグ処理
      if HIDE_POKER::DEBUG_CARD != {}
        @card = HIDE_POKER::DEBUG_CARD.dup
        for i in @card.values
          @cards.push(i)
        end
      end
      @first_draw = true
    end
    # □カードの描画
    draw_card?(@card)
  end
  #--------------------------------------------------------------------------
  # ■ カードの初期化(ポーカーの終了)
  #--------------------------------------------------------------------------
  def card_reset
    # □最初のドローでは、マークジョーカーは除外する
    @first_draw = false
    @cards = [0,14,28,42]
  end
  #--------------------------------------------------------------------------
  # ■ 当り役の取得
  #--------------------------------------------------------------------------
  def card_hit?
    #…………………………………………………………………………………………………
    # ■手持ちのカードをグループ化
    #…………………………………………………………………………………………………
    items = @numbers.uniq
    group = [0]*items.size
    joker = 0
    hi_card = [0]*items.size
    hi = nil
    @numbers.each{ |a| if a == 0 ; joker += 1 ; end }
    for i in 0...items.size
      for z in @numbers
        if z == items[i] && z != 0
          group[i] += 1
          hi_card[i] = z
        end
      end
    end
    #…………………………………………………………………………………………………
    # ■(3,4,5)カード/(1,2)ペアの判定
    #…………………………………………………………………………………………………
    n_card = 0 ; pair = 0
    for i in 0...group.size
      if group[i] > n_card
        n_card = group[i]
      end
      if group[i] == 2
        pair += 1
        # □
        hi = hi_card[i]
      end
    end
    #…………………………………………………………………………………………………
    # ■フラッシュの判定
    #…………………………………………………………………………………………………
    flash = 0
    for i in 0..3
      if @mark[i] > flash
        flash = @mark[i]
      end
    end
    #…………………………………………………………………………………………………
    # ■ストレートの判定
    #…………………………………………………………………………………………………
    straight = 0
    items.sort!
    items.delete_if{ |a| a == 0 }
    n = @datas.index(items[0])
    num = 1
    for s in (n+1)...(n+5)
      if @datas[n] + num == @datas[s]
        straight += 1
      end
      num += 1
    end
    if straight >= 2 && joker > 0
      straight += joker
    end
    #…………………………………………………………………………………………………
    # ■ロイヤル・ストレートの判定(Aエースを含んでいるのが条件)
    #…………………………………………………………………………………………………
    royal = 0 ; num = 1 ; n = 9
    if @numbers.include?(1)
      for s in (n+1)...(n+5)
        if 9 + num == @datas[s]
          royal += 1
        end
        num += 1
      end
    end
    if royal >= 2 && joker > 0
      royal += joker
    end
    #…………………………………………………………………………………………………
    # ■ジョーカーを含む場合
    #…………………………………………………………………………………………………
    if joker > 0
      # □1ペアを3カードに変更
      if pair == 1 && n_card != 3
        n_card = 2 + joker
        pair = 0
      # □2ペアをフルハウスに変更
      elsif pair == 2
        n_card = 3
        pair = 1
      # □(3,4,5)カードに変更
      else
        n_card += joker
      end
    end
    #…………………………………………………………………………………………………
    # ■ロイヤル・ストレート・フラッシュの判定(フラッシュを含んでいるのが条件)
    #…………………………………………………………………………………………………
    if royal == 4 && flash == 5
      return 0
    end
    #…………………………………………………………………………………………………
    # ■ポーカー役の強い順で判別
    #…………………………………………………………………………………………………
    hand = 10
    if n_card == 5
      # □5カード(ワイルドカードを含んでいるのが条件)
      if @mark[4] == 1
        case joker
        when 1,5
          # □5カード
          hand = 1
        when 2,4
          # □4カード
          hand = 3
        when 3
          # □フルハウス
          hand = 4
        end
      else
        case joker
        when 1,4
          # □4カード
          hand = 3
        when 2,3
          # □フルハウス
          hand = 4
        end
      end
    elsif n_card == 4
      if @mark[4] == 1
        # □4カード(ワイルドカードを含んで場合)
        hand = 3
      else
        case joker
        when 0,1,3
          # □4カード
          hand = 3
        when 2
          # □フルハウス(ジョーカー2枚)
          hand = 4
        end
      end
    elsif n_card == 3
      # □ジョーカー2枚のストレート.フラッシュ(フルハウスより優先)
      if flash == 5 && straight == 4
        hand = 2
      # □フルハウス
      elsif pair == 1
        hand = 4
      # □ジョーカー2枚のストレート(3カードより優先)
      elsif straight == 4
        hand = 6
      # □3カード
      else
        hand = 7
      end
    elsif pair == 2
      # □2ペア
      hand = 8
    elsif pair == 1 && hi != nil
      # □Jacks or Better
      if hi >= 11 or hi == 1
        hand = 9
      else
        # □1ペア(役として不成立)
        hand = 10
      end
    else
      # □ストレート.フラッシュ
      if flash == 5 && straight == 4
        hand = 2
      # □フラッシュ
      elsif flash == 5
        hand = 5
      # □ストレート
      elsif straight >= 4
        hand = 6
      # □ジョーカー1枚を含む1ペア(役として成立)
      elsif joker == 1
        hand = 9
      else
        # □0ペア(役として不成立)
        hand = 10
      end
    end
    # □デバッグ処理
    if HIDE_POKER::DEBUG
      p debug = ("F=" + flash.to_s + ",S=" + straight.to_s + ",P=" + 
      pair.to_s + ",C=" + n_card.to_s + ",J=" + joker.to_s + ",R=" + royal.to_s)
    end
    return hand
  end
end
#==============================================================================
# ■ Window_Poker_top
#==============================================================================
class Window_Poker_top
  attr_accessor :rate
  include HIDE_POKER
  #--------------------------------------------------------------------------
  # ■ オブジェクト初期化
  #--------------------------------------------------------------------------
  def initialize
    @poker_top = Sprite.new
    @rate1 = HIDE_POKER::RATE[$game_temp.poker_type]
    n = HIDE_POKER::RAISE
    @rate2 = HIDE_POKER::RATE[$game_temp.poker_type].collect{|a| (a*n).ceil}
    @bitmap1 = make_rate(@rate1)
    @bitmap2 = make_rate(@rate2)
    refresh(1)
  end
  #--------------------------------------------------------------------------
  # ■ ポーカー役のBitmapを作成
  #--------------------------------------------------------------------------
  def make_rate(rate,bx = 0,by = 24)
    name = HIDE_POKER::NAME[$game_temp.poker_type]
    bitmap = Bitmap.new(640,240)
    #…………………………………………………………………………………………………
    # ■ 当りパターンの描画
    #…………………………………………………………………………………………………
    n_font = HIDE_POKER::N_FONT
    r_font = HIDE_POKER::R_FONT
    for i in 0...rate.size
      # □ポーカー役の描画
      bitmap.draw_cache_text((i/5)*320+34,24*(i%5)+48,240,32,name[i].to_s,0,n_font)
      # □当りレートの描画
      bitmap.draw_cache_text((i/5)*320+160-34,24*(i%5)+48,160,32,rate[i].to_s,2,r_font)
    end
    return bitmap
  end
  #--------------------------------------------------------------------------
  # ■ 更新
  #--------------------------------------------------------------------------
  def refresh(type)
    if type == 1
      @poker_top.bitmap = @bitmap1
      @rate = @rate1
    else
      @poker_top.bitmap = @bitmap2
      @rate = @rate2
    end
  end
  #--------------------------------------------------------------------------
  # ■ 解放
  #--------------------------------------------------------------------------
  def dispose
    if @bitmap1 != nil
      @bitmap1.dispose
    end
    if @bitmap2 != nil
      @bitmap2.dispose
    end
    @poker_top.dispose
  end
end
#==============================================================================
# ■ Scene_Poker
#==============================================================================
class Scene_Poker
  include HIDE_POKER
  #--------------------------------------------------------------------------
  # ■ オブジェクト初期化
  #--------------------------------------------------------------------------
  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_POKER::BGM))
  end
  #--------------------------------------------------------------------------
  # ■ ポーカーの初期化
  #--------------------------------------------------------------------------
  def game_reset?
    @ante = @coin
    @card_close = true
    @poker_step = 0
    @raise = false
    @fold = false
    # □ゲーム実行中フラグをOFF
    @playing = false
  end
  #--------------------------------------------------------------------------
  # ■ ウィンドウの初期化
  #--------------------------------------------------------------------------
  def window_reset?
    @card_select_window.active = false
    @card_select_window.index = -1
    @card_select_window.visible = false
    # □カード選択色を変更
    @card_select_window.exchange = [false]*5
    @card_select_window.refresh
    @card_exchange_window.active = false
    @card_exchange_window.index = -1
    @card_exchange_window.visible = false
    # □カード選択色を変更
    @card_exchange_window.exchange = [false]*5
    @card_exchange_window.refresh
    @game_select_window.active = true
    @game_select_window.index = 0
    @game_select_window.visible = true
    @playing = false
    # □当たり報酬を戻す(レイズ)
    @poker_window_top.refresh(1)
  end
  #--------------------------------------------------------------------------
  # ■ メイン処理
  #--------------------------------------------------------------------------
  def main
    @coin = HIDE_POKER::COIN[$game_temp.poker_type]
    @ante = @coin
    #…………………………………………………………………………………………………
    # ■文字装飾を取得
    #…………………………………………………………………………………………………
    s_font = HIDE_POKER::S_FONT ; h_font = HIDE_POKER::H_FONT
    c_font = HIDE_POKER::C_FONT ; t_font = HIDE_POKER::T_FONT
    m_font = HIDE_POKER::M_FONT ; r_font = HIDE_POKER::M2_FONT
    a_font = HIDE_POKER::R_FONT
    #…………………………………………………………………………………………………
    # ■ポーカーウィンドウ背景を作成
    #…………………………………………………………………………………………………
    @poker_window_back = Picture_Blink_Cursor.new(RPG::Cache.windowskin(HIDE_POKER::BACK))
    frame = RPG::Cache.windowskin(HIDE_POKER::FRAME1)
    @poker_window_back.draw_background(frame,16,480-48,320,32)
    # □枠の描画
    frame = RPG::Cache.windowskin(HIDE_POKER::FRAME2)
    @poker_window_back.draw_background(frame,440,445-2,185,32)
    frame = RPG::Cache.windowskin(HIDE_POKER::FRAME4)
    @poker_window_back.draw_background(frame,440+57,445-40,128,32)
    frame = RPG::Cache.windowskin(HIDE_POKER::FRAME3)
    @poker_window_back.draw_background(frame,16,44,640-32,136)
    #…………………………………………………………………………………………………
    # ■タイトルロゴの描画
    #…………………………………………………………………………………………………
    m_font.interval = 2
    if HIDE_POKER::FIVE_JOKER[$game_temp.poker_type]
      wild = HIDE_POKER::WORD4
    else
      wild = HIDE_POKER::WORD3
    end
    @poker_window_back.bitmap.draw_cache_text(0,4,640,0,wild,1,m_font)
    @poker_window_back.bitmap.draw_cache_text(0,26,640,0,HIDE_POKER::WORD5,1,r_font)
    
    @poker_window_back.draw_text(34,13+8,240,0,HIDE_POKER::WORD2,0,t_font)
    @poker_window_back.draw_text(440+8+57+4,446-41,160,0,HIDE_POKER::WORD1,0,t_font)
    @poker_window_back.draw_text(440+8,446,160,0,HIDE_POKER::WORD6,0,t_font)
    #…………………………………………………………………………………………………
    # ■当たり演出ウィンドウを作成
    #…………………………………………………………………………………………………
    @poker_window_under = Picture_Blink_Cursor.new
    @poker_window_under.start(0)
    #…………………………………………………………………………………………………
    # ■ポーカーウィンドウを作成
    #…………………………………………………………………………………………………
    five = HIDE_POKER::FIVE_JOKER[$game_temp.poker_type]
    @card_window = Window_Poker.new(5,true,five)
    @card_window.z = 100 + 2
    #…………………………………………………………………………………………………
    # ■コイン数値ウィンドウを作成
    #…………………………………………………………………………………………………
    @coin_window = Window_digits_number.new(500-16,427,100,$game_party.coin,10,10,c_font)
    #…………………………………………………………………………………………………
    # ■掛け金ウィンドウを作成
    #…………………………………………………………………………………………………
    @ante_window = Window_digits_number.new(500,427-38,100,@ante,10,10,a_font)
    #…………………………………………………………………………………………………
    # ■ポーカーの配当リストを作成
    #…………………………………………………………………………………………………
    @poker_window_top = Window_Poker_top.new
    #…………………………………………………………………………………………………
    # ■ゲーム開始選択ウィンドウを作成
    #…………………………………………………………………………………………………
    pic = RPG::Cache.windowskin(HIDE_POKER::SELECT)
    icon = RPG::Cache.windowskin(HIDE_POKER::CURSOR)
    com = HIDE_POKER::GAME_COMS
    helps = HIDE_POKER::GAME_HELPS
    @game_select_window = Picture_Blink_Cursor.new(16,480-96,96,32,16,0,2,2)
    @game_select_window.draw_cursor(pic,com,s_font,icon)
    @game_select_window.start
    # □ヘルプウィンドウの関連付け
    @game_select_window.make_helps(16+4,416+16,helps,h_font)
    #…………………………………………………………………………………………………
    # ■カード交換ウィンドウを作成
    #…………………………………………………………………………………………………
    com = HIDE_POKER::CARD_COMS
    helps = HIDE_POKER::CARD_HELPS + HIDE_POKER::CARD_HELPS2
    @card_select_window = Picture_Blink_Cursor.new(16,480-144,96,32,16,0,5,5)
    # □カード交換色
    @card_select_window.d_color = HIDE_POKER::C_COLOR
    @card_select_window.draw_cursor(pic,com,s_font,icon)
    # □ヘルプウィンドウの関連付け
    @card_select_window.make_helps(16+4,416+16,helps,h_font)
    #…………………………………………………………………………………………………
    # ■カード交換の開始ウィンドウを作成
    #…………………………………………………………………………………………………
    com = HIDE_POKER::CHANGE_COMS
    helps = HIDE_POKER::CHANGE_HELPS
    @card_exchange_window = Picture_Blink_Cursor.new(16,480-96,96,32,16,0,3,3)
    @card_exchange_window.draw_cursor(pic,com,s_font,icon)
    # □ヘルプウィンドウの関連付け
    @card_exchange_window.make_helps(16+4,416+16,helps,h_font)
    # □選択肢の文字色を初期化
    exchange_colors?
    # トランジション実行
    Graphics.transition
    # メインループ
    loop do
      # ゲーム画面を更新
      Graphics.update
      # 入力情報を更新
      Input.update
      # フレーム更新
      update
      # 画面が切り替わったらループを中断
      if $scene != self
        break
      end
    end
    # トランジション準備
    Graphics.freeze
    # ウィンドウを解放
    @poker_window_back.dispose
    @card_window.dispose
    @coin_window.dispose
    @ante_window.dispose
    @poker_window_top.dispose
    @card_select_window.dispose
    @game_select_window.dispose
    @card_exchange_window.dispose
    @poker_window_under.dispose
  end
  #--------------------------------------------------------------------------
  # ■ フレーム更新(ゲーム開始)
  #--------------------------------------------------------------------------
  def update_select
    #…………………………………………………………………………………………………
    # ■ C ボタンが押された場合
    #…………………………………………………………………………………………………
    if Input.trigger?(Input::C)
      unless @card_window.move
        case @game_select_window.index
        when 0 #□ゲーム開始
          if @poker_step == 8
            @poker_step = 9
          else
            if $game_party.coin >= @coin
              # □決定SEを演奏
              $game_system.se_play(RPG::AudioFile.new(HIDE_POKER::DECISION_SE))
            end
            @poker_step = 1
          end
        when 1 #□ゲーム終了
          # □決定SEを演奏
          $game_system.se_play(RPG::AudioFile.new(HIDE_POKER::DECISION_SE))
          poker_end
        end
      end
      return
    end
    #…………………………………………………………………………………………………
    # ■ B ボタンが押された場合
    #…………………………………………………………………………………………………
    if Input.trigger?(Input::B)
      # □キャンセルSEを演奏
      $game_system.se_play(RPG::AudioFile.new(HIDE_POKER::CANCEL_SE))
      poker_end
      return
    end
  end
  #--------------------------------------------------------------------------
  # ■ ヘルプ更新
  #--------------------------------------------------------------------------
  def update_help
    if @card_window.values[@card_select_window.index] == 16
      he = 0
    else
      he = 5
    end
    @card_select_window.help_id = @card_select_window.index + he
  end
  #--------------------------------------------------------------------------
  # ■ フレーム更新(交換するカードの選択)
  #--------------------------------------------------------------------------
  def update_card
    # □ヘルプ更新
    update_help
    unless @card_window.move
      #…………………………………………………………………………………………………
      # ■ C ボタンが押された場合
      #…………………………………………………………………………………………………
      if Input.trigger?(Input::C)
        @card_window.keys = {0=>false,1=>false,2=>false,3=>false,4=>false}
        @card_window.keys[@card_select_window.index] = true
        #…………………………………………………………………………………………………
        # ■ 表から裏に変わるアニメーションを実行
        #…………………………………………………………………………………………………
        if @card_window.open?(@card_select_window.index)
          @card_window.count_zero?(0)
          @card_close = false
        #…………………………………………………………………………………………………
        # ■ 裏から表に変わるアニメーションを実行
        #…………………………………………………………………………………………………
        else
          @card_window.count_zero?
          @card_close = true
        end
        # □カード選択色を変更
        @card_select_window.exchange[@card_select_window.index] = ! @card_close
        @card_select_window.refresh
        @poker_step = 4
        return
      end
      #…………………………………………………………………………………………………
      # ■ 方向ボタンの下が押された場合
      #…………………………………………………………………………………………………
      if Input.trigger?(Input::DOWN)
        $game_system.se_play($data_system.cursor_se)
        @card_select_window.index = -1
        @card_select_window.active = false
        @card_exchange_window.index = 0
        @card_exchange_window.active = true
        return
      end
      #…………………………………………………………………………………………………
      # ■ B ボタンが押された場合
      #…………………………………………………………………………………………………
      if Input.trigger?(Input::B)
        # □フォルドの実行(ゲームを降りる)
        game_fold?
      end
    end
  end
  #--------------------------------------------------------------------------
  # ■ フレーム更新(カード交換の開始)
  #--------------------------------------------------------------------------
  def update_exchange
    unless @card_window.move
      #…………………………………………………………………………………………………
      # ■ C ボタンが押された場合
      #…………………………………………………………………………………………………
      if Input.trigger?(Input::C)
        case @card_exchange_window.index
        when 0
          # □決定SEを演奏
          $game_system.se_play(RPG::AudioFile.new(HIDE_POKER::DECISION_SE))
          # □カードの交換を実行
          @card_window.card_select?(@card_window.values)
          for i in 0...@card_window.keys.size
            @card_window.keys[i] = ! @card_window.open?(i)
          end
          @poker_step = 5
        when 1
          # □レイズの実行(賭け金を変更)
          unless @raise
            # □コイン(賭け金)を減らす
            if $game_party.coin >= @coin
              # □決定SEを演奏
              $game_system.se_play(RPG::AudioFile.new(HIDE_POKER::DECISION_SE))
              $game_party.lose_coin(@coin)
              @ante *= 2
            else
              # □ブザー SE を演奏
              $game_system.se_play(RPG::AudioFile.new(HIDE_POKER::BUZZER_SE))
              return
            end
            # □カード選択色を変更
            @raise = true
            @fold = true
            exchange_colors?(true)
            # □当たり報酬をn倍に変更
            @poker_window_top.refresh(2)
          else
            # □ブザー SE を演奏
            $game_system.se_play(RPG::AudioFile.new(HIDE_POKER::BUZZER_SE))
          end
        when 2
          # □フォルドの実行(ゲームを降りる)
          game_fold?
        end
        return
      end
      #…………………………………………………………………………………………………
      # ■ 方向ボタンの上が押された場合
      #…………………………………………………………………………………………………
      if Input.trigger?(Input::UP)
        $game_system.se_play($data_system.cursor_se)
        @card_exchange_window.index = -1
        @card_exchange_window.active = false
        @card_select_window.index = 0
        @card_select_window.active = true
        return
      end
      #…………………………………………………………………………………………………
      # ■ B ボタンが押された場合
      #…………………………………………………………………………………………………
      if Input.trigger?(Input::B)
        # □フォルドの実行(ゲームを降りる)
        game_fold?
      end
    end
  end
  #--------------------------------------------------------------------------
  # ■ フォルドの実行(ゲームを降りる)
  #--------------------------------------------------------------------------
  def game_fold?
    unless @fold
      # □決定SEを演奏
      $game_system.se_play(RPG::AudioFile.new(HIDE_POKER::DECISION_SE))
      # □コインを増やす(賭け金の半分)
      $game_party.gain_coin((@coin/2))
      # □カード選択色を変更
      exchange_colors?
      @card_close = false
      @card_window.count_zero?(0)
      for i in 0...@card_window.keys.size
        @card_window.keys[i] = @card_window.open?(i)
      end
      @poker_step = 12
    else
      # □ブザー SE を演奏
      $game_system.se_play(RPG::AudioFile.new(HIDE_POKER::BUZZER_SE))
    end
  end
  #--------------------------------------------------------------------------
  # ■ 選択肢の色更新
  #--------------------------------------------------------------------------
  def exchange_colors?(on = $game_party.coin < @coin)
    # □カード選択色を変更
    @raise = on
    @game_select_window.exchange[0] = $game_party.coin < @coin
    @game_select_window.refresh
    @card_exchange_window.exchange[1] = @raise
    @card_exchange_window.exchange[2] = @fold
    @card_exchange_window.refresh
  end
  #--------------------------------------------------------------------------
  # ■ 当たりの処理
  #--------------------------------------------------------------------------
  def poker_hit
    @card_window.move = true
    @game_select_window.active = false
    hit = @card_window.card_hit?
    #…………………………………………………………………………………………………
    # ■ 当りの場合の効果音を演奏(ME)
    #…………………………………………………………………………………………………
    gain = 0
    unless hit == 10
      # □ハズレの場合、待ち時間無し
      gain = @poker_window_top.rate[hit]
    end
    #…………………………………………………………………………………………………
    # ■ 所持コインを増やす
    #…………………………………………………………………………………………………
    $game_party.gain_coin(gain)
    # □当たりの出たレートを点滅
    @poker_window_under.bitmap.clear
    flash = RPG::Cache.windowskin(HIDE_POKER::POKER_HIT)
    @poker_window_under.draw_flash(flash,(hit/5)*320+24,(hit%5)*24+48,276,32)
    
    time_up = 0
    if gain > 0
      # □大当たりの場合
      if gain >= HIDE_POKER::ME_RATE_MAX[$game_temp.poker_type]
        $game_system.me_play(RPG::AudioFile.new(HIDE_POKER::HIT_ME_MAX))
        # □次のゲーム開始まで待つ(MEの演奏時間)
        time_up = HIDE_POKER::ME_MAX_TIME
      else
        $game_system.me_play(RPG::AudioFile.new(HIDE_POKER::HIT_ME))
        # □次のゲーム開始まで待つ(MEの演奏時間)
        time_up = HIDE_POKER::ME_TIME
      end
    end
    #…………………………………………………………………………………………………
    # ■ 次の開始まで待つ
    #…………………………………………………………………………………………………
    time = 0
    @poker_window_under.blink_start
    while @poker_window_under.blink_active
      # □ゲーム画面を更新
      Graphics.update
      # □回転数値の更新(所持コイン)
      @coin_window.update($game_party.coin)
      # □当りの演出を更新
      if time < time_up
        if @poker_window_under.count?
          time += 1
        end
        @poker_window_under.update
      else
        @poker_window_under.blink_end
      end
    end
    # □選択色を変更
    exchange_colors?
    @poker_step = 7
  end
  #--------------------------------------------------------------------------
  # ■ ゲームの終了
  #--------------------------------------------------------------------------
  def poker_end
    unless @playing
      # □ポーカー開始前の BGM に戻す
      $game_system.bgm_play($game_temp.map_bgm)
      # マップ画面に切り替え
      $scene = Scene_Map.new
      return
    end
  end
  #--------------------------------------------------------------------------
  # ■ フレーム更新
  #--------------------------------------------------------------------------
  def update
    #…………………………………………………………………………………………………
    # ■ 回転数値の更新(所持コイン)
    #…………………………………………………………………………………………………
    @coin_window.update($game_party.coin)
    #…………………………………………………………………………………………………
    # ■ 掛け金の更新
    #…………………………………………………………………………………………………
    
    @ante = @raise ? @coin*2 : @coin
    
    @ante_window.refresh(@ante)
    #…………………………………………………………………………………………………
    # ■ カード選択ウィンドウの更新
    #…………………………………………………………………………………………………
    if @card_select_window.active
      @card_select_window.update
      update_card
    end
    #…………………………………………………………………………………………………
    # ■ ゲーム開始ウィンドウの更新
    #…………………………………………………………………………………………………
    if @game_select_window.active
      @game_select_window.update
      update_select
    end
    #…………………………………………………………………………………………………
    # ■ カード決定ウィンドウの更新
    #…………………………………………………………………………………………………
    if @card_exchange_window.active
      @card_exchange_window.update
      update_exchange
    end
    #…………………………………………………………………………………………………
    # ■ ゲームの流れ
    #…………………………………………………………………………………………………
    case @poker_step
    when 1
      # □コインを減らす(賭け金)
      if $game_party.coin >= @coin
        $game_party.lose_coin(@coin)
        # □カード選択色を変更
        exchange_colors?
        @playing = true
        @game_select_window.active = false
        @poker_step = 2
      else
        # □ブザー SE を演奏
        $game_system.se_play(RPG::AudioFile.new(HIDE_POKER::BUZZER_SE))
        @poker_step = 0
        @playing = false
        return
      end
    when 2
      # □裏向きカードを全て表向きに変更
      @card_window.keys = {0=>true,1=>true,2=>true,3=>true,4=>true}
      if @card_window.card_anim?
        @game_select_window.active = false
        @game_select_window.index = -1
        @game_select_window.visible = false
        # □カード交換の処理フラグをON
        @card_select_window.active = true
        @card_select_window.index = 0
        @card_select_window.visible = true
        @card_exchange_window.visible = true
        @poker_step = 3
      end
      return
    when 3
      # □交換するカードの選択待ち
      return
    when 4
      # □交換するカードの向きを変更(個別)
      if @card_window.card_anim?(@card_close)
        @poker_step = -1
      end
      return
    when 5
      # □裏向きカードのみ表向きに変更
      if @card_window.card_anim?
        @poker_step = 6
      end
      return
    when 6
      unless @card_window.move
        # □ポーカー役の判定
        poker_hit
      end
      return
    when 7
      # □ウインドウの初期化
      @card_window.move = false
      window_reset?
      @poker_step = 8
      return
    when 8
      # □ゲームの開始待ち(連続ゲーム)
      return
    when 9
      @card_close = false
      # □コイン数のチェック
      if $game_party.coin >= @coin
        @playing = true
        @game_select_window.active = false
        @card_window.count_zero?(0)
        @poker_step = 10
      else
        # □ブザー SE を演奏
        $game_system.se_play(RPG::AudioFile.new(HIDE_POKER::BUZZER_SE))
        @poker_step = 0
        @playing = false
        return
      end
      return
    when 10
      # □表向きカードを全て裏向きに変更
      @card_window.keys = {0=>true,1=>true,2=>true,3=>true,4=>true}
      if @card_window.card_anim?(false)
        @poker_step = 11
      end
      return
    when 11
      unless @card_window.move
        # □ポーカーの初期化(ゲーム開始)
        poker_reset?
        @poker_step = 1
      end
      return
    when 12 #(ゲームを降りる)
      # □表向きカードのみ裏向きに変更
      if @card_window.card_anim?(false)
        # □ウインドウの初期化
        window_reset?
        @card_close = false
        # □ポーカーの初期化(ゲーム開始)
        poker_reset?
        @poker_step = 0
      end
      return
    end
  end
  #--------------------------------------------------------------------------
  # ■ ポーカーの初期化
  #--------------------------------------------------------------------------
  def poker_reset?
    @card_window.card_clear
    @card_window.card_reset
    @card_window.card_select?
    game_reset?
    
  end
end