Did Not Understand Diagnol Check Code in Tic Tac Toe Example

SachGw

Member
Licensed User
Longtime User
Hi Guys,I am having a bit of problem understanding the Logic in following piece of code from Tic Tac Toe example.Could anybody please explain me how the code works.. :sign0085:

B4X:
   'Check diagonals
   found = True
   For i = 0 To 2
      found = found AND Buttons(i, i).Text = Player
   Next
   If found = True Then Return True
   
   found = True
   For i = 0 To 2
      found = found AND Buttons(i, 2 - i).Text = Player
   Next
   If found = True Then Return True
   Return False
 

Widget

Well-Known Member
Licensed User
Longtime User
There are 2 diagonals to check so there are two loops.

The first loop checks for (0,0), (1,1), (2,2)
The second loop checks for (0,2),(1,1),(2,0)

Widget
 
Upvote 0

Hero post

Member
Licensed User
Longtime User
What Button has been touched

I want to use part of the tictactoe code for4 an app of mine, but I need to know what button has been clicked.
I have three rows of buttons, but I am unclear on how to i:sign0104:dentify the button.
 
Upvote 0
Top