Code :
UseJPEGImageDecoder()
IncludeFile "Common.pb"
Declare.b getcoord(x.w,y.w)
Declare pressgo(x.b,y.b)
Declare putoff(x.b,y.b)
steps.w=1
Define.b xindex=0,yindex=0
Dim qp.b(18,18)
Define thisx.w,thisy.w
; open window 0
open_window_0()
;SetClassLongPtr_(WindowID(#window_0), #GCL_HBRBACKGROUND, hBrush)
InitSprite()
OpenWindowedScreen(WindowID(0),319,39,650,650,0,0,0)
#MinX=319:#MaxX=968
#MinY=39:#MaxY=688
;Result = ExamineMouse()
CreateSprite(0,30,30)
CreateSprite(1,30,30)
StartDrawing(SpriteOutput(0))
LoadSprite(0,"blackman.bmp")
StopDrawing()
StartDrawing(SpriteOutput(0))
LoadSprite(1,"whiteman.bmp")
StopDrawing()
TransparentSpriteColor(0,RGB(128,128,128))
TransparentSpriteColor(1,RGB(128,128,128))
Repeat
event=WaitWindowEvent()
Select event
Case #PB_Event_Gadget
Select EventGadget()
Case #Image_0
EventType=EventType()
If eventtype=#PB_EventType_LeftClick
thisx= WindowMouseX(0)
thisy= WindowMouseY(0)
If getcoord(thisx,thisy)
If qp(xindex,yindex)=0
pressgo(xindex,yindex)
steps+1
Else
putoff(xindex,yindex)
EndIf
EndIf
EndIf
EndSelect
Case #WM_PAINT
EndSelect
Until event= #PB_Event_CloseWindow
End
Procedure.b getcoord(x.w,y.w)
Shared qp(),xindex,yindex
Define.f xx,yy
x-#minx
y-#miny
xx=x/(#maxx-#minx)*18
yy=y/(#maxy-#miny)*18
If ((xx-Int(xx))>0.8 Or (xx-Int(xx))<0.2) And ((yy-Int(yy)>0.

Or (yy-Int(yy))<0.2)
xindex=Int(xx+0.5)
yindex=Int(yy+0.5)
If xindex>=0 And xindex<19 And yindex>=0 And yindex<19
If qp(xindex,yindex)=0
ProcedureReturn 1
Else
ProcedureReturn 1
EndIf
EndIf
EndIf
EndProcedure
Procedure pressgo(x.b,y.b)
Shared steps,qp()
Define.w xcoord,ycoord
xcoord=(x+1)*(#maxx-#minx)/18
ycoord=(Y+1)*(#maxy-#miny)/18
;FlipBuffers()
If steps%2
DisplayTransparentSprite(0,xcoord-15,ycoord-15)
qp(x,y)=1
Else
DisplayTransparentSprite(1,xcoord-15,ycoord-15)
qp(x,y)=-1
EndIf
RedrawWindow_(WindowID(0), 0, 0, #RDW_INVALIDATE|#RDW_UPDATENOW)
EndProcedure
Procedure putoff(x.b,y.b)
Shared qp()
Define.w xcoord,ycoord
Define.rect rect
xcoord=#minx+x*(#maxx-#minx)/18
ycoord=#miny+y*(#maxy-#miny)/18
rect\left=xcoord-15
rect\right=xcoord+15
rect\top=ycoord+15
rect\bottom=ycoord-15
hwnd.l=WindowID(0)
;hdc.l=StartDrawing(ImageOutput(0))
;DrawingMode(#PB_2DDrawing_XOr)
;RedrawWindow_(hwnd, @rect, #Null, #RDW_NOFRAME|#RDW_ERASE|#RDW_INVALIDATE | #RDW_UPDATENOW)
;If qp(x,y)>0
;Circle(xcoord,ycoord,14,#White)
;Else
;Circle(xcoord,ycoord,14,#White)
;EndIf
;SetGadgetState(#Image_0,ImageID(0))
;InvalidateRect_(hwnd,@rect,#True)
;UpdateWindow_(hwnd)
;StopDrawing()
;RedrawWindow_(hwnd, @rect, 0, #RDW_ERASE|#RDW_INVALIDATE|#RDW_UPDATENOW)
;qp(x,y)=0
EndProcedure