#==============================================================================
# ■ 25Puzzle vol.1.40
#------------------------------------------------------------------------------
# ※『Window_digits_number 5.90以上』(必須)
# ※『Picture_Blink_Cursor 1.60以上』(必須)
# ※『Coin_Base 5.00以上』(必須)より下に挿入
# 12/04/22
#==============================================================================
module HIDE_25PUZZLE
  #==============================================================================
  # ■ デバッグ(開発者用)
  #==============================================================================
  DEBUG = false                       # [true/false]
  #==============================================================================
  # ■ イベントコマンド『スクリプト』に以下を追加
  #------------------------------------------------------------------------------
  #   make_25puzzle(type)
  #------------------------------------------------------------------------------
  #   type=25パズルタイプの設定を参照
  #==============================================================================
  # ■ グラフィック設定 ※Windowskinsフォルダ内のファイル名を指定
  #==============================================================================
  BACK = "coin_background1"            # 25パズル背景画像
  TOP = "puzzle25_top"                # テーブル画像
  TOP2 = "puzzle25_top2"              # テーブル上画像
  FRAME1 = "frame_emboss"             # ウィンドウ枠画像
  FRAME2 = "frame_line"               # ウィンドウ枠画像
  PIECE = "puzzle25_piece"            # 25パズル画像
  NUMBER = "puzzle25_number"          # 25パズル上画像(数値)
  PIECE_S = "puzzle25_piece_s"        # 小25パズル画像
  HIT = "flash_yellow"                # 当たりの画像(当たり効果)
  CURSOR_P = "puzzle25_cursor"        # カーソル画像
  SELECT = "cursor_back"              # メニューカーソル画像
  CURSOR = "cursor_anim"              # カーソルアイコン画像
  #==============================================================================
  # ■ 選択肢とヘルプの設定
  #==============================================================================
  GAME_COMS = ["Start","End","Reset"]
  GAME_HELPS = ["ゲームを開始します。", "ゲームを終了します。",
  "スコアを初期化します。"]
  PIECE_HELP1 = "ピース"
  PIECE_HELP2 = "をスライドさせます。"
  PIECE_HELP3 = "はスライドできません。"
  PIECE_HELP4 = "パズルが完成しました。"
  PIECE_HELP5 = "スペースはスライドできません。"
  #==============================================================================
  # ■ 音の設定 ※ファイル名を指定 ※Audioフォルダ内 #()のファイル名
  #==============================================================================
  BGM = "019-Field02"              # 25パズル実行中のBGM(BGM)
  DECISION_SE = "002-System02"     # 決定キーの効果音(SE)
  CANCEL_SE = "003-System03"       # キャンセルキーの効果音(SE)
  #--------------------------------------------------------------------------
  MOVE_SE = "046-Book01"           # ピース移動の効果音(SE)
  BUZZER_SE = "004-System04"       # ブザー音の効果音(SE)
  HIT_ME_MAX = "009-Fanfare03"     # 大当りの効果音(ME)
  HIT_ME = "007-Fanfare01"         # 当りの効果音(ME)
  NO_ITEM_ME = "016-Shock01"       # 景品無しの効果音(ME)
  #--------------------------------------------------------------------------
  ME_MAX_TIME = 12                 # 大当りの待ち時間(HIT_ME_MAXの演奏時間(秒))
  ME_TIME = 4                      # 当りの待ち時間(HIT_MEの演奏時間(秒))
  #==============================================================================
  # ■ アイコン設定 ※Iconsフォルダ内のファイル名を指定
  #==============================================================================
  COIN_ICON = "icon_coin"          # コインのアイコン
  GOLD_ICON = "icon_gold"          # お金のアイコン
  #==============================================================================
  # ■ ゲーム設定
  #==============================================================================
  SPEED = 10                       # ピースアニメ(大=遅い)
  
  PC_STOP = true                   # ゲームの更新が止まった場合、パネルを中断する
  PC_STOP_COUNT = 0.2              # ゲーム停止時間(小=速い)
  #==============================================================================
  # ■ 25パズルタイプの設定
  # COIN[n] = value　※n=タイプ番号($game_temp.puzzle25_type から参照される)
  #==============================================================================
  COIN = [] # value=消費コイン
  COIN[0] = 500 # 1ゲーム500
  COIN[1] = 50
  COIN[2] = 5
  #==============================================================================
  # RAND[n] = value
  # n=タイプ番号($game_temp.puzzle25_type から参照される)
  # value=ピースシャッフル基本回数(value以下の場合)
  #--------------------------------------------------------------------------
  RAND = []
  RAND[0] = 100
  RAND[1] = 50
  RAND[2] = 5
  #==============================================================================
  # ■ TIMEパターンを設定(手動設定)
  # TIME[n] = [ value, ... ]
  #==============================================================================
  # TIME[n] = value
  # n=タイプ番号($game_temp.puzzle25_type から参照される)
  # value=制限時間秒(value以下の場合)
  #--------------------------------------------------------------------------
  TIME = []
  TIME[0] = [30,60,120,180,240,300,360]
  TIME[1] = [30,60,120,180,240,300,360]
  TIME[2] = [30,60,120,180,240,300,360]
  #--------------------------------------------------------------------------
  # ME_RATE_MAX[n] = value
  # n=タイプ番号($game_temp.puzzle25_type から参照される)
  # value=大当りの効果音(HIT_ME_MAX)を演奏する獲得コイン数(value以上)
  #--------------------------------------------------------------------------
  ME_RATE_MAX = []
  ME_RATE_MAX[0] = 3 #3番以上は大当たり
  ME_RATE_MAX[1] = 3
  ME_RATE_MAX[2] = 3
  #==============================================================================
  # ■ 景品パターンを設定(手動設定)
  # ITEMS[n] = [ value, ... ]
  #==============================================================================
  # ※valueを必ず1個〜7個指定する(左から1番,2番...)
  #--------------------------------------------------------------------------
  # "i(ID)"      …i=アイテム,ID=アイテムID
  # "w(ID)"      …w=武器,ID=武器ID
  # "a(ID)"      …a=防具,ID=防具ID
  # "g(num)"     …g=お金,num=金額
  # "c(num)"     …c=コイン,num=枚数
  #==============================================================================
  ITEMS = []
  ITEMS[0] = ["w1","i5","c1000","g2500","a1","i1","g100"]
  ITEMS[1] = ["w1","i5","c1000","g2500","a1","i1","g100"]
  ITEMS[2] = ["w1","i5","c1000","g2500","a1","i1","g100"]
  #==============================================================================
  # ■ 景品リストを設定(手動設定)
  # ※指定した景品からランダムに決定される
  #==============================================================================
  # LIST[n] = [ value, ... ]
  # n=パターン番号($game_temp.puzzle25_type から参照される)
  # value= ITEMS[n]のn番号を指定
  #==============================================================================
  LIST= []
  LIST[0]= [0,1,2]
  LIST[1]= [0,0,0,0,1,1,2]
  LIST[2]= [0,0,1,1,2]
  #==============================================================================
  # ■ 文字色設定
  #==============================================================================
  A_COLOR = Color.new(255,255,255,255)     # 通常色
  B_COLOR = Color.new(0,0,0,255)           # 影色
  S_COLOR = Color.new(255,255,0,255)       # システム色
  F_COLOR = Color.new(255,255,0,255)       # カーソル点滅色
  M_COLOR = Color.new(255,255,255,255)     # 通常色
  N_COLOR = Color.new(100,100,100,255)     # 無効色
  P_COLOR = Color.new(255,255,255,255)     # ピース点滅色
  #==============================================================================
  # ■ メニュー文字設定
  #==============================================================================
  WORD1 = "Coin"
  WORD2 = "Shuffle"
  WORD3 = "Time"
  WORD4 = "Slide"
  WORD5 = "Hi Score"
  WORD6 = "枚"
  #--------------------------------------------------------------------------
  # 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 = ["ＭＳ ゴシック"]               # フォント名
  #--------------------------------------------------------------------------
  # Item の文字設定
  #--------------------------------------------------------------------------
  I_SIZE = 22                              # 文字サイズ
  I_BOLD = false                           # 太文字フラグ[true/false]
  I_ITALIC = false                         # 斜め文字フラグ[true/false]
  I_SHADOW = false                         # 影文字フラグ[true/false]
  I_ROUND = false                          # 囲み文字フラグ[true/false]
  I_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","ＭＳ ゴシック"]       # フォント名
  #--------------------------------------------------------------------------
  # 選択肢 の文字設定
  #--------------------------------------------------------------------------
  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","ＭＳ ゴシック"]     # フォント名
  #--------------------------------------------------------------------------
  # システム の文字設定
  #--------------------------------------------------------------------------
  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)
  M_FONT = Copy_Font.new(18,true,false,false,false,["Arial","ＭＳ ゴシック"],M_COLOR,B_COLOR)
  I_FONT = Copy_Font.new(I_SIZE,I_BOLD,I_ITALIC,I_SHADOW,I_ROUND,I_NAME,A_COLOR,B_COLOR)
  #==============================================================================
