game.loading do |loader|
loader.add :window, :system => "window"
loader.add :gui_item, :system => "gui_item"
loader.add :aite, 0
loader.add :you, 1
loader.add :win_count, 2
loader.add :lose_count, 3
loader.add :chain_count, 4
end
# ゲーム全体で使うデータ
# 定数に入れておいて、関数で同じインスタンスを返すようにする
LOCAL_DATA_CONSTANT = {}
def local_data
LOCAL_DATA_CONSTANT
end
#変数初期化
local_data[:win_count] = 0
local_data[:lose_count] = 0
game.on_init do
set_window_image :window
set_gui_image :gui_item
speak("じゃんけんゲームへようこそ")
scene_change :serect_scene
end
scene :serect_scene do |scene|
#連勝カウント初期化
local_data[:chain_count] = 0
#何するか選択
text = scene.text :position => [300, 410]
text.set_text_area_size 250, 200
text.set_font_point_size 32
text.set_text ("どうしますか?")
text = scene.text :position => [50, 100]
text.set_text_area_size 250, 80
text.set_font_point_size 32
text.set_text ("じゃんけんする")
text.event :on_click do |event|
scene_change :battle_scene
end
text = scene.text :position => [50, 180]
text.set_text_area_size 250, 80
text.set_font_point_size 32
text.set_text ("戦績を見る")
text.event :on_click do |event|
scene_change :log_scene
end
text = scene.text :position => [50, 260]
text.set_text_area_size 250, 80
text.set_font_point_size 32
text.set_text ("終了する")
text.event :on_click do |event|
speak("プレーありがとうございました。")
scene_change :end_scene
end
end
scene :battle_scene do |scene|
local_data[:aite] = rand(3) #相手の手
#出す手を選択
text = scene.text :position => [170, 410]
text.set_text_area_size 400, 200
text.set_font_point_size 32
text.set_text ("出す手を選択してください。")
text = scene.text :position => [50, 100]
text.set_text_area_size 250, 200
text.set_font_point_size 32
text.set_text ("グー")
text.event :on_click do |event|
local_data[:you] = 0
scene_change :result_scene
end
text = scene.text :position => [250, 100]
text.set_text_area_size 250, 200
text.set_font_point_size 32
text.set_text ("チョキ")
text.event :on_click do |event|
local_data[:you] = 1
scene_change :result_scene
end
text = scene.text :position => [450, 100]
text.set_text_area_size 250, 200
text.set_font_point_size 32
text.set_text ("パー")
text.event :on_click do |event|
local_data[:you] = 2
scene_change :result_scene
end
end
scene :result_scene do |scene|
#相手の手を表示
case local_data[:aite]
when 0
speak("相手はグーを出した!")
when 1
speak("相手はチョキを出した!")
when 2
speak("相手はパーを出した!")
end
#勝敗表示
if (local_data[:aite] - local_data[:you]) == 1
speak("あなたの勝ち")
local_data[:win_count] += 1
local_data[:chain_count] += 1
elsif (local_data[:aite] - local_data[:you]) == -2
speak("あなたの勝ち")
local_data[:win_count] += 1
local_data[:chain_count] += 1
elsif (local_data[:aite] - local_data[:you]) == -1
speak("あなたの負け")
local_data[:lose_count] += 1
local_data[:chain_count] = 0
elsif (local_data[:aite] - local_data[:you]) == 2
speak("あなたの負け")
local_data[:lose_count] += 1
local_data[:chain_count] = 0
elsif (local_data[:aite] == local_data[:you])
speak("あいこ")
end
scene_change :more_scene
end
scene :more_scene do |scene|
if (local_data[:aite] != local_data[:you])
if local_data[:chain_count] > 0
speak("現在、" + local_data[:chain_count].to_s + "連勝中!") #連勝表示
end
#続けるか選択
text = scene.text :position => [300, 410]
text.set_text_area_size 250, 200
text.set_font_point_size 32
text.set_text ("続けますか?")
text = scene.text :position => [50, 100]
text.set_text_area_size 250, 80
text.set_font_point_size 32
text.set_text ("はい")
text.event :on_click do |event|
scene_change :battle_scene
end
text = scene.text :position => [50, 180]
text.set_text_area_size 250, 80
text.set_font_point_size 32
text.set_text ("いいえ")
text.event :on_click do |event|
scene_change :serect_scene
end
else
scene_change :battle_scene #あいこなら強制的にもう1回
end
end
scene :log_scene do |scene|
#戦績表示
#コンマを使うと動作しないっぽい
speak("あなたの戦績は" + local_data[:win_count].to_s + "勝" + local_data[:lose_count].to_s + "敗です。")
scene_change :serect_scene
end
scene :end_scene do |scene|
game.change_project "start_menu" #ゲーム終了
end