まず、初期化の部分を考えます。
1 2 3 4 4 5 |
#define SX (ginfo_winx / numx) // 1マスの横幅 #define SY (ginfo_winy / numy) // 1マスの高さ numx = 3 // 横マスの個数 numy = 3 // 縦マスの個数 randomize |
1 2 3 |
*game_start space = 0 // 現在の空きマス位置 clear = 0 // ゲームクリアフラグ |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
*draw_tips // 完成図 buffer 1, ginfo_winx, ginfo_winy color 150, 255, 100 : boxf : color , , 255 font msmincho, SY, 1 repeat numx * numy pos cnt \ numx * SX + (SX - SY) / 2, cnt / numx * SY : mes strf("%02d", cnt + 1) loop // 補助線 buffer 2, ginfo_winx, ginfo_winy gcopy 1, , , ginfo_winx, ginfo_winy color 255 repeat numx + 1 boxf cnt * SX - 2, -1, cnt * SX + 1, ginfo_winy // マス左右の枠線 loop repeat numy + 1 boxf -1, cnt * SY - 2, ginfo_winx, cnt * SY + 1 // マス上下の枠線 loop gsel 0 return |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
*shuffle dim tip, numx * numy repeat numx * numy : tip.cnt = cnt : loop repeat length(tip) * length(tip) i = space, rnd(4) // [ReplaceTipNo], [0:left, 1:top, 2:right, 3:down] if i.1 = 0 : if space \ numx = 0 : continue : else : space-- if i.1 = 1 : if space / numx = 0 : continue : else : space -= numx if i.1 = 2 : if space \ numx = numx - 1 : continue : else : space++ if i.1 = 3 : if space / numx = numy - 1 : continue : else : space += numx tip.space = tip.space ^ tip.i tip.i = tip.space ^ tip.i tip.space = tip.space ^ tip.i loop return |
1 2 3 4 5 6 7 8 9 10 |
*draw_map redraw 0 color 255, 255, 255 : boxf repeat numx * numy if cnt = space : continue pos cnt \ numx * SX, cnt / numx * SY gcopy 2, tip.cnt \ numx * SX, tip.cnt / numx * SY, SX, SY loop redraw 1 return |
1 2 3 4 5 6 7 8 |
#define SX (ginfo_winx / numx) #define SY (ginfo_winy / numy) numx = 3 numy = 3 randomize gosub *game_start stop |
1 2 3 4 5 6 7 |
*game_start space = 0 // 現在の空きマス位置 clear = 0 // ゲームクリアフラグ gosub *draw_tips // ステージ準備 gosub *shuffle // マス位置のランダム化 gosub *draw_map // 各マス描画 return |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
*game_main repeat wait 1 stick key if key & 256 { i.0 = mousex / SX + mousey / SY * numx i.1 = (i - 1 = space) & (i \ numx ! 0) i.2 = (i - numx = space) & (i / numx ! 0) i.3 = (i + 1 = space) & (i \ numx ! numx - 1) i.4 = (i + numx = space) & (i / numx ! numy - 1) if i.1 | i.2 | i.3 | i.4 { tip.space = tip.space ^ tip.i tip.i = tip.space ^ tip.i tip.space = tip.space ^ tip.i space = i gosub *draw_map } } loop return |
1 2 3 4 5 6 7 8 9 |
#define SX (ginfo_winx / numx) #define SY (ginfo_winy / numy) numx = 3 numy = 3 randomize gosub *game_start gosub *game_main stop |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
*game_main repeat wait 1 stick key if key & 256 { i.0 = mousex / SX + mousey / SY * numx i.1 = (i - 1 = space) & (i \ numx ! 0) i.2 = (i - numx = space) & (i / numx ! 0) i.3 = (i + 1 = space) & (i \ numx ! numx - 1) i.4 = (i + numx = space) & (i / numx ! numy - 1) if i.1 | i.2 | i.3 | i.4 { tip.space = tip.space ^ tip.i tip.i = tip.space ^ tip.i tip.space = tip.space ^ tip.i space = i gosub *draw_map gosub *clear_check if clear : break } } loop return |
1 2 3 4 5 6 |
*clear_check clear = 1 // クリアフラグを一旦ONにしておく repeat numx * numy if tip.cnt ! cnt : clear = 0 : break // 元の並びでないならクリアフラグをOFFにして確認終了 loop return |
1 2 3 4 5 6 7 8 9 10 |
#define SX (ginfo_winx / numx) #define SY (ginfo_winy / numy) numx = 3 numy = 3 randomize gosub *game_start gosub *game_main gosub *game_clear stop |
1 2 3 4 5 6 7 8 9 10 |
*game_clear repeat 8, 1 wait 10 gmode 3, SX, SY, cnt * 32 pos space \ numx * SX, space / numx * SY gcopy 2, tip.space \ numx * SX, tip.space / numx * SY loop pos 0, 0 : gcopy 1, , , ginfo_winx, ginfo_winy dialog "Game Clear !" return |