end
#==============================================================================
# ■ Scene_25Puzzle
#==============================================================================
class Scene_25Puzzle
  include HIDE_25PUZZLE
  #--------------------------------------------------------------------------
  # ■ オブジェクト初期化
  #--------------------------------------------------------------------------
  def initialize
    # □マップ BGM を記憶し、BGM を停止
    $game_temp.map_bgm = $game_system.playing_bgm
    $game_system.bgm_stop
    # □25パズル BGM を演奏
    $game_system.bgm_play(RPG::AudioFile.new(HIDE_25PUZZLE::BGM))
  end
  #--------------------------------------------------------------------------
  # ■ 競合対策(初期化)
  #--------------------------------------------------------------------------
  def format?
    if $game_party.puzzle25_times == nil
      $game_party.puzzle25_times = []
    end
  end
  #--------------------------------------------------------------------------
  # ■ メイン処理
  #--------------------------------------------------------------------------
  def main
    # □タイプを取得
    t = $game_temp.puzzle25_type
    # □掛け金を取得
    @coin = HIDE_25PUZZLE::COIN[t]
    # □シャッフル基本回数を取得
    @rand = HIDE_25PUZZLE::RAND[t]
    # □競合対策(初期化)
    format?
    # □初期化
    if $game_party.puzzle25_times[t] == nil
      $game_party.puzzle25_times[t] = [[nil,nil]]*11
      $game_party.puzzle25_times[t][0] = [0,0]
    end
    @shuffle = 0 ; @slide = 0
    @playing = false
    #…………………………………………………………………………………………………
    # ■文字装飾を取得
    #…………………………………………………………………………………………………
    @s_font = HIDE_25PUZZLE::S_FONT.dup ; @h_font = HIDE_25PUZZLE::H_FONT
    @c_font = HIDE_25PUZZLE::C_FONT ; @b_font = HIDE_25PUZZLE::T_FONT
    @m_font = HIDE_25PUZZLE::M_FONT
    #…………………………………………………………………………………………………
    # ■25パズルウィンドウ背景を作成
    #…………………………………………………………………………………………………
    @puzzle25_window_back = Picture_Blink_Cursor.new(RPG::Cache.windowskin(HIDE_25PUZZLE::BACK))
    # □フレームの描画
    frame = RPG::Cache.windowskin(HIDE_25PUZZLE::FRAME2)
    @puzzle25_window_back.draw_background(frame,18,358,160,64)
    @puzzle25_window_back.draw_background(frame,408,34,220,320)
    frame = RPG::Cache.windowskin(HIDE_25PUZZLE::FRAME1)
    @puzzle25_window_back.draw_background(frame,464,432,160,32)
    #…………………………………………………………………………………………………
    # ■25パズルBOXを作成
    #…………………………………………………………………………………………………
    @puzzle25_window_top = Picture_Blink_Cursor.new(RPG::Cache.windowskin(HIDE_25PUZZLE::TOP))
    #…………………………………………………………………………………………………
    # ■ゲーム開始選択ウィンドウを作成
    #…………………………………………………………………………………………………
    pic = RPG::Cache.windowskin(HIDE_25PUZZLE::SELECT)
    icon = RPG::Cache.windowskin(HIDE_25PUZZLE::CURSOR)
    com = HIDE_25PUZZLE::GAME_COMS
    helps = HIDE_25PUZZLE::GAME_HELPS
    @game_select_window = Picture_Blink_Cursor.new(16,432,96,32,16,0,com.size,com.size)
    @game_select_window.z = 100+5
    @game_select_window.draw_cursor(pic,com,@s_font,icon)
    @game_select_window.start(100+5)
    # □ヘルプウィンドウの関連付け
    @game_select_window.make_helps(206,389,helps,@h_font)
    #…………………………………………………………………………………………………
    # ■文字を描画
    #…………………………………………………………………………………………………
    wold = HIDE_25PUZZLE::WORD1 + " x " + @coin.to_s
    @puzzle25_window_top.bitmap.draw_cache_text(296,350,320,32,wold,2,@b_font)
    m_font = @m_font.dup
    m_font.size = 14
    text = "A piece is slid."
    @puzzle25_window_top.draw_text(4,28,160,0,text,1,m_font)
    text = "Please rearrange"
    @puzzle25_window_top.draw_text(4,28+16,160,0,text,1,m_font)
    text = "the number of"
    @puzzle25_window_top.draw_text(4,28+16*2,160,0,text,1,m_font)
    text = "1 to 24 in order."
    @puzzle25_window_top.draw_text(4,28+16*3,160,0,text,1,m_font)
    #…………………………………………………………………………………………………
    # ■25パズルを作成
    #…………………………………………………………………………………………………
    @puzzle25_piece = Window_Puzzle25.new
    move_piece?(@puzzle25_piece.items)
    items = [] ; @first_items = []
    for i in 1..24
      items.push(sprintf("%02d",i))
      @first_items.push(sprintf("%02d",i))
    end
    items.push("x")
    @first_items.push("x")
    #…………………………………………………………………………………………………
    # ■ピース選択
    #…………………………………………………………………………………………………
    pic = RPG::Cache.windowskin(HIDE_25PUZZLE::CURSOR_P)
    @cursor_window = Puzzle25_Cursor.new(77,145,61,61,0,0,25,5)
    @cursor_window.x_es = @puzzle25_piece.x_es
    @cursor_window.y_es = @puzzle25_piece.y_es
    @cursor_window.draw_back = false
    @cursor_window.items = items
    @cursor_window.draw_cursor(pic,nil,nil,icon,nil)
    @cursor_window.draw_icon_cursor(icon,100+5)
    #…………………………………………………………………………………………………
    # ■簡易ピース選択
    #…………………………………………………………………………………………………
    @s_cursor_window = Puzzle25_Cursor.new(20,300,17,17,0,0,25,5)
    @s_cursor_window.x_es = @puzzle25_piece.sx_es
    @s_cursor_window.y_es = @puzzle25_piece.sy_es
    @s_cursor_window.draw_back = false
    @s_cursor_window.draw_color_cursor(HIDE_25PUZZLE::A_COLOR.dup)
    @s_cursor_window.items = items
    @s_cursor_window.z = 0
    # □ヘルプウィンドウの関連付け
    @helps1 = [] ; @helps2 = []
    h0 = HIDE_25PUZZLE::PIECE_HELP1
    h1 = HIDE_25PUZZLE::PIECE_HELP2
    h2 = HIDE_25PUZZLE::PIECE_HELP3
    h3 = HIDE_25PUZZLE::PIECE_HELP4
    h4 = HIDE_25PUZZLE::PIECE_HELP5
    for i in 0...25
      @helps1.push(h0 + i.to_s + h1) ; @helps2.push(h0 + i.to_s + h2)
    end
    @helps1.push(h4)
    @helps2.push(h3)
    @helps1 += @helps2
    @s_cursor_window.make_helps(206,389,@helps1,@h_font)
    #…………………………………………………………………………………………………
    # ■描画
    #…………………………………………………………………………………………………
    # □シャッフル回数の描画
    y = 358
    @puzzle25_window_top.draw_text(28,y,0,0,HIDE_25PUZZLE::WORD2,0,@b_font)
    @puzzle25_window_top.draw_text(28,y+16,0,0,HIDE_25PUZZLE::WORD3,0,@b_font)
    @puzzle25_window_top.draw_text(28,y+32,0,0,HIDE_25PUZZLE::WORD4,0,@b_font)
    a_font = @m_font.dup
    @puzzle25_window_top.draw_text(84,y,80,0,@shuffle.to_s,2,@m_font)
    @puzzle25_window_top.draw_text(132+5,y+15,0,0,":",0,@m_font)
    # □PLAY回数の描画
    draw_play?
    #…………………………………………………………………………………………………
    # ■当り演出ウィンドウを作成
    #…………………………………………………………………………………………………
    @puzzle25_hit_window = Picture_Blink_Cursor.new
    @puzzle25_hit_window.start(0)
    #…………………………………………………………………………………………………
    # ■景品を作成
    #…………………………………………………………………………………………………
    @puzzle25_item = Window_25Puzzle_Item.new
    #…………………………………………………………………………………………………
    # ■得点ウィンドウを作成
    #…………………………………………………………………………………………………
    @puzzle25_score = Window_25Puzzle_Score.new
    @puzzle25_score.visible = true
    #…………………………………………………………………………………………………
    # ■選択肢の文字色を初期化
    #…………………………………………………………………………………………………
    exchange_colors?
    #…………………………………………………………………………………………………
    # ■コイン数値ウィンドウを作成
    #…………………………………………………………………………………………………
    @coin_window = Window_digits_number.new(484,416,100,$game_party.coin,10,10,@c_font)
    #…………………………………………………………………………………………………
    # ■タイマーを作成
    #…………………………………………………………………………………………………
    @timer_min = Window_digits_number.new(114,358,100,0,2,0,@m_font)
    @timer_sec = Window_digits_number.new(114+32,358,100,0,2,0,@m_font)
    @timer = false
    @total_sec = 0
    #…………………………………………………………………………………………………
    # ■スライド回数を作成
    #…………………………………………………………………………………………………
    @slide_count = Window_digits_number.new(114+14,374,100,@slide,4,10,@m_font)
    #…………………………………………………………………………………………………
    # ■25パズルBOX(上)を作成
    #…………………………………………………………………………………………………
    @puzzle25_window_top2 = Picture_Blink_Cursor.new(RPG::Cache.windowskin(HIDE_25PUZZLE::TOP2))
    # トランジション実行
    Graphics.transition
    # メインループ
    loop do
      # ゲーム画面を更新
      Graphics.update
      # 入力情報を更新
      Input.update
      # フレーム更新
      update
      # 画面が切り替わったらループを中断
      if $scene != self
        break
      end
    end
    # トランジション準備
    Graphics.freeze
    # ウィンドウを解放
    @puzzle25_window_back.dispose
    @puzzle25_window_top.dispose
    @puzzle25_window_top2.dispose
    @cursor_window.dispose
    @s_cursor_window.dispose
    @game_select_window.dispose
    @puzzle25_piece.dispose
    @puzzle25_score.dispose
    @puzzle25_item.dispose
    @coin_window.dispose
    @timer_min.dispose
    @timer_sec.dispose
    @slide_count.dispose
    @puzzle25_hit_window.dispose
  end
  #--------------------------------------------------------------------------
  # ■ 選択肢の色更新
  #--------------------------------------------------------------------------
  def exchange_colors?
    @game_select_window.exchange[0] = $game_party.coin < @coin
    s = [[nil,nil]]*11
    s[0] = [0,0]
    t = $game_temp.puzzle25_type
    @game_select_window.exchange[2] = $game_party.puzzle25_times[t] == s
    @game_select_window.refresh
  end
  #--------------------------------------------------------------------------
  # ■ PLAY回数の描画
  #--------------------------------------------------------------------------
  def draw_play?(n = 0, play = 0)
    t = $game_temp.puzzle25_type
    data = $game_party.puzzle25_times[t][0]
    t0 = data[0] ; t1 = data[1]
    $game_party.puzzle25_times[t][0][0] = [[t0 + n, 0].max, 99999].min
    $game_party.puzzle25_times[t][0][1] = [[t1 + play, 0].max, 99999].min
    text = t0.to_s + " / " + t1.to_s
    @puzzle25_window_top.draw_text(640-160-24,8,160,0,text,2,@m_font)
  end
  #--------------------------------------------------------------------------
  # ■ PC時間経過によるタイマーの強制終了
  #--------------------------------------------------------------------------
  def pc_time_stop?
    unless HIDE_25PUZZLE::PC_STOP
      return false
    end
    # □PC時間を保存
    @pc_time = Time.now
    if @pc_old_time != nil
      return @pc_old_time < @pc_time - HIDE_25PUZZLE::PC_STOP_COUNT
    elsif @timer
      pc_time?
    end
    return false
  end
  #--------------------------------------------------------------------------
  # ■ PC時間の取得
  #--------------------------------------------------------------------------
  def pc_time?
    # □PC時間を取得
    @pc_time = Time.now
    if Graphics.frame_count / Graphics.frame_rate != @pc_skip_sec
      # □PC時間を保存
      if @pc_old_time == nil
        @pc_old_time = Time.now
      end
      @pc_old_time += 1
      @total_sec = [[@total_sec + 1,0].max,5999].min
    end
    @pc_skip_sec = Graphics.frame_count / Graphics.frame_rate
    min = @total_sec / 60
    sec = @total_sec % 60
    @timer_min.refresh([[min,0].max,99].min)
    @timer_sec.refresh([[sec,0].max,59].min)
  end
  #--------------------------------------------------------------------------
  # ■ フレーム更新
  #--------------------------------------------------------------------------
  def update
    #…………………………………………………………………………………………………
    # ■ PC時間経過によるタイマーの強制終了
    #…………………………………………………………………………………………………
    if @cursor_window.active
      if pc_time_stop? && HIDE_25PUZZLE::PC_STOP && HIDE_25PUZZLE::DEBUG == false
        @total_sec = 5999
        @puzzle25_item.timer = @total_sec
        @puzzle25_item.update
      end
    end
    #…………………………………………………………………………………………………
    # ■ タイマーの更新
    #…………………………………………………………………………………………………
    if @timer
      # □PC時間の取得
      pc_time?
    end
    # □回転数値の更新(所持コイン)
    @coin_window.update($game_party.coin)
    @slide_count.refresh(@slide)
    #…………………………………………………………………………………………………
    # ■ ピースの演出を更新
    #…………………………………………………………………………………………………
    if @cursor_window.active
      flash_piece?(@cursor_window.items)
    end
    #…………………………………………………………………………………………………
    # ■ 当りの演出を更新
    #…………………………………………………………………………………………………
    @puzzle25_hit_window.update
    #…………………………………………………………………………………………………
    # ■ 景品の更新
    #…………………………………………………………………………………………………
    @puzzle25_item.timer = @total_sec
    @puzzle25_item.update
    #…………………………………………………………………………………………………
    # ■ ゲーム開始ウィンドウの更新
    #…………………………………………………………………………………………………
    if @game_select_window.active
      @game_select_window.update
      update_select
      return
    end
    #…………………………………………………………………………………………………
    # ■ ピース選択の更新
    #…………………………………………………………………………………………………
    if @cursor_window.active
      @cursor_window.update
      @s_cursor_window.update
      update_help
      cursor_table_update
      return
    end
  end
  #--------------------------------------------------------------------------
  # ■ Xのindexを取得
  #--------------------------------------------------------------------------
  def x_index?(i,items)
    x_pos = nil
    for n in [i-5,i+5,i-1,i+1]
      if items[n] == "x" && n > -1 && n < 25
        x_pos = n
        break
      end
    end
    return x_pos
  end
  #--------------------------------------------------------------------------
  # ■ ピースのランダム移動
  #--------------------------------------------------------------------------
  def rand_piece?(x,window)
    # □指定回数だけループ
    while x > 0
      i = nil
      for n in 0...25
        if window.items[n] == "x"
          i = n
          break
        end
      end
      x_pos = []
      for n in [i-5,i+5,i-1,i+1]
        if n > -1 && n < 25
          x_pos.push(n)
        end
      end
      r = x_pos[rand(x_pos.size)]
      window.items[i],window.items[r] = 
      window.items[r],window.items[i]
      x -= 1
      @shuffle += 1
    end
    # □Xが初期位置に戻るまでループ
    i = nil ; @i_loop = nil
    while @i_loop != 24
      for n in 0...25
        if window.items[n] == "x"
          i = n
          @i_loop = n
          break
        end
      end
      x_pos = []
      for n in [i-5,i+5,i-1,i+1]
        if n > -1 && n < 25
          x_pos.push(n)
        end
      end
      r = x_pos[rand(x_pos.size)]
      window.items[i],window.items[r] = 
      window.items[r],window.items[i]
      @shuffle += 1
    end
    # □Xを初期位置に移動
    if i != nil && r != nil
      window.items[i],window.items[r] = 
      window.items[r],window.items[i]
      @shuffle += 1
    end
    # □更新
    window.refresh
  end
  #--------------------------------------------------------------------------
  # ■ ピースの点滅演出
  #--------------------------------------------------------------------------
  def flash_piece?(items)
    if @count == nil
      @count = 0
    end
    @animas = [0,1,2,3]
    oy = @animas[@count/HIDE_25PUZZLE::SPEED]*61
    @count += 1
    if @count == @animas.size*HIDE_25PUZZLE::SPEED
      @count = 0
    end
    n = items.index("x")
    x_pos = []
    for i in [n-5,n+5]
      if items[i] != nil
        x_pos.push(i)
      end
    end
    if items[n-1] != nil && (n-1) % 5 < 4
      x_pos.push(n-1)
    end
    if items[n+1] != nil && (n+1) % 5 > 0
      x_pos.push(n+1)
    end
    for i in 0...25
      n = nil
      if items[i] != "x"
        n = items[i].to_i
      end
      if n != nil && @puzzle25_piece.piece[n-1] != nil
        if x_pos.include?(i)
          @puzzle25_piece.piece[n-1].oy = oy
        else
          @puzzle25_piece.piece[n-1].oy = 0
        end
      end
    end
  end
  #--------------------------------------------------------------------------
  # ■ ピースの移動
  #--------------------------------------------------------------------------
  def move_piece?(items)
    for i in 0...25
      n = nil
      if items[i] != "x"
        n = items[i].to_i
      end
      if n != nil && @puzzle25_piece.piece[n-1] != nil
        # □大ピースの移動
        x = @puzzle25_piece.x_es[i] ; y = @puzzle25_piece.y_es[i]
        @puzzle25_piece.piece[n-1].viewport.rect.x = x
        @puzzle25_piece.piece[n-1].viewport.rect.y = y
        # □小ピースの移動
        x = @puzzle25_piece.sx_es[i] ; y = @puzzle25_piece.sy_es[i]
        @puzzle25_piece.s_piece[n-1].viewport.rect.x = x
        @puzzle25_piece.s_piece[n-1].viewport.rect.y = y
        if n-1 == i
          @puzzle25_piece.piece[n-1].ox = 61
          @puzzle25_piece.s_piece[n-1].ox = 17
        else
          @puzzle25_piece.piece[n-1].ox = 0
          @puzzle25_piece.s_piece[n-1].ox = 0
        end
      end
    end
  end
  #--------------------------------------------------------------------------
  # ■ ピースの再描画
  #--------------------------------------------------------------------------
  def refresh_piece?(piece = 0...25)
    @puzzle25_piece.piece.each{ |a| a.oy = 0 }
    for i in piece
      # □大ピースの移動
      x = @puzzle25_piece.x_es[i] ; y = @puzzle25_piece.y_es[i]
      @puzzle25_piece.piece[i].viewport.rect.x = x
      @puzzle25_piece.piece[i].viewport.rect.y = y
      @puzzle25_piece.piece[i].ox = 61
      # □小ピースの移動
      x = @puzzle25_piece.sx_es[i] ; y = @puzzle25_piece.sy_es[i]
      @puzzle25_piece.s_piece[i].viewport.rect.x = x
      @puzzle25_piece.s_piece[i].viewport.rect.y = y
      @puzzle25_piece.s_piece[i].ox = 17
    end
    @cursor_window.items = @first_items.dup
  end
  #--------------------------------------------------------------------------
  # ■ 25番ピースの移動
  #--------------------------------------------------------------------------
  def move_25piece?
    # □大ピースの移動
    x = @puzzle25_piece.x_es[24] + 31*0
    y = @puzzle25_piece.y_es[24] + 31*4
    @puzzle25_piece.piece[24].viewport.rect.x = x
    @puzzle25_piece.piece[24].viewport.rect.y = y
    # □小ピースの移動
    x = @puzzle25_piece.sx_es[24] + 17*2
    y = @puzzle25_piece.sy_es[24]
    @puzzle25_piece.s_piece[24].viewport.rect.x = x
    @puzzle25_piece.s_piece[24].viewport.rect.y = y
  end
  #--------------------------------------------------------------------------
  # ■ ピース選択の更新
  #--------------------------------------------------------------------------
  def cursor_table_update
    #…………………………………………………………………………………………………
    # ■ C ボタンが押された場合
    #…………………………………………………………………………………………………
    if Input.trigger?(Input::C)
      i = @cursor_window.index
      x_pos = x_index?(i,@cursor_window.items)
      if x_pos == nil
        # □ブザー SEを演奏
        $game_system.se_play(RPG::AudioFile.new(HIDE_25PUZZLE::BUZZER_SE))
      else
        # □ゲーム開始
        @cursor_window.items[i],@cursor_window.items[x_pos] = 
        @cursor_window.items[x_pos],@cursor_window.items[i]
        move_piece?(@cursor_window.items)
        # □ヘルプの更新
        @old_help_id = nil
        # □移動 SEを演奏
        $game_system.se_play(RPG::AudioFile.new(HIDE_25PUZZLE::MOVE_SE))
        @slide = [[@slide + 1,0].max,9999].min
        #…………………………………………………………………………………………………
        # ■ 当りの場合
        #…………………………………………………………………………………………………
        if @cursor_window.items == @first_items
          @cursor_window.visible = false
          @timer = false
          # □25番ピースの移動
          refresh_piece?([24])
          a = HIDE_25PUZZLE::TIME[$game_temp.puzzle25_type]
          c = -1
          for n in 0...a.size
            if @total_sec <= a[n]
              c = n
              break
            end
          end
          #…………………………………………………………………………………………………
          # ■ スコアの更新
          #…………………………………………………………………………………………………
          scors = [] ; times = []
          now = Time.now
          t = $game_temp.puzzle25_type
          s_break = false
          num = 1
          for i in 1...$game_party.puzzle25_times[t].size
            unless s_break
              if $game_party.puzzle25_times[t][i][0] == nil
                $game_party.puzzle25_times[t][i] = [@total_sec,now]
                num = i
                s_break = true
              else
                if $game_party.puzzle25_times[t][i][0] > @total_sec
                  scors = [@total_sec]
                  times = [now]
                  for n in i...$game_party.puzzle25_times[t].size-1
                    scors.push($game_party.puzzle25_times[t][n][0])
                    times.push($game_party.puzzle25_times[t][n][1])
                  end
                  num = i
                  s_break = true
                end
              end
            end
          end
          # □スコアの並び替え
          s = 0
          if scors != [] && times != []
            for n in num...$game_party.puzzle25_times[t].size
              $game_party.puzzle25_times[t][n] = [scors[s],times[s]]
              s += 1
            end
          end
          @s_cursor_window.help_id = 25+26
          @s_cursor_window.update_help
          @puzzle25_score.refresh
          # □PLAY回数の加算(成功回数)
          draw_play?(1,0)
          #…………………………………………………………………………………………………
          # ■ 時間切れ
          #…………………………………………………………………………………………………
          if c < 0
            @puzzle25_hit_window.bitmap.clear
            @puzzle25_piece.flash_end
            # □ゲーム再開
            replay?
            return
          end
          #…………………………………………………………………………………………………
          # ■ アイテムの取得
          #…………………………………………………………………………………………………
          gain_treasures?(@puzzle25_item.type[c])
          #…………………………………………………………………………………………………
          # ■ 当たりを点滅
          #…………………………………………………………………………………………………
          b = HIDE_25PUZZLE::ME_RATE_MAX[$game_temp.puzzle25_type]
          if @total_sec <= a[b]
            $game_system.me_play(RPG::AudioFile.new(HIDE_25PUZZLE::HIT_ME_MAX))
            # □次の25パズル開始まで待つ(MEの演奏時間)
            time_up = HIDE_25PUZZLE::ME_MAX_TIME
          else
            $game_system.me_play(RPG::AudioFile.new(HIDE_25PUZZLE::HIT_ME))
            # □次の25パズル開始まで待つ(MEの演奏時間)
            time_up = HIDE_25PUZZLE::ME_TIME
          end
          # □当たりを点滅
          flash = RPG::Cache.windowskin(HIDE_25PUZZLE::HIT)
          @puzzle25_hit_window.draw_flash(flash,410,52+45*c,214,32)
          #…………………………………………………………………………………………………
          # ■ 次の25パズル開始まで待つ
          #…………………………………………………………………………………………………
          time = 0
          while time < time_up
            # □ゲーム画面を更新
            Graphics.update
            # □回転数値の更新(所持コイン)
            @coin_window.update($game_party.coin)
            # □当りの演出を更新
            @puzzle25_hit_window.update
            if @puzzle25_hit_window.count?
              time += 1
            end
            @puzzle25_piece.flash
          end
          @puzzle25_hit_window.bitmap.clear
          @puzzle25_piece.flash_end
          # □ゲーム再開
          replay?
          return
        else
          @timer = true
          move_25piece?
        end
      end
    end
    #…………………………………………………………………………………………………
    # ■ B ボタンが押された場合
    #…………………………………………………………………………………………………
    if Input.trigger?(Input::B)
      # □キャンセルSEを演奏
      $game_system.se_play(RPG::AudioFile.new(HIDE_25PUZZLE::CANCEL_SE))
      # □ゲーム再開
      replay?
      return
    end
  end
  #--------------------------------------------------------------------------
  # ■ ゲーム再開
  #--------------------------------------------------------------------------
  def replay?
    @puzzle25_score.visible = true
    @puzzle25_item.visible = false
    @s_cursor_window.help_id = 25
    @s_cursor_window.update_help
    @playing = false
    refresh_piece?
    @cursor_window.index = -1
    @cursor_window.active = false
    @cursor_window.visible = false
    @s_cursor_window.index = -1
    @s_cursor_window.active = false
    @s_cursor_window.visible = false
    @pc_old_time = nil
    @total_sec = 0
    @timer = false
    @game_select_window.active = true
  end
  #--------------------------------------------------------------------------
  # ■ フレーム更新(ゲーム開始)
  #--------------------------------------------------------------------------
  def update_select
    #…………………………………………………………………………………………………
    # ■ C ボタンが押された場合
    #…………………………………………………………………………………………………
    if Input.trigger?(Input::C)
      case @game_select_window.index
      when 0 #□ゲーム開始
        if $game_party.coin >= @coin
          # □決定SEを演奏
          $game_system.se_play(RPG::AudioFile.new(HIDE_25PUZZLE::DECISION_SE))
          # □ゲーム開始
          @puzzle25_score.visible = false
          @puzzle25_item.visible = true
          # □ランダムに景品リストを選択
          @puzzle25_item.item_type?
          # □カーソル位置の初期化
          @cursor_window.index = 24
          @cursor_window.active = true
          @cursor_window.visible = true
          @s_cursor_window.index = 24
          @s_cursor_window.active = true
          @s_cursor_window.visible = true
          game_start?
        # □コインが足りない場合
        else
          # □ブザー SE を演奏
          $game_system.se_play(RPG::AudioFile.new(HIDE_25PUZZLE::BUZZER_SE))
          return
        end
      when 1 #□ゲーム終了
        # □決定SEを演奏
        $game_system.se_play(RPG::AudioFile.new(HIDE_25PUZZLE::DECISION_SE))
        @playing = false
        puzzle25_end
      when 2 #□スコアの初期化
        s = [[nil,nil]]*11
        s[0] = [0,0]
        t = $game_temp.puzzle25_type
        if $game_party.puzzle25_times[t] == s
          # □ブザー SE を演奏
          $game_system.se_play(RPG::AudioFile.new(HIDE_25PUZZLE::BUZZER_SE))
          # □選択肢の文字色を初期化
          exchange_colors?
          return
        end
        # □決定SEを演奏
        $game_system.se_play(RPG::AudioFile.new(HIDE_25PUZZLE::DECISION_SE))
        t = $game_temp.puzzle25_type
        $game_party.puzzle25_times[t] = [[nil,nil]]*11
        $game_party.puzzle25_times[t][0] = [0,0]
        # □PLAY回数の初期化
        draw_play?
        @puzzle25_score.refresh
        # □選択肢の文字色を初期化
        exchange_colors?
      end
      return
    end
    #…………………………………………………………………………………………………
    # ■ B ボタンが押された場合
    #…………………………………………………………………………………………………
    if Input.trigger?(Input::B)
      # □キャンセルSEを演奏
      $game_system.se_play(RPG::AudioFile.new(HIDE_25PUZZLE::CANCEL_SE))
      @playing = false
      puzzle25_end
      return
    end
  end
  #--------------------------------------------------------------------------
  # ■ ゲームの終了
  #--------------------------------------------------------------------------
  def puzzle25_end
    unless @playing
      # □25パズル開始前の BGM に戻す
      $game_system.bgm_play($game_temp.map_bgm)
      # マップ画面に切り替え
      $scene = Scene_Map.new
      return
    end
  end
  #--------------------------------------------------------------------------
  # ■ 25パズル開始
  #--------------------------------------------------------------------------
  def game_start?
    # □PLAY回数の加算
    draw_play?(0,1)
    @timer = true
    @shuffle = 0
    @slide = 0
    @puzzle25_hit_window.bitmap.clear
    # □ピース位置の初期化
    refresh_piece?
    # □ピースのランダム配置
    while @cursor_window.items == @first_items
      rand_piece?(@rand,@cursor_window)
    end
    # □ピースを移動
    move_piece?(@cursor_window.items)
    # □シャッフル回数を描画
    a_font = @b_font.dup
    a_font.color = Color.new(255,255,255)
    y = 380-22
    @puzzle25_window_top.draw_text(84,y,80,0,@shuffle.to_s,2,a_font)
    # □ピース25を移動
    move_25piece?
    @playing = true
    # □コインを減らす
    $game_party.lose_coin(@coin)
    # □選択肢の文字色を初期化
    exchange_colors?
    @game_select_window.active = false
  end
  #--------------------------------------------------------------------------
  # ■ フレーム更新(ヘルプ)
  #--------------------------------------------------------------------------
  def update_help
    if @old_help_id != @s_cursor_window.index
      i = @s_cursor_window.index
      x_pos = x_index?(i,@cursor_window.items)
      if x_pos == nil && @cursor_window.items != @first_items
        he = 26
      else
        he = 0
      end
      if @cursor_window.items[i] == "x"
        @s_cursor_window.help_id = 25
      else
        @s_cursor_window.help_id = @cursor_window.items[i].to_i + he
      end
      @old_help_id = @s_cursor_window.index
    end
  end
  #--------------------------------------------------------------------------
  # ■ アイテムの獲得
  #--------------------------------------------------------------------------
  def gain_treasures?(treasure)
    treasure.scan(/([iwagc])([0-9]+)/)
    type = $1 ; id = $2
    case type
    when "i"
      $game_party.gain_item(id.to_i,1)
    when "w"
      $game_party.gain_weapon(id.to_i,1)
    when "a"
      $game_party.gain_armor(id.to_i,1)
    when "g" # お金
      $game_party.gain_gold(id.to_i)
    when "c" # コイン
      $game_party.gain_coin(id.to_i)
    end
  end
