*define
;vOC
nsa

;^Cg
caption "]Q[ Ver.1.10"

;o[W
versionstr "]Q[ Ver.1.10","F"

;ϐ`-------------------------------------------------
;ϐ
numalias btn,0
numalias lv,1
numalias all,2
numalias red,3
numalias t,4
;֐p
numalias x,30
numalias y,31
numalias z,32
;forp
numalias i,33
numalias j,34
numalias n,35

;zϐ
dim ?0[5]
numalias btn_x,0
dim ?1[5]
numalias btn_y,1
dim ?2[36]
numalias btn_c,2

;ϐ
numalias btnimg1,0
numalias btnimg2,1



;֐`---------------------------------------------------
;XvCgꊇ폜
defsub csps
;XvCgꊇ\E\
defsub vsps


;vOX^[g-----------------------------------------
game
*start
;ݒ---------------------------------------------------
mov %lv,3
mov $btnimg1,":a;img\btn1.bmp"
mov $btnimg2,":a;img\btn2.bmp"

;Q[X^[g
*start_game
movl ?btn_c,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0

;{^vZ
mov %all,%lv
mul %all,%all

;wiE{^Wݒ
if %lv==3 movl ?btn_x,230,290,350,0,0,0
if %lv==3 movl ?btn_y,150,210,270,0,0,0
if %lv==3 lsp 40,":a;img\tb3.bmp",225,145
if %lv==3 bg"img\bg3.jpg",0,100

if %lv==4 movl ?btn_x,200,260,320,380,0,0
if %lv==4 movl ?btn_y,120,180,240,300,0,0
if %lv==4 lsp 40,":a;img\tb4.bmp",195,115
if %lv==4 bg"img\bg4.jpg",0,100

if %lv==5 movl ?btn_x,170,230,290,350,410,0
if %lv==5 movl ?btn_y,90,150,210,270,330,0
if %lv==5 lsp 40,":a;img\tb5.bmp",165,85
if %lv==5 bg"img\bg5.jpg",0,100

if %lv==6 movl ?btn_x,140,200,260,320,380,440
if %lv==6 movl ?btn_y, 60,120,180,240,300,360
if %lv==6 lsp 40,":a;img\tb6.bmp",135,55
if %lv==6 bg"img\bg6.jpg",0,100

;Q[Jn-------------------------------------------------

;萔l
mov %t,0
itoa2 $t,%t

;\
mov %i,0
mov %n,0
for %i=1 to %lv
mov %j,0
	for %j=1 to %lv
		add %n,1
		lsp %n,$btnimg1,?btn_x[%j-1],?btn_y[%i-1]
	next
next

*btn
;c聜vZ
mov %red,%all
for %i=1 to %all
	sub %red,?btn_c[%i]
next
itoa2 $red,%red
;\
lsp  41,":s#5050FFc"+$red+"@"+$t+"",5,5
lsp  42,":s#5050FF#0000FFZbg",5,30
spbtn 42,42

;NA
if %red == 0 goto *clear

;{^
for %i=1 to %all
	spbtn %i,%i
next

;͑҂
btnwait %btn
;{^`
btndef ""

;GAO
if %btn <= 0 goto *btn
;Zbg{^
if %btn == 42 goto *start_game

;WvZ
mov %x,%btn-1
mod %x,%lv
mov %y,%btn-1
div %y,%lv

;{^]
if ?btn_c[%btn] == 0 lsp %btn,$btnimg2,?btn_x[%x],?btn_y[%y]:mov ?btn_c[%btn],1:goto *check
if ?btn_c[%btn] == 1 lsp %btn,$btnimg1,?btn_x[%x],?btn_y[%y]:mov ?btn_c[%btn],0:goto *check

*check
;萔vZ
add %t,1
itoa2 $t,%t

;O`FbN
notif %y==0 gosub *check1
notif %x==0 gosub *check2
notif %y==%lv-1 gosub *check3
notif %x==%lv-1 gosub *check4
gosub *btn

;{^]E
*check1
if ?btn_c[%btn-%lv] == 0 lsp %btn-%lv,$btnimg2,?btn_x[%x],?btn_y[%y-1]:mov ?btn_c[%btn-%lv],1:return
if ?btn_c[%btn-%lv] == 1 lsp %btn-%lv,$btnimg1,?btn_x[%x],?btn_y[%y-1]:mov ?btn_c[%btn-%lv],0:return

;{^]E
*check2
if ?btn_c[%btn-1] == 0   lsp %btn-1,$btnimg2,?btn_x[%x-1],?btn_y[%y]:mov ?btn_c[%btn-1],1:return
if ?btn_c[%btn-1] == 1   lsp %btn-1,$btnimg1,?btn_x[%x-1],?btn_y[%y]:mov ?btn_c[%btn-1],0:return

;{^]E
*check3
if ?btn_c[%btn+%lv] == 0 lsp %btn+%lv,$btnimg2,?btn_x[%x],?btn_y[%y+1]:mov ?btn_c[%btn+%lv],1:return
if ?btn_c[%btn+%lv] == 1 lsp %btn+%lv,$btnimg1,?btn_x[%x],?btn_y[%y+1]:mov ?btn_c[%btn+%lv],0:return

;{^]E
*check4
if ?btn_c[%btn+1] == 0   lsp %btn+1,$btnimg2,?btn_x[%x+1],?btn_y[%y]:mov ?btn_c[%btn+1],1:return
if ?btn_c[%btn+1] == 1   lsp %btn+1,$btnimg1,?btn_x[%x+1],?btn_y[%y]:mov ?btn_c[%btn+1],0:return

;Xe[WNA---------------------------------------------
*clear
if %lv>=6 goto *end
br:br:br:br:br:br:br
@@@@@@@@@bI
@@@@@@mdws@rs`fdI\
add %lv,1
goto *start_game

;I---------------------------------------------------
*end
br:br:br:br:br:br:br
@@@@@@@`kk@bI\
mov %lv,3
csps 1,%all
goto *start_game

;֐-------------------------------------------------------
*vsps
getparam %x,%y,%z
for %x=0 to %y
vsp %x,%z
next
print 1
return

*csps
getparam %x,%y
for %x=0 to %y
csp %x
next
return
