Hi,
I'm writing a Naughts and Crosses game (kind of like Tic-Tac-Toe, but you have an unlimited playing field and your goal is to get five in a row).
I've written a function to check if there are five in a row or not. First it check vertical, then horizontal, then diagonaly - this is what is causing me troubles... I can check one of the diagonals, the one leaning to the left at the top (kind of like this: \ ) But the one leaning to the right at the top (like this: / ) is harder.
The way my function works is that it takes the cell the user placed the last piece on and then checks four cells out from that cell in all directions. This is the piece of code that doesn't work (it doesn't detect a win). Please have a look(I'm playing this on a MSFlexGrid)VB Code:
'check (/) ---------------------------------------- intForRow = intRow + 5 'intRow is the row the last piece was put on For intFor = (intCol - 4) To (intCol + 4) 'intCol is the col the last piece was put on intForRow = intForRow - 1 If intFor >= 0 And intFor <= mfg.Cols - 1 And intForRow >= 0 And intForRow <= mfg.Rows - 1 Then mfg.Col = intFor mfg.Row = intForRow If mfg.Text = strPlayer Then 'strPlayer is either X or O intCheck = intCheck + 1 Else If intCheck >= 5 Then check = True 'check is the name of this function Exit Function End If intCheck = 0 End If End If Next




Reply With Quote