end
#==============================================================================
# ■ Window_25Puzzle_Score
#==============================================================================
class Window_25Puzzle_Score
  include HIDE_25PUZZLE
  attr_accessor :timer
  #--------------------------------------------------------------------------
  # ■ オブジェクト初期化
  #--------------------------------------------------------------------------
  def initialize
    @item_window = Sprite.new(Viewport.new(0,0,640,480))
    @item_window.bitmap = Bitmap.new(640,480)
    @m_font = HIDE_25PUZZLE::M_FONT ; @b_font = HIDE_25PUZZLE::T_FONT
    @font = @m_font.dup
    @s_font = @b_font.dup
    text = HIDE_25PUZZLE::WORD5
    @item_window.bitmap.draw_cache_text(418,8,160,32,text,0,@s_font)
    @a_color = HIDE_25PUZZLE::A_COLOR.dup
    @c_color = HIDE_25PUZZLE::S_COLOR.dup
    @d_color = HIDE_25PUZZLE::N_COLOR.dup
    @item_window.viewport.visible = false
    refresh
  end
  #--------------------------------------------------------------------------
  # ■ 更新
  #--------------------------------------------------------------------------
  def refresh
    t = $game_temp.puzzle25_type
    for i in 1...$game_party.puzzle25_times[t].size
      draw_item(i)
    end
  end
  #--------------------------------------------------------------------------
  # ■ ウィンドウの可視化
  #--------------------------------------------------------------------------
  def visible=(visible)
    @item_window.viewport.visible = visible
  end
  #--------------------------------------------------------------------------
  # ■ 順位とTimeを描画
  #--------------------------------------------------------------------------
  def draw_item(i,x = 410,y = 10)
    t = $game_temp.puzzle25_type
    cy = 32
    @item_window.bitmap.fill_rect(Rect.new(x+18,y+cy*i,320,cy),Color.new(0,0,0,0))
    @item_window.bitmap.draw_cache_text(x+8,y+cy*i,16,0,i.to_s,2,@s_font)
    time = $game_party.puzzle25_times[t][i][0]
    time_stamp = $game_party.puzzle25_times[t][i][1]
    if time == nil or time_stamp == nil
      return
    end
    min = time == 0 ? "00" : sprintf("%02d",time / 60)
    sec = time == 0 ? "00" : sprintf("%02d",time % 60)
    w = @font.text_width(min) ; h = @font.text_height(min)
    @item_window.bitmap.draw_cache_text(x+38,y+cy*i,w,h,min,0,@font)
    @item_window.bitmap.draw_cache_text(w+x+38+6,y+cy*i-1,w,h,":",0,@font)
    cw = @font.text_width(":")
    @item_window.bitmap.draw_cache_text(cw+w+x+38+12,y+cy*i,w,h,sec,0,@font)
    text = time_stamp.strftime("%Y/%m/%d %H:%M")
    w = @font.text_width(text) ; h = @font.text_height(text)
    @item_window.bitmap.draw_cache_text(cw+w+x-20,y+cy*i,w,h,text,0,@font)
  end
  #--------------------------------------------------------------------------
  # ■ 解放
  #--------------------------------------------------------------------------
  def dispose
    unless @item_window == nil or @item_window.disposed?
      @item_window.viewport.dispose
      @item_window.dispose
    end
  end
