Results 1 to 40 of 62

Thread: seeking help with a project.......!, Gomoku or 5 in a row Game

Threaded View

  1. #1

    Thread Starter
    Member
    Join Date
    Feb 2009
    Posts
    52

    seeking help with a project.......!, Gomoku or 5 in a row Game

    hello everyone...........

    im working on a project in vb6. the project is a game called 5 in a row........its like tic tac toe but on a bigger grid....i have got a 19 x 19 grid..the grid is made using labels. so i have 361 labels...all the labels are in an array ..when a user click it put X or O.........currently it two players game....noughts and crosses........now i need help in check if noughts or crosses are 5 in row ...it could be Vertically, horizontally or diagonally..........i got Vertically and horizontally working............

    im wondering if anyone can help me with diagional checking ..................thnx

    the code that i used is like
    Code:
    Function Check(turn As String) As Boolean 'check for victory
    
    Dim X, Y, index As Integer
    Dim InARow As Integer
    
    ' check for horizontal win
    For Y = 0 To 18
    InARow = 0
    
    For X = 0 To 18
    index = (Y * 19) + X
    
    If Label1(index).Caption = turn Then
    InARow = InARow + 1
    If InARow >= 5 Then GoTo FoundWinner
    Else
    InARow = InARow - 1
    If InARow < 0 Then InARow = 0
    End If
    Next X
    Next Y
    
    ' check for vertical win
    For X = 0 To 18
    InARow = 0
    
    For Y = 0 To 18
    index = (Y * 19) + X
    
    If Label1(index).Caption = turn Then
    InARow = InARow + 1
    If InARow >= 5 Then GoTo FoundWinner
    Else
    InARow = InARow - 1
    If InARow < 0 Then InARow = 0
    End If
    Next Y
    Next X
    
    FoundWinner:
    
    If InARow >= 5 Then
    '==========================Player 1==================================
    If turn = "X" Then
    MsgBox "Player 1 wins!"
    
    player1_score = player1_score + 1
    lbl_player1score.Caption = player1_score
    
    cleargrid
    
    
    End If
    
    
    '==========================Player 2==================================
    If turn = "O" Then
    MsgBox "player 2 wins!"
    
    player2_score = player2_score + 1
    lbl_player2score.Caption = player2_score
    
    cleargrid
    
    End If
    
    End If
    
    End Function
    Last edited by Hack; Feb 18th, 2009 at 12:06 PM. Reason: Added Code Tags

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width