#試験的に二人対戦と通常モードでは、やり方を変えている。
# ロードする素材の指定
game.loading do |loader|
# speak用window画像のロード
loader.add :windowG, 305
loader.add :gui_item, :system => "gui_item"
#選択用背景
loader.add :backs, 306
loader.add :backs2, 318
#文字
loader.add :tx1, 319
loader.add :tx2, 320
#メイン背景
loader.add :sW, 307
loader.add :sS, 308
loader.add :sT, 309
loader.add :sZ, 310
#その他背景
loader.add :haikei1, 321
loader.add :haikei2, 322
#ターン表示
loader.add :tO, 311
loader.add :tT, 312
#○・×
loader.add :maru, 313
loader.add :batu, 314
loader.add :maruw, 326
loader.add :batuw, 325
#勝敗
loader.add :kati, 315
loader.add :make, 316
loader.add :hiki, 317
#データロード
loader.load_data :game_data, "savedata", :scope => :private, :project_id => 190
end
# ゲーム全体で使うデータ
# 定数に入れておいて、関数で同じインスタンスを返すようにする
LOCAL_DATA_CONSTANT = {}
def local_data
LOCAL_DATA_CONSTANT
end
#データセーブ
def seve(data)
game.load_wait do |loader|
loader.save_data "savedata", data, :scope => :private
end
end
#初級敵AI
def syokyu(a)
if local_data[:zyun] == 0 #敵後攻
s = -1
else
s = 1
end
loop = true
while loop
m = rand(9)
if ((a[1] + a[2] == 2 * s) || (a[4] + a[8] == 2 * s) || (a[3] + a[6] == 2 * s)) && a[0] == 0 #勝てるか
a[0] = s
loop = false
elsif ((a[0] + a[2] == 2 * s) || (a[4] + a[7] == 2 * s)) && a[1] == 0 #勝てるか
a[1] = s
loop = false
elsif ((a[1] + a[0] == 2 * s) || (a[4] + a[6] == 2 * s) || (a[5] + a[8] == 2 * s)) && a[2] == 0 #勝てるか
a[2] = s
loop = false
elsif ((a[0] + a[6] == 2 * s) || (a[4] + a[5] == 2 * s)) && a[3] == 0 #勝てるか
a[3] = s
loop = false
elsif ((a[3] + a[5] == 2 * s) || (a[1] + a[7] == 2 * s) || (a[0] + a[6] == 2 * s) || (a[2] + a[6] == 2 * s)) && a[4] == 0 #勝てるか
a[4] = s
loop = false
elsif ((a[2] + a[8] == 2 * s) || (a[3] + a[4] == 2 * s)) && a[5] == 0 #勝てるか
a[5] = s
loop = false
elsif ((a[0] + a[3] == 2 * s) || (a[7] + a[8] == 2 * s) || (a[2] + a[4] == 2 * s)) && a[6] == 0 #勝てるか
a[6] = s
loop = false
elsif ((a[1] + a[4] == 2 * s) || (a[6] + a[8] == 2 * s)) && a[7] == 0 #勝てるか
a[7] = s
loop = false
elsif ((a[2] + a[5] == 2 * s) || (a[0] + a[4] == 2 * s) || (a[6] + a[7] == 2 * s)) && a[8] == 0 #勝てるか
a[8] = s
loop = false
elsif a[m] == 0 #マスは空いてるか
a[m] = s
loop = false
end
end
end
#中級敵AI
def tyukyu(a)
if local_data[:zyun] == 0 #敵後攻
s = -1
else
s = 1
end
loop = true
while loop
m = rand(9)
if ((a[1] + a[2] == 2 * s) || (a[4] + a[8] == 2 * s) || (a[3] + a[6] == 2 * s)) && a[0] == 0 #勝てるか
a[0] = s
loop = false
elsif ((a[0] + a[2] == 2 * s) || (a[4] + a[7] == 2 * s)) && a[1] == 0 #勝てるか
a[1] = s
loop = false
elsif ((a[1] + a[0] == 2 * s) || (a[4] + a[6] == 2 * s) || (a[5] + a[8] == 2 * s)) && a[2] == 0 #勝てるか
a[2] = s
loop = false
elsif ((a[0] + a[6] == 2 * s) || (a[4] + a[5] == 2 * s)) && a[3] == 0 #勝てるか
a[3] = s
loop = false
elsif ((a[3] + a[5] == 2 * s) || (a[1] + a[7] == 2 * s) || (a[0] + a[8] == 2 * s) || (a[2] + a[6] == 2 * s)) && a[4] == 0 #勝てるか
a[4] = s
loop = false
elsif ((a[2] + a[8] == 2 * s) || (a[3] + a[4] == 2 * s)) && a[5] == 0 #勝てるか
a[5] = s
loop = false
elsif ((a[0] + a[3] == 2 * s) || (a[7] + a[8] == 2 * s) || (a[2] + a[4] == 2 * s)) && a[6] == 0 #勝てるか
a[6] = s
loop = false
elsif ((a[1] + a[4] == 2 * s) || (a[6] + a[8] == 2 * s)) && a[7] == 0 #勝てるか
a[7] = s
loop = false
elsif ((a[2] + a[5] == 2 * s) || (a[0] + a[4] == 2 * s) || (a[6] + a[7] == 2 * s)) && a[8] == 0 #勝てるか
a[8] = s
loop = false
elsif ((a[1] + a[2] == -2 * s) || (a[4] + a[8] == -2 * s) || (a[3] + a[6] == -2 * s)) && a[0] == 0 #負けるか
a[0] = s
loop = false
elsif ((a[0] + a[2] == -2 * s) || (a[4] + a[7] == -2 * s)) && a[1] == 0
a[1] = s
loop = false
elsif ((a[1] + a[0] == -2 * s) || (a[4] + a[6] == -2 * s) || (a[5] + a[8] == -2 * s)) && a[2] == 0
a[2] = s
loop = false
elsif ((a[0] + a[6] == -2 * s) || (a[4] + a[5] == -2 * s)) && a[3] == 0
a[3] = s
loop = false
elsif ((a[3] + a[5] == -2 * s) || (a[1] + a[7] == -2 * s) || (a[0] + a[8] == -2 * s) || (a[2] + a[6] == -2 * s)) && a[4] == 0
a[4] = s
loop = false
elsif ((a[2] + a[8] == -2 * s) || (a[3] + a[4] == -2 * s)) && a[5] == 0
a[5] = s
loop = false
elsif ((a[0] + a[3] == -2 * s) || (a[7] + a[8] == -2 * s) || (a[2] + a[4] == -2 * s)) && a[6] == 0
a[6] = s
loop = false
elsif ((a[1] + a[4] == -2 * s) || (a[6] + a[8] == -2 * s)) && a[7] == 0
a[7] = s
loop = false
elsif ((a[2] + a[5] == -2 * s) || (a[0] + a[4] == -2 * s) || (a[6] + a[7] == -2 * s)) && a[8] == 0
a[8] = s
loop = false
elsif a[m] == 0 #マスは空いてるか
a[m] = s
loop = false
end
end
end
#上級敵AI
def zyokyu(a)
if local_data[:zyun] == 0 #敵後攻
s = -1
else
s = 1
end
loop = true
while loop
m = rand(9)
if ((a[1] + a[2] == 2 * s) || (a[4] + a[8] == 2 * s) || (a[3] + a[6] == 2 * s)) && a[0] == 0 #勝てるか
a[0] = s
loop = false
elsif ((a[0] + a[2] == 2 * s) || (a[4] + a[7] == 2 * s)) && a[1] == 0 #勝てるか
a[1] = s
loop = false
elsif ((a[1] + a[0] == 2 * s) || (a[4] + a[6] == 2 * s) || (a[5] + a[8] == 2 * s)) && a[2] == 0 #勝てるか
a[2] = s
loop = false
elsif ((a[0] + a[6] == 2 * s) || (a[4] + a[5] == 2 * s)) && a[3] == 0 #勝てるか
a[3] = s
loop = false
elsif ((a[3] + a[5] == 2 * s) || (a[1] + a[7] == 2 * s) || (a[0] + a[8] == 2 * s) || (a[2] + a[6] == 2 * s)) && a[4] == 0 #勝てるか
a[4] = s
loop = false
elsif ((a[2] + a[8] == 2 * s) || (a[3] + a[4] == 2 * s)) && a[5] == 0 #勝てるか
a[5] = s
loop = false
elsif ((a[0] + a[3] == 2 * s) || (a[7] + a[8] == 2 * s) || (a[2] + a[4] == 2 * s)) && a[6] == 0 #勝てるか
a[6] = s
loop = false
elsif ((a[1] + a[4] == 2 * s) || (a[6] + a[8] == 2 * s)) && a[7] == 0 #勝てるか
a[7] = s
loop = false
elsif ((a[2] + a[5] == 2 * s) || (a[0] + a[4] == 2 * s) || (a[6] + a[7] == 2 * s)) && a[8] == 0 #勝てるか
a[8] = s
loop = false
elsif ((a[1] + a[2] == -2 * s) || (a[4] + a[8] == -2 * s) || (a[3] + a[6] == -2 * s)) && a[0] == 0 #負けるか
a[0] = s
loop = false
elsif ((a[0] + a[2] == -2 * s) || (a[4] + a[7] == -2 * s)) && a[1] == 0
a[1] = s
loop = false
elsif ((a[1] + a[0] == -2 * s) || (a[4] + a[6] == -2 * s) || (a[5] + a[8] == -2 * s)) && a[2] == 0
a[2] = s
loop = false
elsif ((a[0] + a[6] == -2 * s) || (a[4] + a[5] == -2 * s)) && a[3] == 0
a[3] = s
loop = false
elsif ((a[3] + a[5] == -2 * s) || (a[1] + a[7] == -2 * s) || (a[0] + a[8] == -2 * s) || (a[2] + a[6] == -2 * s)) && a[4] == 0
a[4] = s
loop = false
elsif ((a[2] + a[8] == -2 * s) || (a[3] + a[4] == -2 * s)) && a[5] == 0
a[5] = s
loop = false
elsif ((a[0] + a[3] == -2 * s) || (a[7] + a[8] == -2 * s) || (a[2] + a[4] == -2 * s)) && a[6] == 0
a[6] = s
loop = false
elsif ((a[1] + a[4] == -2 * s) || (a[6] + a[8] == -2 * s)) && a[7] == 0
a[7] = s
loop = false
elsif ((a[2] + a[5] == -2 * s) || (a[0] + a[4] == -2 * s) || (a[6] + a[7] == -2 * s)) && a[8] == 0
a[8] = s
loop = false
elsif a[0]==0 && a[1]==0 && a[2]==0 && a[3]==0 && a[4]==0 && a[5]==0 && a[6]==0 && a[7]==0 && a[8]==0
local_data[:pt] = rand(18)
if local_data[:pt] == 0
a[0] = s
loop = false
elsif local_data[:pt] == 1
a[2] = s
loop = false
elsif local_data[:pt] == 2
a[6] = s
loop = false
elsif local_data[:pt] == 3
a[8] = s
loop = false
elsif local_data[:pt] >= 4 && local_data[:pt] <= 7
a[4] = s
loop = false
elsif local_data[:pt] == 8
a[2] = s
loop = false
elsif local_data[:pt] == 9
a[0] = s
loop = false
elsif local_data[:pt] == 10 || local_data[:pt] == 17
a[2] = s
loop = false
elsif local_data[:pt] == 11 || local_data[:pt] == 12
a[0] = s
loop = false
elsif local_data[:pt] == 13 || local_data[:pt] == 14
a[6] = s
loop = false
elsif local_data[:pt] == 15 || local_data[:pt] == 16
a[8] = s
loop = false
end
elsif ((a[0] + a[8] == -2 * s || a[2] + a[6] == -2 * s) && a[4] == s) && local_data[:zyun] == 0
if a[1] == 0
a[1] = s
elsif a[3] == 0
a[3] = s
elsif a[5] == 0
a[5] = s
elsif a[7] == 0
a[7] = s
else
loop2 = true
while loop2
m2 = rand(9)
if a[m2] == 0 #マスは空いてるか
a[m2] = s
loop2 = false
end
end
end
loop = false
elsif ((a[2] + a[3] == -2 * s) || (a[1] + a[6] == -2 * s)) && a[0] == 0
a[0] = s
loop = false
elsif ((a[3] + a[8] == -2 * s) || (a[0] + a[7] == -2 * s)) && a[6] == 0
a[6] = s
loop = false
elsif ((a[2] + a[7] == -2 * s) || (a[5] + a[6] == -2 * s)) && a[8] == 0
a[8] = s
loop = false
elsif ((a[1] + a[8] == -2 * s) || (a[0] + a[5] == -2 * s)) && a[2] == 0
a[2] = s
loop = false
elsif (local_data[:pt] == 10 || local_data[:pt] == 15) && a[3] == 0
a[3] = s
loop = false
elsif (local_data[:pt] == 11 || local_data[:pt] == 17) && a[7] == 0
a[7] = s
loop = false
elsif (local_data[:pt] == 12 || local_data[:pt] == 13) && a[5] == 0
a[5] = s
loop = false
elsif (local_data[:pt] == 14 || local_data[:pt] == 16) && a[1] == 0
a[1] = s
loop = false
elsif ((a[2] + a[3] == 2 * s) || (a[1] + a[6] == 2 * s)) && a[0] == 0
a[0] = s
loop = false
elsif ((a[0] + a[7] == 2 * s) || (a[3] + a[8] == 2 * s)) && a[6] == 0
a[6] = s
loop = false
elsif ((a[2] + a[7] == 2 * s) || (a[5] + a[6] == 2 * s)) && a[8] == 0
a[8] = s
loop = false
elsif ((a[0] + a[5] == 2 * s) || (a[1] + a[8] == 2 * s)) && a[2] == 0
a[2] = s
loop = false
elsif (a[0] == s && a[4] == -1*s) && a[8] == 0
a[8] = s
loop = false
elsif (a[2] == s && a[4] == -1*s) && a[6] == 0
a[6] = s
loop = false
elsif (a[6] == s && a[4] == -1*s) && a[2] == 0
a[2] = s
loop = false
elsif (a[8] == s && a[4] == -1*s) && a[0] == 0
a[0] = s
loop = false
elsif a[4]==-1*s
if a[0] == 0
a[0] = s
elsif a[2] == 0
a[2] = s
elsif a[6] == 0
a[6] = s
elsif a[8] == 0
a[8] = s
else
loop2 = true
while loop2
m2 = rand(9)
if a[m2] == 0 #マスは空いてるか
a[m2] = s
loop2 = false
end
end
end
loop = false
elsif (local_data[:pt] == 0 && (a[2] == -2*s || a[6] == -2*s)) && a[8] == 0 #パターン0~3
a[8] == s
loop = false
elsif (local_data[:pt] == 1 && (a[0] == -2*s || a[8] == -2*s)) && a[6] == 0
a[6] == s
loop = false
elsif (local_data[:pt] == 2 && (a[0] == -2*s || a[8] == -2*s)) && a[2] == 0
a[2] == s
loop = false
elsif (local_data[:pt] == 3 && (a[2] == -2*s || a[6] == -2*s)) && a[0] == 0
a[0] == s
loop = false
elsif a[4]==s
if a[0] == 0
a[0] = s
elsif a[2] == 0
a[2] = s
elsif a[6] == 0
a[6] = s
elsif a[8] == 0
a[8] = s
else
loop2 = true
while loop2
m2 = rand(9)
if a[m2] == 0 #マスは空いてるか
a[m2] = s
loop2 = false
end
end
end
loop = false
elsif a[4] == 0
a[4] = s
loop = false
elsif a[m] == 0 #マスは空いてるか
a[m] = s
loop = false
end
end
end
# 初期化処理
game.on_init do
# speak用window画像の指定
set_window_image :windowG
set_gui_image :gui_item
#ロード出来たか
if game.loaded_data_result[:game_data][:success]
local_data[:data] = game.loaded_data[:game_data]
else
local_data[:data] = [0,0,0,0,0,0,0,0]
local_data[:data][3] = [0,0,0] #初級 勝ち 負け 引き分け
local_data[:data][4] = [0,0,0] #中級
local_data[:data][5] = [0,0,0] #上級
local_data[:data][6] = [0,0,0] #二人対戦1P
local_data[:data][7] = [0,0,0] #二人対戦2P
end
# シーン「start_scene」に移動
scene_change :start_scene
end
# シーン「start_scene」の定義
scene :start_scene do |scene|
scene.loading do
end
scene.on_init do
#背景
backs = scene.add :image, :texture => :backs, :align => :fullscreen
speak "このゲームは三目並べです。"
speak "モードを選択して下さい。"
local_data[:mode] = -1
text0 = scene.text :position => [150, 100]
text0.set_text_area_size 190, 50
text0.set_font_point_size 40
text0.set_text "二人対戦"
text0.event :on_click do |event| #二人対戦を選んだ時
local_data[:mode] = 0
end
text1 = scene.text :position => [190, 200]
text1.set_text_area_size 90, 50
text1.set_font_point_size 40
text1.set_text "初級"
text1.event :on_click do |event|
local_data[:mode] = 1
end
if local_data[:data][0] == 1 #初級で勝ったか
text2 = scene.text :position => [190, 300]
text2.set_text_area_size 90, 50
text2.set_font_point_size 40
text2.set_text "中級"
text2.event :on_click do |event|
local_data[:mode] = 2
end
else
text2 = scene.add :collision, :center_position => [-10, -10]
end
if local_data[:data][1] == 1 #中級で勝ったか
text3 = scene.text :position => [190, 400]
text3.set_text_area_size 90, 50
text3.set_font_point_size 40
text3.set_text "上級"
text3.event :on_click do |event|
local_data[:mode] = 3
end
else
text3 = scene.add :collision, :center_position => [-10, -10]
end
text4 = scene.text :position => [190, 600]
text4.set_text_area_size 90, 50
text4.set_font_point_size 40
text4.set_text "終了"
text4.event :on_click do |event|
local_data[:mode] = 5
end
text5 = scene.text :position => [190, 500]
text5.set_text_area_size 90, 50
text5.set_font_point_size 40
text5.set_text "戦歴"
text5.event :on_click do |event|
local_data[:mode] = 4
end
while local_data[:mode] == -1
wait_time 10
end
text0.delete
text1.delete
text2.delete
text3.delete
text4.delete
text5.delete
if local_data[:mode] == 0 #二人対戦
#二人対戦用シーンへ
scene_change :double
elsif local_data[:mode] == 4 #戦歴
scene_change :senreki
elsif local_data[:mode] == 5 #終了
#データセーブ
data = local_data[:data]
#speak("初級:#{data[3]} 中級:#{data[4]} 上級:#{data[5]} 二人対戦1P:#{data[6]} 2P:#{data[7]}")
seve(data)
# スタートメニューへ
game.change_project "start_menu"
elsif local_data[:mode] == 6 #ヘルプ(予定)
else
speak("先攻か後攻かを決めてください。")
local_data[:zyun] = -1
text = scene.text :position => [190, 250]
text.set_text_area_size 90, 50
text.set_font_point_size 40
text.set_text "先攻"
text.event :on_click do |event|
local_data[:zyun] = 0
end
text = scene.text :position => [190, 550]
text.set_text_area_size 90, 50
text.set_font_point_size 40
text.set_text "後攻"
text.event :on_click do |event|
local_data[:zyun] = 1
end
while local_data[:zyun] == -1
wait_time 10
end
# シーン「main」に移動
scene_change :main
end
end
end
# シーン「double」(二人対戦用)の定義
scene :double do |scene|
scene.loading do
end
scene.on_init do
#背景
back = scene.add :image, :texture => :backs2, :align => :fullscreen
speak("あなたはどの機器でプレイしますか?")
kiki = -1
textsa = scene.add :image, :name => :textsa, :texture => :tx1, :center_position => [450 / 2, 800 / 3]
scene.event :textsa, :on_click do
kiki = 0
end
textsb = scene.add :image, :name => :textsb, :texture => :tx2, :center_position => [450 / 2, 800 / 3 * 2]
scene.event :textsb, :on_click do
kiki = 1
end
while kiki == -1
wait_time 10
end
textsa.delete
textsb.delete
onemore = true
if kiki == 1
back2 = scene.add :image, :texture => :haikei1, :align => :fullscreen, :z_order => 2
speak("1P・2Pを決め、このような配置になるように移動して下さい。")
wait_time 1000
speak("よろしいですか?")
back2.delete
else
speak("1P・2Pを決めて下さい。")
end
speak("それでは、どちらが先攻か決めてください。")
wait_loop = true
text0 = scene.text :position => [150, 800 / 4]
text0.set_text_area_size 190, 50
text0.set_font_point_size 40
text0.set_text "1P: 先攻"
text0.event :on_click do |event|
local_data[:snko] = 0
wait_loop = false
end
text1 = scene.text :position => [150, 800 / 4 * 2]
text1.set_text_area_size 190, 50
text1.set_font_point_size 40
text1.set_text "2P: 先攻"
text1.event :on_click do |event|
local_data[:snko] = 1
wait_loop = false
end
text2 = scene.text :position => [150, 800 / 4 * 3]
text2.set_text_area_size 190, 50
text2.set_font_point_size 40
text2.set_text "おまかせ"
text2.event :on_click do |event|
local_data[:snko] = rand(2)
wait_loop = false
end
while wait_loop
wait_time 10
end
text0.delete
text1.delete
text2.delete
if local_data[:snko] == 0
oneP = "先攻"
twoP = "後攻"
else
oneP = "後攻"
twoP = "先攻"
end
while onemore
speak("1Pが#{oneP}、\n2Pが#{twoP}です。")
speak("先攻が○、後攻が×をクリック・タップで置きます。")
speak("それでは、ゲーム開始です!")
#配列 0は何もない 1は○ -1は×
masu = [0, 0, 0 ,0 ,0 ,0 ,0 ,0 ,0]
#背景を消す
back.delete
#メイン背景表示
scene.add :image, :texture => :sW, :align => :fullscreen
loop = true
turn = 2 #偶数は先攻
while loop
#ターン表示
if turn % 2 == 0
case local_data[:snko]
when 0
tan = scene.add :image, :texture => :tO, :position => [100, 650]
else
case kiki
when 0 #PCでプレイ
tan = scene.add :image, :texture => :tT, :position => [100, 650]
else
tan = scene.add :image, :texture => :tT, :position => [100, 50], :rotation => 3.14 #180°回転
end
end
else
case local_data[:snko]
when 0
case kiki
when 0 #PCでプレイ
tan = scene.add :image, :texture => :tT, :position => [100, 650]
else
tan = scene.add :image, :texture => :tT, :position => [100, 50], :rotation => 3.14 #180°回転
end
else
tan = scene.add :image, :texture => :tO, :position => [100, 650]
end
end
#当たり判定
masu1 = scene.add :collision, :name => :masu1, :center_position => [10 + 70, 185 + 70], :scale => [140, 140]
masu2 = scene.add :collision, :name => :masu2, :center_position => [155 + 70, 185 + 70], :scale => [140, 140]
masu3 = scene.add :collision, :name => :masu3, :center_position => [300 + 70, 185 + 70], :scale => [140, 140]
masu4 = scene.add :collision, :name => :masu4, :center_position => [10 + 70, 330 + 70], :scale => [140, 140]
masu5 = scene.add :collision, :name => :masu5, :center_position => [155 + 70, 330 + 70], :scale => [140, 140]
masu6 = scene.add :collision, :name => :masu6, :center_position => [300 + 70, 330 + 70], :scale => [140, 140]
masu7 = scene.add :collision, :name => :masu7, :center_position => [10 + 70, 475 + 70], :scale => [140, 140]
masu8 = scene.add :collision, :name => :masu8, :center_position => [155 + 70, 475 + 70], :scale => [140, 140]
masu9 = scene.add :collision, :name => :masu9, :center_position => [300 + 70, 475 + 70], :scale => [140, 140]
go = true
scene.event :masu1, :on_click do
if masu[0] == 0
if turn % 2 == 0
masu[0] = 1
scene.add :image, :name => :kata1, :texture =>:maru, :center_position => [10 + 70, 185 + 70]
else
masu[0] = -1
scene.add :image, :name => :kata1, :texture =>:batu, :center_position => [10 + 70, 185 + 70]
end
go = false
end
end
scene.event :masu2, :on_click do
if masu[1] == 0
if turn % 2 == 0
masu[1] = 1
scene.add :image, :name => :kata2, :texture =>:maru, :center_position => [155 + 70, 185 + 70]
else
masu[1] = -1
scene.add :image, :name => :kata2, :texture =>:batu, :center_position => [155 + 70, 185 + 70]
end
go = false
end
end
scene.event :masu3, :on_click do
if masu[2] == 0
if turn % 2 == 0
masu[2] = 1
scene.add :image, :name => :kata3, :texture =>:maru, :center_position => [300 + 70, 185 + 70]
else
masu[2] = -1
scene.add :image, :name => :kata3, :texture =>:batu, :center_position => [300 + 70, 185 + 70]
end
go = false
end
end
scene.event :masu4, :on_click do
if masu[3] == 0
if turn % 2 == 0
masu[3] = 1
scene.add :image, :name => :kata4, :texture =>:maru, :center_position => [10 + 70, 330 + 70]
else
masu[3] = -1
scene.add :image, :name => :kata4, :texture =>:batu, :center_position => [10 + 70, 330 + 70]
end
go = false
end
end
scene.event :masu5, :on_click do
if masu[4] == 0
if turn % 2 == 0
masu[4] = 1
scene.add :image, :name => :kata5, :texture =>:maru, :center_position => [155 + 70, 330 + 70]
else
masu[4] = -1
scene.add :image, :name => :kata5, :texture =>:batu, :center_position => [155 + 70, 330 + 70]
end
go = false
end
end
scene.event :masu6, :on_click do
if masu[5] == 0
if turn % 2 == 0
masu[5] = 1
scene.add :image, :name => :kata6, :texture =>:maru, :center_position => [300 + 70, 330 + 70]
else
masu[5] = -1
scene.add :image, :name => :kata6, :texture =>:batu, :center_position => [300 + 70, 330 + 70]
end
go = false
end
end
scene.event :masu7, :on_click do
if masu[6] == 0
if turn % 2 == 0
masu[6] = 1
scene.add :image, :name => :kata7, :texture =>:maru, :center_position => [10 + 70, 475 + 70]
else
masu[6] = -1
scene.add :image, :name => :kata7, :texture =>:batu, :center_position => [10 + 70, 475 + 70]
end
go = false
end
end
scene.event :masu8, :on_click do
if masu[7] == 0
if turn % 2 == 0
masu[7] = 1
scene.add :image, :name => :kata8, :texture =>:maru, :center_position => [155 + 70, 475 + 70]
else
masu[7] = -1
scene.add :image, :name => :kata8, :texture =>:batu, :center_position => [155 + 70, 475 + 70]
end
go = false
end
end
scene.event :masu9, :on_click do
if masu[8] == 0
if turn % 2 == 0
masu[8] = 1
scene.add :image, :name => :kata9, :texture =>:maru, :center_position => [300 + 70, 475 + 70]
else
masu[8] = -1
scene.add :image, :name => :kata9, :texture =>:batu, :center_position => [300 + 70, 475 + 70]
end
go = false
end
end
while go
wait_time 10
end
masu1.delete
masu2.delete
masu3.delete
masu4.delete
masu5.delete
masu6.delete
masu7.delete
masu8.delete
masu9.delete
#勝敗
if (masu[0] + masu[1] + masu[2] == 3) || (masu[3] + masu[4] + masu[5] == 3) || (masu[6] + masu[7] + masu[8] == 3) || (masu[0] + masu[3] + masu[6] == 3) || (masu[1] + masu[4] + masu[7] == 3) || (masu[2] + masu[5] + masu[8] == 3) || (masu[0] + masu[4] + masu[8] == 3) || (masu[2] + masu[4] + masu[6] == 3) #先攻勝ったか
if local_data[:snko] == 0 #先攻は誰か
#1P勝利
case kiki
when 0 #PCでプレイ
syohai = scene.add :image, :texture => :kati, :position => [0, 500]
when 1
syohai = scene.add :image, :texture => :make, :position => [0, 200], :rotation => 3.14 #180°回転
syohai2 = scene.add :image, :texture => :kati, :position => [0, 500]
end
local_data[:data][6][0] = local_data[:data][6][0] + 1 #1P勝ち
local_data[:data][7][1] = local_data[:data][7][1] + 1 #2P負け
else
#2P勝利
case kiki
when 0 #PCでプレイ
syohai = scene.add :image, :texture => :kati, :position => [0, 500]
when 1
syohai = scene.add :image, :texture => :kati, :position => [0, 200], :rotation => 3.14 #180°回転
syohai2 = scene.add :image, :texture => :make, :position => [0, 500]
end
local_data[:data][6][1] = local_data[:data][6][1] + 1 #1P負け
local_data[:data][7][0] = local_data[:data][7][0] + 1 #2P勝ち
end
clear=true
elsif (masu[0] + masu[1] + masu[2] == -3) || (masu[3] + masu[4] + masu[5] == -3) || (masu[6] + masu[7] + masu[8] == -3) || (masu[0] + masu[3] + masu[6] == -3) || (masu[1] + masu[4] + masu[7] == -3) || (masu[2] + masu[5] + masu[8] == -3) || (masu[0] + masu[4] + masu[8] == -3) || (masu[2] + masu[4] + masu[6] == -3) #後攻勝ったか
if local_data[:snko] == 1 #後攻は誰か
#1P勝利
case kiki
when 0 #PCでプレイ
syohai = scene.add :image, :texture => :kati, :position => [0, 500]
when 1
syohai = scene.add :image, :texture => :make, :position => [0, 200], :rotation => 3.14 #180°回転
syohai2 = scene.add :image, :texture => :kati, :position => [0, 500]
end
local_data[:data][6][0] = local_data[:data][6][0] + 1 #1P勝ち
local_data[:data][7][1] = local_data[:data][7][1] + 1 #2P負け
else
#2P勝利
case kiki
when 0 #PCでプレイ
syohai = scene.add :image, :texture => :kati, :position => [0, 500]
when 1
syohai = scene.add :image, :texture => :kati, :position => [0, 200], :rotation => 3.14 #180°回転
syohai2 = scene.add :image, :texture => :make, :position => [0, 500]
end
local_data[:data][6][1] = local_data[:data][6][1] + 1 #1P負け
local_data[:data][7][0] = local_data[:data][7][0] + 1 #2P勝ち
end
clear=true
elsif turn == 10
#引き分け
case kiki
when 0 #PCでプレイ
syohai = scene.add :image, :texture => :hiki, :position => [0, 500]
when 1
syohai = scene.add :image, :texture => :hiki, :position => [0, 200], :rotation => 3.14 #180°回転
syohai2 = scene.add :image, :texture => :hiki, :position => [0, 500]
end
local_data[:data][6][2] = local_data[:data][6][2] + 1 #1P引き分け
local_data[:data][7][2] = local_data[:data][7][2] + 1 #2P引き分け
clear=true
else
clear=false
end
if clear
#セーブ
seve(local_data[:data])
loop2 = true
#全画面に当たり判定
alls = scene.add :collision, :name => :alls, :center_position => [450 / 2, 800 / 2], :scale => [450, 800]
scene.event :alls, :on_click do
loop2 = false
end
while loop2
wait_time 10
end
alls.delete
#全て削除
scene.delete_all
#背景
back = scene.add :image, :texture => :backs2, :align => :fullscreen
sentak = true
speak("もう一度プレイしますか?")
texta = scene.text :position => [190, 250]
texta.set_text_area_size 90, 50
texta.set_font_point_size 40
texta.set_text "はい"
texta.event :on_click do |event|
onemore = true
sentak = false
end
textb = scene.text :position => [180, 550]
textb.set_text_area_size 150, 50
textb.set_font_point_size 40
textb.set_text "いいえ"
textb.event :on_click do |event|
onemore = false
sentak = false
end
while sentak
wait_time 10
end
texta.delete
textb.delete
loop = false
if onemore #はい
else #いいえ
scene_change :start_scene
end
end
turn = turn + 1
wait_time 10
tan.delete
end
end
end
end
# シーン「main」の定義 local_data[:mode] local_data[:zyun]
scene :main do |scene|
scene.loading do
end
scene.on_init do
#背景
back = scene.add :image, :texture => :backs2, :align => :fullscreen
if local_data[:zyun] == 0
oneP = "先攻"
twoP = "後攻"
else
oneP = "後攻"
twoP = "先攻"
end
onemore = true
while onemore
speak("あなた(1P)が#{oneP}、\n敵(2P)が#{twoP}です。")
speak("先攻が○、後攻が×をクリック・タップで置きます。")
speak("それでは、ゲーム開始です!")
#配列 0は何もない 1は○ -1は×
masu = [0, 0, 0 ,0 ,0 ,0 ,0 ,0 ,0]
#上級AI用変数
local_data[:pt] = -1
#背景を消す
back.delete
#メイン背景表示
if local_data[:mode] == 1 #初級
scene.add :image, :texture => :sS, :align => :fullscreen
elsif local_data[:mode] == 2 #中級
scene.add :image, :texture => :sT, :align => :fullscreen
elsif local_data[:mode] == 3 #上級
scene.add :image, :texture => :sZ, :align => :fullscreen
end
#ダミー
kata1 = scene.add :collision, :center_position => [-10, -10]
kata2 = scene.add :collision, :center_position => [-10, -10]
kata3 = scene.add :collision, :center_position => [-10, -10]
kata4 = scene.add :collision, :center_position => [-10, -10]
kata5 = scene.add :collision, :center_position => [-10, -10]
kata6 = scene.add :collision, :center_position => [-10, -10]
kata7 = scene.add :collision, :center_position => [-10, -10]
kata8 = scene.add :collision, :center_position => [-10, -10]
kata9 = scene.add :collision, :center_position => [-10, -10]
hanten = scene.add :collision, :center_position => [-10, -10]
loop = true
turn = 2 #偶数は先攻
while loop
#ターン表示
if turn % 2 == 0 #先攻
if local_data[:zyun] == 0 #プレイヤーは先攻か?
tan = scene.add :image, :texture => :tO, :position => [100, 650]
playok = true
else
tan = scene.add :image, :texture => :tT, :position => [100, 650]
playok = false
end
else
if local_data[:zyun] == 1
tan = scene.add :image, :texture => :tO, :position => [100, 650]
playok = true
else
tan = scene.add :image, :texture => :tT, :position => [100, 650]
playok = false
end
end
if playok #プレイヤーのターン
#当たり判定
masu1 = scene.add :collision, :name => :masu1, :center_position => [10 + 70, 185 + 70], :scale => [140, 140]
masu2 = scene.add :collision, :name => :masu2, :center_position => [155 + 70, 185 + 70], :scale => [140, 140]
masu3 = scene.add :collision, :name => :masu3, :center_position => [300 + 70, 185 + 70], :scale => [140, 140]
masu4 = scene.add :collision, :name => :masu4, :center_position => [10 + 70, 330 + 70], :scale => [140, 140]
masu5 = scene.add :collision, :name => :masu5, :center_position => [155 + 70, 330 + 70], :scale => [140, 140]
masu6 = scene.add :collision, :name => :masu6, :center_position => [300 + 70, 330 + 70], :scale => [140, 140]
masu7 = scene.add :collision, :name => :masu7, :center_position => [10 + 70, 475 + 70], :scale => [140, 140]
masu8 = scene.add :collision, :name => :masu8, :center_position => [155 + 70, 475 + 70], :scale => [140, 140]
masu9 = scene.add :collision, :name => :masu9, :center_position => [300 + 70, 475 + 70], :scale => [140, 140]
if local_data[:mode] == 3 #上級
hanten = scene.add :collision, :name => :hanten, :center_position => [450, 800], :scale => [100, 100]
end
go = true
scene.event :masu1, :on_click do
if masu[0] == 0
if turn % 2 == 0
masu[0] = 1
else
masu[0] = -1
end
go = false
end
end
scene.event :masu2, :on_click do
if masu[1] == 0
if turn % 2 == 0
masu[1] = 1
else
masu[1] = -1
end
go = false
end
end
scene.event :masu3, :on_click do
if masu[2] == 0
if turn % 2 == 0
masu[2] = 1
else
masu[2] = -1
end
go = false
end
end
scene.event :masu4, :on_click do
if masu[3] == 0
if turn % 2 == 0
masu[3] = 1
else
masu[3] = -1
end
go = false
end
end
scene.event :masu5, :on_click do
if masu[4] == 0
if turn % 2 == 0
masu[4] = 1
else
masu[4] = -1
end
go = false
end
end
scene.event :masu6, :on_click do
if masu[5] == 0
if turn % 2 == 0
masu[5] = 1
else
masu[5] = -1
end
go = false
end
end
scene.event :masu7, :on_click do
if masu[6] == 0
if turn % 2 == 0
masu[6] = 1
else
masu[6] = -1
end
go = false
end
end
scene.event :masu8, :on_click do
if masu[7] == 0
if turn % 2 == 0
masu[7] = 1
else
masu[7] = -1
end
go = false
end
end
scene.event :masu9, :on_click do
if masu[8] == 0
if turn % 2 == 0
masu[8] = 1
else
masu[8] = -1
end
go = false
end
end
scene.event :hanten, :on_click do
i = 0
while i < 9
masu[i] = masu[i] * -1
i = i + 1
end
go = false
#hanN = hanN + 1
end
while go
wait_time 10
end
masu1.delete
masu2.delete
masu3.delete
masu4.delete
masu5.delete
masu6.delete
masu7.delete
masu8.delete
masu9.delete
else #敵のターン
wait_time 250
if local_data[:mode] == 3 #上級
zyokyu(masu)
elsif local_data[:mode] == 2 #中級
tyukyu(masu)
elsif local_data[:mode] == 1 #初級
syokyu(masu)
end
wait_time 250
end
kata1.delete
kata2.delete
kata3.delete
kata4.delete
kata5.delete
kata6.delete
kata7.delete
kata8.delete
kata9.delete
#check
if local_data[:mode] == 3 #上級
ma = :maruw
ba = :batuw
else
ma = :maru
ba = :batu
end
if masu[0] == 1
kata1 = scene.add :image, :name => :kata1, :texture =>ma, :center_position => [10 + 70, 185 + 70]
elsif masu[0] == -1
kata1 = scene.add :image, :name => :kata1, :texture =>ba, :center_position => [10 + 70, 185 + 70]
else
kata1 = scene.add :collision, :center_position => [-10, -10]
end
if masu[1] == 1
kata2 = scene.add :image, :name => :kata2, :texture =>ma, :center_position => [155 + 70, 185 + 70]
elsif masu[1] == -1
kata2 = scene.add :image, :name => :kata2, :texture =>ba, :center_position => [155 + 70, 185 + 70]
else
kata2 = scene.add :collision, :center_position => [-10, -10]
end
if masu[2] == 1
kata3 = scene.add :image, :name => :kata3, :texture =>ma, :center_position => [300 + 70, 185 + 70]
elsif masu[2] == -1
kata3 = scene.add :image, :name => :kata3, :texture =>ba, :center_position => [300 + 70, 185 + 70]
else
kata3 = scene.add :collision, :center_position => [-10, -10]
end
if masu[3] == 1
kata4 = scene.add :image, :name => :kata4, :texture =>ma, :center_position => [10 + 70, 330 + 70]
elsif masu[3] == -1
kata4 = scene.add :image, :name => :kata4, :texture =>ba, :center_position => [10 + 70, 330 + 70]
else
kata4 = scene.add :collision, :center_position => [-10, -10]
end
if masu[4] == 1
kata5 = scene.add :image, :name => :kata5, :texture =>ma, :center_position => [155 + 70, 330 + 70]
elsif masu[4] == -1
kata5 = scene.add :image, :name => :kata5, :texture =>ba, :center_position => [155 + 70, 330 + 70]
else
kata5 = scene.add :collision, :center_position => [-10, -10]
end
if masu[5] == 1
kata6 = scene.add :image, :name => :kata6, :texture =>ma, :center_position => [300 + 70, 330 + 70]
elsif masu[5] == -1
kata6 = scene.add :image, :name => :kata6, :texture =>ba, :center_position => [300 + 70, 330 + 70]
else
kata6 = scene.add :collision, :center_position => [-10, -10]
end
if masu[6] == 1
kata7 = scene.add :image, :name => :kata7, :texture =>ma, :center_position => [10 + 70, 475 + 70]
elsif masu[6] == -1
kata7 = scene.add :image, :name => :kata7, :texture =>ba, :center_position => [10 + 70, 475 + 70]
else
kata7 = scene.add :collision, :center_position => [-10, -10]
end
if masu[7] == 1
kata8 = scene.add :image, :name => :kata8, :texture =>ma, :center_position => [155 + 70, 475 + 70]
elsif masu[7] == -1
kata8 = scene.add :image, :name => :kata8, :texture =>ba, :center_position => [155 + 70, 475 + 70]
else
kata8 = scene.add :collision, :center_position => [-10, -10]
end
if masu[8] == 1
kata9 = scene.add :image, :name => :kata9, :texture =>ma, :center_position => [300 + 70, 475 + 70]
elsif masu[8] == -1
kata9 = scene.add :image, :name => :kata9, :texture =>ba, :center_position => [300 + 70, 475 + 70]
else
kata9 = scene.add :collision, :center_position => [-10, -10]
end
#勝敗
if (masu[0] + masu[1] + masu[2] == 3) || (masu[3] + masu[4] + masu[5] == 3) || (masu[6] + masu[7] + masu[8] == 3) || (masu[0] + masu[3] + masu[6] == 3) || (masu[1] + masu[4] + masu[7] == 3) || (masu[2] + masu[5] + masu[8] == 3) || (masu[0] + masu[4] + masu[8] == 3) || (masu[2] + masu[4] + masu[6] == 3) #先攻勝ったか
if local_data[:zyun] == 0 #先攻は誰か
#1P勝利
syohai = scene.add :image, :texture => :kati, :position => [0, 500]
#勝った記録を残す
if local_data[:mode] == 1
local_data[:data][0] = 1
local_data[:data][3][0] = local_data[:data][3][0] + 1 # 初級 勝ち数
elsif local_data[:mode] == 2
local_data[:data][1] = 1
local_data[:data][4][0] = local_data[:data][4][0] + 1 # 中級 勝ち数
elsif local_data[:mode] == 3
local_data[:data][2] = 1
local_data[:data][5][0] = local_data[:data][5][0] + 1 # 上級 勝ち数
end
else
#2P勝利
syohai2 = scene.add :image, :texture => :make, :position => [0, 500]
#勝った記録を残す
if local_data[:mode] == 1
local_data[:data][3][1] = local_data[:data][3][1] + 1 # 初級 負け数
elsif local_data[:mode] == 2
local_data[:data][4][1] = local_data[:data][4][1] + 1 # 中級 負け数
elsif local_data[:mode] == 3
local_data[:data][5][1] = local_data[:data][5][1] + 1 # 上級 負け数
end
end
clear=true
elsif (masu[0] + masu[1] + masu[2] == -3) || (masu[3] + masu[4] + masu[5] == -3) || (masu[6] + masu[7] + masu[8] == -3) || (masu[0] + masu[3] + masu[6] == -3) || (masu[1] + masu[4] + masu[7] == -3) || (masu[2] + masu[5] + masu[8] == -3) || (masu[0] + masu[4] + masu[8] == -3) || (masu[2] + masu[4] + masu[6] == -3) #後攻勝ったか
if local_data[:zyun] == 1 #後攻は誰か
#1P勝利
syohai = scene.add :image, :texture => :kati, :position => [0, 500]
#勝った記録を残す
if local_data[:mode] == 1
local_data[:data][0] = 1
local_data[:data][3][0] = local_data[:data][3][0] + 1 # 初級 勝ち数
elsif local_data[:mode] == 2
local_data[:data][1] = 1
local_data[:data][4][0] = local_data[:data][4][0] + 1 # 中級 勝ち数
elsif local_data[:mode] == 3
local_data[:data][2] = 1
local_data[:data][5][0] = local_data[:data][5][0] + 1 # 上級 勝ち数
end
else
#2P勝利
syohai2 = scene.add :image, :texture => :make, :position => [0, 500]
#負けた記録を残す
if local_data[:mode] == 1
local_data[:data][3][1] = local_data[:data][3][1] + 1 # 初級 負け数
elsif local_data[:mode] == 2
local_data[:data][4][1] = local_data[:data][4][1] + 1 # 中級 負け数
elsif local_data[:mode] == 3
local_data[:data][5][1] = local_data[:data][5][1] + 1 # 上級 負け数
end
end
clear=true
elsif turn == 10
#引き分け
syohai = scene.add :image, :texture => :hiki, :position => [0, 500]
#引き分けした記録を残す
if local_data[:mode] == 1
local_data[:data][3][2] = local_data[:data][3][2] + 1 # 初級 引き分け数
elsif local_data[:mode] == 2
local_data[:data][4][2] = local_data[:data][4][2] + 1 # 中級 引き分け数
elsif local_data[:mode] == 3
local_data[:data][5][2] = local_data[:data][5][2] + 1 # 上級 引き分け数
end
clear=true
else
clear=false
end
if clear
#セーブ
seve(local_data[:data])
loop2 = true
#全画面に当たり判定
alls = scene.add :collision, :name => :alls, :center_position => [450 / 2, 800 / 2], :scale => [450, 800]
scene.event :alls, :on_click do
loop2 = false
end
while loop2
wait_time 10
end
alls.delete
#全て削除
scene.delete_all
#背景
back = scene.add :image, :texture => :backs2, :align => :fullscreen
sentak = true
speak("もう一度プレイしますか?")
texta = scene.text :position => [190, 250]
texta.set_text_area_size 90, 50
texta.set_font_point_size 40
texta.set_text "はい"
texta.event :on_click do |event|
sentak = false
onemore = true
end
textb = scene.text :position => [180, 550]
textb.set_text_area_size 150, 50
textb.set_font_point_size 40
textb.set_text "いいえ"
textb.event :on_click do |event|
onemore = false
sentak = false
end
while sentak
wait_time 10
end
texta.delete
textb.delete
loop = false
if onemore #はい
else #いいえ
scene_change :start_scene
end
end
turn = turn + 1
wait_time 10
tan.delete
end
end
end
end
# シーン「senreki」の定義
scene :senreki do |scene|
scene.loading do
end
scene.on_init do
back = scene.add :image, :texture => :haikei2, :align => :fullscreen
text = scene.text :position => [130, 62] #勝
text.set_text_area_size 309, 27
text.set_font_point_size 20
text.set_color 255, 0, 0, 255
text.set_text "#{local_data[:data][6][0]} (1P)"
text = scene.text :position => [130, 111] #負
text.set_text_area_size 309, 27
text.set_font_point_size 20
text.set_color 2, 0, 169, 255
text.set_text "#{local_data[:data][6][1]} (1P)"
text = scene.text :position => [130, 162] #引分
text.set_text_area_size 309, 27
text.set_font_point_size 20
text.set_color 37, 209, 0, 255
text.set_text "#{local_data[:data][6][2]} (1P)"
text = scene.text :position => [130, 263] #勝
text.set_text_area_size 309, 27
text.set_font_point_size 20
text.set_color 255, 0, 0, 255
text.set_text "#{local_data[:data][3][0]}"
text = scene.text :position => [130, 312] #負
text.set_text_area_size 309, 27
text.set_font_point_size 20
text.set_color 2, 0, 169, 255
text.set_text "#{local_data[:data][3][1]}"
text = scene.text :position => [130, 362] #引分
text.set_text_area_size 309, 27
text.set_font_point_size 20
text.set_color 37, 209, 0, 255
text.set_text "#{local_data[:data][3][2]}"
text = scene.text :position => [130, 462] #勝
text.set_text_area_size 309, 27
text.set_font_point_size 20
text.set_color 255, 0, 0, 255
text.set_text "#{local_data[:data][4][0]}"
text = scene.text :position => [130, 511] #負
text.set_text_area_size 309, 27
text.set_font_point_size 20
text.set_color 2, 0, 169, 255
text.set_text "#{local_data[:data][4][1]}"
text = scene.text :position => [130, 562] #引分
text.set_text_area_size 309, 27
text.set_font_point_size 20
text.set_color 37, 209, 0, 255
text.set_text "#{local_data[:data][4][2]}"
text = scene.text :position => [130, 663] #勝
text.set_text_area_size 309, 27
text.set_font_point_size 20
text.set_color 255, 0, 0, 255
text.set_text "#{local_data[:data][5][0]}"
text = scene.text :position => [130, 711] #負
text.set_text_area_size 309, 27
text.set_font_point_size 20
text.set_color 2, 0, 169, 255
text.set_text "#{local_data[:data][5][1]}"
text = scene.text :position => [130, 762] #引分
text.set_text_area_size 309, 27
text.set_font_point_size 20
text.set_color 37, 209, 0, 255
text.set_text "#{local_data[:data][5][2]}"
back.event :on_click do |event|
scene.delete_all #全て削除
scene_change :start_scene
end
end
end