Post by tsh73 on Dec 13, 2021 21:50:49 GMT
Magic square.
On BMPbuttons.
Lovely ;)
On BMPbuttons.
Lovely ;)
'playing with bmpbuttons
'tsh73 dec 2021
'now add logic over mechanics
nomainwin
desiredWidth = 400
desiredHeight = 400
gosub [ajustWindow]
'now, center window
UpperLeftX = (DisplayWidth - WindowWidth)/2
UpperLeftY = (DisplayHeight - WindowHeight)/2
'now, open your window with desired size
'BackgroundColor$ = "darkblue"
'of cource this is BASIC-generated code
bmpbutton #main.lttr00, "letr.bmp", btnClick, UL, 0, 0
bmpbutton #main.lttr01, "letr.bmp", btnClick, UL, 80, 0
bmpbutton #main.lttr02, "letr.bmp", btnClick, UL, 160, 0
bmpbutton #main.lttr03, "letr.bmp", btnClick, UL, 240, 0
bmpbutton #main.lttr04, "letr.bmp", btnClick, UL, 320, 0
bmpbutton #main.lttr10, "letr.bmp", btnClick, UL, 0, 80
bmpbutton #main.lttr11, "letr.bmp", btnClick, UL, 80, 80
bmpbutton #main.lttr12, "letr.bmp", btnClick, UL, 160, 80
bmpbutton #main.lttr13, "letr.bmp", btnClick, UL, 240, 80
bmpbutton #main.lttr14, "letr.bmp", btnClick, UL, 320, 80
bmpbutton #main.lttr20, "letr.bmp", btnClick, UL, 0, 160
bmpbutton #main.lttr21, "letr.bmp", btnClick, UL, 80, 160
bmpbutton #main.lttr22, "letr.bmp", btnClick, UL, 160, 160
bmpbutton #main.lttr23, "letr.bmp", btnClick, UL, 240, 160
bmpbutton #main.lttr24, "letr.bmp", btnClick, UL, 320, 160
bmpbutton #main.lttr30, "letr.bmp", btnClick, UL, 0, 240
bmpbutton #main.lttr31, "letr.bmp", btnClick, UL, 80, 240
bmpbutton #main.lttr32, "letr.bmp", btnClick, UL, 160, 240
bmpbutton #main.lttr33, "letr.bmp", btnClick, UL, 240, 240
bmpbutton #main.lttr34, "letr.bmp", btnClick, UL, 320, 240
bmpbutton #main.lttr40, "letr.bmp", btnClick, UL, 0, 320
bmpbutton #main.lttr41, "letr.bmp", btnClick, UL, 80, 320
bmpbutton #main.lttr42, "letr.bmp", btnClick, UL, 160, 320
bmpbutton #main.lttr43, "letr.bmp", btnClick, UL, 240, 320
bmpbutton #main.lttr44, "letr.bmp", btnClick, UL, 320, 320
open "*MAGIC*" for window_nf as #main
#main, "trapclose [quit]"
'initial placement
dim c$(4,4) 'letters for swapping
dim a(4,4) 'is avaliable for moving -1 (or fixed - 0)
global code$
code$="FNGBENERCBGRARGBCRENEBGNF"
ltrs$="AAAAEEEENOOOOPPRRRRSSTTTT"
for i = 0 to 4
for j = 0 to 4
pos=i*5+j +1
r=int(rnd(0)*len(ltrs$))+1
c$=mid$(ltrs$,r,1)
c$(i,j)=c$ 'array to do swapping
ltrs$=left$(ltrs$, r-1)+mid$(ltrs$,r+1)
handle$="#main.lttr";i;j
if mid$(code$,pos,1)=rot13$(c$) then
bmp$="ltr";"R";c$
a(i,j)=0 'should not be moved
'#handle$ "disable" 'it is right but not interesting
else
bmp$="ltr";"N";c$
a(i,j)=1
end if
'print c$;
'print i, j, r, c$, ltrs$
#handle$ "bitmap ";bmp$
next
'print
next
global selI, selJ
selI=-1: selJ=-1
wait
'-----------------------
[quit]
timer 0
close #main
end
'-------------------------------------------------
[ajustWindow]
UpperLeftX = 20
UpperLeftY = 20
WindowWidth = 200 '100 seems to be too much - works different
WindowHeight = 200
open "Ajusting..." for graphics_nsb_nf as #gr
' graphics
' graphics_nsb
' graphics_nsb_nf
#gr, "home ; down ; posxy x y"
'x, y give us width, height
width = 2*x : height = 2*y
#gr "backcolor white"
' #gr "font times_new_roman bold 30 80"
' #gr "font times_new_roman 30 80"
' #gr "place 10 65"
' #gr "\";"M"
gosub [btn]
#gr "getbmp tmp0 1 1 80 80"
bmpsave "tmp0", "letr.bmp"
#gr "font times_new_roman 30 80"
base$="ltrN"
for i = asc("A") to asc("Z")
#gr "place 1 1; boxfilled 81 81"
c$=chr$(i)
#gr "stringwidth? c$ w"
#gr "place ";40-w/2;" 65"
#gr "\";c$
gosub [btn]
#gr "getbmp ";base$;chr$(i);" 1 1 80 80"
next
#gr "font times_new_roman 30 80"
base$="ltrR"
for i = asc("A") to asc("Z")
#gr "place 1 1; boxfilled 81 81"
c$=chr$(i)
#gr "stringwidth? c$ w"
#gr "place ";40-w/2;" 65"
#gr "color red"
#gr "\";chr$(i)
gosub [btn]
#gr "getbmp ";base$;chr$(i);" 1 1 80 80"
next
#gr "color black"
#gr "font times_new_roman bold 30 80"
base$="ltrB"
for i = asc("A") to asc("Z")
#gr "place 1 1; boxfilled 81 81"
c$=chr$(i)
#gr "stringwidth? c$ w"
#gr "place ";40-w/2;" 65"
#gr "\";c$
gosub [btn]
#gr "getbmp ";base$;chr$(i);" 1 1 80 80"
next
close #gr
slackX = 200-width
slackY = 200-height
WindowWidth = desiredWidth + slackX
WindowHeight = desiredHeight + slackY
return
[btn]
#gr "size 3; color lightgray"
#gr "place 3 3; box 80 80"
#gr "color darkgray"
#gr "place 6 6; box 79 79"
#gr "color white; place 6 6; box 76 76"
#gr "size 1; color black"
#gr "place 1 1; box 81 81"
return
'====================================
sub btnClick handle$
i=val(mid$(handle$,11,1))
j=val(mid$(handle$,12,1))
'notice handle$;":";i;j
'print i, j, c$(i,j), selI, selJ
if not(a(i,j)) then exit sub
if selI=-1 then 'do select
selI=i:selJ=j
bmp$="ltr";"B";c$(i,j)
#handle$ "bitmap ";bmp$
exit sub
else 'do swap
tmp$=c$(i,j)
c$(i,j)=c$(selI,selJ)
c$(selI,selJ)=tmp$
'check if new letters fit
pos=i*5+j +1
c$=c$(i,j)
if mid$(code$,pos,1)=rot13$(c$) then
bmp$="ltr";"R";c$
a(i,j)=0 'should not be moved
else
bmp$="ltr";"N";c$
end if
#handle$ "bitmap ";bmp$
'same for selI, selJ
i=selI: j=selJ
handle$="#main.lttr";i;j
pos=i*5+j +1
c$=c$(i,j)
if mid$(code$,pos,1)=rot13$(c$) then
bmp$="ltr";"R";c$
a(i,j)=0 'should not be moved
else
bmp$="ltr";"N";c$
end if
#handle$ "bitmap ";bmp$
'clear selection
selI=-1: selJ=-1
end if
end sub
function rot13$(a$) 'toy code. But it hides from a plain sight.
rot13$ = ""
A0=asc("A")
for i = 1 to len(a$)
c0=asc(mid$(a$,i,1))
c = (c0-A0 +13) mod 26
c1 = c+A0
'print i, c0, c, c1
rot13$=rot13$+chr$(c1)
next
end function