end
#==============================================================================
# ■ Window_25Puzzle_Item
#==============================================================================
class Window_25Puzzle_Item
  include HIDE_25PUZZLE
  attr_accessor :timer
  attr_accessor :type
  #--------------------------------------------------------------------------
  # ■ オブジェクト初期化
  #--------------------------------------------------------------------------
  def initialize
    @item_window = Sprite.new(Viewport.new(0,0,640,480))
    @item_window.bitmap = Bitmap.new(640,480)
    @index = 0
    @i_font = HIDE_25PUZZLE::I_FONT ; @b_font = HIDE_25PUZZLE::T_FONT
    @time = HIDE_25PUZZLE::TIME[$game_temp.puzzle25_type]
    @list = HIDE_25PUZZLE::LIST[$game_temp.puzzle25_type]
    @font = @i_font.dup
    @s_font = @b_font.dup
    @s_font.size = 16
    text = HIDE_25PUZZLE::WORD3
    @item_window.bitmap.draw_cache_text(418,8,160,32,text,0,@s_font)
    @a_color = HIDE_25PUZZLE::A_COLOR.dup
    @c_color = HIDE_25PUZZLE::S_COLOR.dup
    @d_color = HIDE_25PUZZLE::N_COLOR.dup
    @item_window.viewport.visible = false
    @item_window.viewport.z = 10
    item_type?
  end
  #--------------------------------------------------------------------------
  # ■ 更新
  #--------------------------------------------------------------------------
  def update
    for t in 0...@time.size
      if @time[t] < @timer && @old_times[t] == false
        @font.color = @d_color
        @s_font.color = @d_color
        @old_times[t] = true
        draw_item(t)
      end
    end
  end
  #--------------------------------------------------------------------------
  # ■ ウィンドウの可視化
  #--------------------------------------------------------------------------
  def visible=(visible)
    @item_window.viewport.visible = visible
  end
  #--------------------------------------------------------------------------
  # ■ ランダムに景品を決定
  #--------------------------------------------------------------------------
  def item_type?
    @timer = 0
    @old_times = [false]*@time.size
    @font.color = @a_color
    @s_font.color = @c_color
    r = @list[rand(@list.size)]
    @type = HIDE_25PUZZLE::ITEMS[r]
    for i in 0...@type.size
      draw_item(i)
    end
  end
  #--------------------------------------------------------------------------
  # ■ 景品とTimeを描画
  #--------------------------------------------------------------------------
  def draw_item(i,x = 410,y = 42)
    @item_window.bitmap.fill_rect(Rect.new(x+18,y+45*i-4,200,45),Color.new(0,0,0,0))
    @item_window.bitmap.draw_cache_text(x+18,y+45*i-4,0,0,@time[i].to_s,0,@s_font)
    name = item_name?(@type[i])
    @item_window.bitmap.draw_cache_text(x+6,y+45*i+10,0,32,name,0,@font)
  end
  #--------------------------------------------------------------------------
  # ■ アイテムの取得
  #--------------------------------------------------------------------------
  def item_name?(treasure)
    treasure.scan(/([iwagc])([0-9]+)/)
    type = $1 ; id = $2
    case type
    when "i"
      name = $data_items[id.to_i].name
      icon = $data_items[id.to_i].icon_name
    when "w"
      name = $data_weapons[id.to_i].name
      icon = $data_weapons[id.to_i].icon_name
    when "a"
      name = $data_armors[id.to_i].name
      icon = $data_armors[id.to_i].icon_name
    when "g" # お金
      name = id.to_s + $data_system.words.gold
      icon = HIDE_25PUZZLE::GOLD_ICON
    when "c" # コイン
      name = id.to_s + HIDE_25PUZZLE::WORD6
      icon = HIDE_25PUZZLE::COIN_ICON
    end
    return "\\icon[" + icon + "]" + name
  end
  #--------------------------------------------------------------------------
  # ■ 解放
  #--------------------------------------------------------------------------
  def dispose
    unless @item_window == nil or @item_window.disposed?
      @item_window.viewport.dispose
      @item_window.dispose
    end
  end
