Results 1 to 6 of 6

Thread: VB6.0 Tic Tac Toe/Noughts and Crosses

Threaded View

  1. #1

    Thread Starter
    PowerPoster Nightwalker83's Avatar
    Join Date
    Dec 2001
    Location
    Adelaide, Australia
    Posts
    13,344

    VB6.0 Tic Tac Toe/Noughts and Crosses

    Hi,

    This is a little game of Tic Tac Toe aka Noughts and Crosses that I tried rewriting in VB6.0 from JAVA.

    Change log:

    Tic Tac Toe/Noughts and Crosses
    Language VB6.0
    Author: Nightwalker83
    'Website: http://aaronspehr.net/
    Version 1.0 11/04/2012 - Basic two player functions implemented.
    Version 2.0 14/04/2012 - Implemented player verse computer A.I game
    Version 2.1 21/05/2012 - Allows for player to choose their marker
    VB Code:
    1. Dim CLICKCOUNT, i, winner As Integer
    2.  
    3. Private Sub cmdExit_Click()
    4. 'Quit the game
    5. Unload Me
    6. End Sub
    7.  
    8. Private Sub cmdPlay_Click()
    9. 'Play the game
    10. Play
    11. End Sub
    12.  
    13. Private Sub cmdTile_Click(Index As Integer)
    14. If (CLICKCOUNT Mod 2 = 1) Then
    15. cmdTile(Index).Caption = "x"
    16. Else
    17. cmdTile(Index).Caption = "o"
    18. End If
    19. CLICKCOUNT = CLICKCOUNT + 1
    20. cmdTile(Index).Enabled = False
    21. CheckWinner
    22. End Sub
    23.  
    24. Private Sub Form_Load()
    25. 'Tic Tac Toe/Noughts and Crosses
    26. '14/04/2012
    27. 'Version 1.0
    28. 'Language VB6.0
    29. 'Author: Nightwalker83
    30. 'Website: http://aaronspehr.net/
    31. 'Version 1.0 11/04/2012 - Basic two player functions implemented.
    32. Me.Caption = "Tic Tac Toe/Noughts and Crosses"
    33. For i = 0 To 8
    34. cmdTile(i).Enabled = False
    35. Next i
    36. End Sub
    37.  
    38. Private Sub Play()
    39. CLICKCOUNT = 0
    40. winner = -1
    41. For i = 0 To 8
    42. cmdTile(i).Caption = ""
    43. cmdTile(i).Enabled = True
    44. Next i
    45. End Sub
    46.  
    47. Private Sub CheckWinner()
    48. ' Horizontal row 1
    49. If cmdTile(0).Caption = "o" And cmdTile(1).Caption = "o" And cmdTile(2).Caption = "o" Then winner = 0
    50. If cmdTile(0).Caption = "x" And cmdTile(1).Caption = "x" And cmdTile(2).Caption = "x" Then winner = 1
    51. ' Horizontal row 2
    52. If cmdTile(3).Caption = "o" And cmdTile(4).Caption = "o" And cmdTile(5).Caption = "o" Then winner = 2
    53. If cmdTile(3).Caption = "x" And cmdTile(4).Caption = "x" And cmdTile(5).Caption = "x" Then winner = 3
    54. ' Horizontal row 3
    55. If cmdTile(6).Caption = "o" And cmdTile(7).Caption = "o" And cmdTile(8).Caption = "o" Then winner = 4
    56. If cmdTile(6).Caption = "x" And cmdTile(7).Caption = "x" And cmdTile(8).Caption = "x" Then winner = 5
    57. 'Vertical row 1
    58. If cmdTile(0).Caption = "o" And cmdTile(3).Caption = "o" And cmdTile(6).Caption = "o" Then winner = 6
    59. If cmdTile(0).Caption = "x" And cmdTile(3).Caption = "x" And cmdTile(6).Caption = "x" Then winner = 7
    60. 'Vertical row 2
    61. If cmdTile(1).Caption = "o" And cmdTile(4).Caption = "o" And cmdTile(7).Caption = "o" Then winner = 8
    62. If cmdTile(1).Caption = "x" And cmdTile(4).Caption = "x" And cmdTile(7).Caption = "x" Then winner = 9
    63. 'Vertical row 3
    64. If cmdTile(2).Caption = "o" And cmdTile(5).Caption = "o" And cmdTile(8).Caption = "o" Then winner = 10
    65. If cmdTile(2).Caption = "x" And cmdTile(5).Caption = "x" And cmdTile(8).Caption = "x" Then winner = 11
    66. 'Diagonal 1
    67. If cmdTile(0).Caption = "o" And cmdTile(4).Caption = "o" And cmdTile(8).Caption = "o" Then winner = 12
    68. If cmdTile(0).Caption = "x" And cmdTile(4).Caption = "x" And cmdTile(8).Caption = "x" Then winner = 13
    69. 'Diagonal 2
    70. If cmdTile(2).Caption = "o" And cmdTile(4).Caption = "o" And cmdTile(6).Caption = "o" Then winner = 14
    71. If cmdTile(2).Caption = "x" And cmdTile(4).Caption = "x" And cmdTile(6).Caption = "x" Then winner = 15
    72. 'MsgBox (winner)
    73. If (winner = 0 Or winner = 2 Or winner = 4 Or winner = 6 Or winner = 8 Or winner = 10 Or winner = 12 Or winner = 14) Then
    74.      Result = MsgBox("Player o is victorious! Play Again?", vbYesNo)
    75.      If Result = vbYes Then
    76.      Play
    77.      Else
    78.      endGame
    79.      End If
    80.      End If
    81. If (winner = 1 Or winner = 3 Or winner = 5 Or winner = 7 Or winner = 9 Or winner = 11 Or winner = 13 Or winner = 15) Then
    82.      Result = MsgBox("Player x is victorious! Play Again?", vbYesNo)
    83.      If Result = vbYes Then
    84.      Play
    85.      Else
    86.      endGame
    87.      End If
    88.      End If
    89. If CLICKCOUNT = 9 Then
    90. MsgBox ("This game is a draw!")
    91. endGame
    92. End If
    93. End Sub
    94.  
    95. Private Sub endGame()
    96. For i = 0 To 8
    97. cmdTile(i).Enabled = False
    98. Next i
    99. End Sub

    Comments and suggestions welcome!


    Nightwalker
    Attached Files Attached Files
    Last edited by Nightwalker83; May 24th, 2012 at 04:05 AM. Reason: Adding more!
    when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
    If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
    https://get.cryptobrowser.site/30/4111672

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