Private Sub pnl_Click
Dim pnl As Panel = Sender
Dim rowcol As String = pnl.tag
Log("pnl_click: " & rowcol)
If clickcnt < 1 Then
srctext = pnl.GetView(0).As(Label).Text
Log("source: " & srctext)
clickcnt = 1
Else
desttext = pnl.GetView(0).As(Label).Text
Log("destination: " & desttext)
clickcnt = 0
End If
End Sub
End Sub
To make a piece move the user has to tap (or click) on a panel the first time and then tap on another panel the second time. For this we use the clickcnt variable (click count). Private clickcnt As Int = 0
Private srctext As String = ""
Private desttext As String = ""
To test the click event just add the subroutine and the variable declarations and run the app. cnvscell.Initialize(pnl)
show_cell_border(Colors.Green,10dip,cnvscell)
And then add the following subroutine to show a green border:Private Sub show_cell_border(bordercolor As Int, thick As Int, cnv As Canvas)
cnv.DrawRect(BorderRect, bordercolor, False, thick)
cnv.DrawRect(BorderRect, Colors.Black, False, 1dip)
End Sub
Test the app and you will see a green border on each panel you tap.Private Sub refresh_board
pnlmain.RemoveAllViews
For r = 0 To 7
For c = 0 To 7
Private pnl As Panel = set_panel(r,c)
pnl.GetView(0).As(Label).Text = board(r,c)
pnlmain.AddView(pnl,30dip+(c*40dip),30dip+(r*40dip),40dip,40dip)
put_bitmap_in_cell(r,c,pnl,board(r,c))
Next
Next
End Sub
This subroutine is called after the board array has changed. Insert this line above the clickcnt = 0 line in the pnl_Click subroutine. refresh_board
Now if the user taps a second time on a panel the board is refreshed and the borders disappear.Private Sub do_move
Private srow As Int = srcrowcol.SubString2(0,1)
Private scol As Int = srcrowcol.SubString(1)
Private drow As Int = destrowcol.SubString2(0,1)
Private dcol As Int = destrowcol.SubString(1)
board(drow,dcol) = srctext
board(srow,scol) = "EEE"
End Sub
This routine is called before the refresh_board call in the pnl_Click subroutine.Private Sub pnl_Click
Dim pnl As Panel = Sender
Dim rowcol As String = pnl.tag
Log("pnl_click: " & rowcol)
If clickcnt < 1 Then
srctext = pnl.GetView(0).As(Label).Text
Log("source: " & srctext)
cnvscell.Initialize(pnl)
show_cell_border(Colors.Green,10dip,cnvscell)
srcrowcol = rowcol
clickcnt = 1
Else
desttext = pnl.GetView(0).As(Label).Text
Log("destination: " & desttext)
cnvscell.Initialize(pnl)
show_cell_border(Colors.Green,10dip,cnvscell)
destrowcol = rowcol
do_move
refresh_board
show_board_log
clickcnt = 0
End If
End Sub
Run the app and test the moves. Look at the log panel for the changes to the board.