end
#==============================================================================
# ■ Window_Puzzle25
#==============================================================================
class Window_Puzzle25
  include HIDE_25PUZZLE
  attr_accessor :piece
  attr_accessor :s_piece
  attr_accessor :items
  attr_accessor :x_es
  attr_accessor :y_es
  attr_accessor :sx_es
  attr_accessor :sy_es
  #--------------------------------------------------------------------------
  # ■ オブジェクト初期化
  #--------------------------------------------------------------------------
  def initialize
    @piece = [] ; @viewports1 = [] ; @items = []
    @s_piece = [] ;  ; @viewports2 = [] ; @sx_es = [] ; @sy_es = []
    @x_es = [] ; @y_es = []
    pic = RPG::Cache.windowskin(HIDE_25PUZZLE::PIECE)
    pic1 = RPG::Cache.windowskin(HIDE_25PUZZLE::PIECE_S)
    num = RPG::Cache.windowskin(HIDE_25PUZZLE::NUMBER)
    # □25パズルを作成
    for i in 0...25
      ex = 77+31*(i%5)+(i/5)*31
      ey = 145-31*(i%5)+(i/5)*31
      @x_es.push(ex) ; @y_es.push(ey) ; @items.push(i+1)
      @viewports1[i] = Viewport.new(ex,ey,pic.width/2,pic.height/4)
      @piece[i] = Sprite.new(@viewports1[i])
      @piece[i].bitmap = Bitmap.new(pic.width,pic.height)
      @piece[i].bitmap.blt(0,0,pic,Rect.new(0,0,pic.width,pic.height))
      for y in 0...4
        @piece[i].bitmap.blt(18,17+y*61,num,Rect.new(i/5*25,i%5*25,num.width/5,num.height/5))
        @piece[i].bitmap.blt(18+61,17+y*61,num,Rect.new(i/5*25,i%5*25,num.width/5,num.height/5))
      end
      # □小25パズルを作成
      ex = i%5*17+20
      ey = i/5*17+300-36
      @sx_es.push(ex) ; @sy_es.push(ey)
      @viewports2[i] = Viewport.new(ex,ey,17,17)
      @s_piece[i] = Sprite.new(@viewports2[i])
      @s_piece[i].bitmap = Bitmap.new(17*2,17*2)
      @s_piece[i].bitmap.blt(0,0,pic1,Rect.new(i/5*17,i%5*17,17,17))
      @s_piece[i].bitmap.blt(17,0,pic1,Rect.new(i/5*17+85,i%5*17,17,17))
    end
    @piece_flash = 150
    @s_piece.each{|a| a.viewport.z = 100}
  end
  #--------------------------------------------------------------------------
  # ■ ピースの点滅更新
  #--------------------------------------------------------------------------
  def flash
    if @blink_opa
      if @piece_flash >= 150
        @blink_opa = false
      end
      @back_opa = -5
    else
      if @piece_flash <= 0
        @blink_opa = true
      end
      @back_opa = 5
    end
    f1 = HIDE_25PUZZLE::P_COLOR
    @piece_flash -= @back_opa
    @piece.each{ |a| a.flash(Color.new(f1.red,f1.green,f1.blue,@piece_flash),0) }
  end
  #--------------------------------------------------------------------------
  # ■ ピースの点滅更新の終了
  #--------------------------------------------------------------------------
  def flash_end
    @piece_flash = 150
    @piece.each{ |a| a.flash(Color.new(0,0,0,0),0) }
  end
  #--------------------------------------------------------------------------
  # ■ 解放
  #--------------------------------------------------------------------------
  def dispose
    @piece.each{ |a| a.viewport.dispose ; a.bitmap.dispose }
    @piece.each{ |a| a.dispose }
    @s_piece.each{ |a| a.viewport.dispose ; a.bitmap.dispose }
    @s_piece.each{ |a| a.dispose }
  end
end
#==============================================================================
# ■ Puzzle25_Cursor
#==============================================================================
class Puzzle25_Cursor < Picture_Blink_Cursor
  attr_accessor :x_es
  attr_accessor :y_es
  attr_accessor :help_id
  #--------------------------------------------------------------------------
  # ■ オブジェクト初期化
  #--------------------------------------------------------------------------
  def initialize(x = 0,y = 0,width = 640,height = 480,
    cx = 0,cy = 0,max = 1,column = 1,back = false)
    super
    @x_es = [] ; @y_es = []
    @help_id = -1
  end
  #--------------------------------------------------------------------------
  # ■ 点滅色の設定
  #--------------------------------------------------------------------------
  def draw_color(color = @back_color,alpha = @back_alpha)
    color.alpha = 200
    for i in 0...@item_max
      x = (i % @column_max) * @cx
      y = (i / @column_max) * @cy
      @picture_blink.bitmap.fill_rect(Rect.new(x+4,y+4,@width-8,@height-8),color)
    end
    @draw_blink = true
    @back_color = color
  end
  #--------------------------------------------------------------------------
  # ■ カーソルの矩形更新
  #--------------------------------------------------------------------------
  def update_cursor_rect
    if @zero
      @active = false
      self.visible = false
      return
    end
    # □カーソルの座標を計算
    x = @x_es[@index]
    y = @y_es[@index]
    @picture_blink.viewport.rect.x = x
    @picture_blink.viewport.rect.y = y
    @picture_blink.viewport.ox = @index % @column_max * @cx
    @picture_blink.viewport.oy = @index / @column_max * @cy
    # □カーソルアイコンの座標を計算
    unless @csr4_icon.nil? or @csr4_icon.disposed?
      @csr4_icon.viewport.rect.x = x - @cursor_x
      h0 = @picture_blink.viewport.rect.height / 2
      h1 = @csr4_icon.viewport.rect.height / 2
      @csr4_icon.viewport.rect.y = y + (h0 - h1)
    end
  end
  #--------------------------------------------------------------------------
  # ■ ヘルプテキスト更新
  #--------------------------------------------------------------------------
  def update_help
    unless @picture_help.nil? or @picture_help.disposed?
      @picture_help.oy = @help_id*32
      @picture_help.visible = @active
    end
  end
end