Results 1 to 8 of 8

Thread: vb tic tac toe

  1. #1

    Thread Starter
    New Member
    Join Date
    May 2007
    Posts
    3

    vb tic tac toe

    Hey guys im new to vb and im trying to make this game for my class. But im having a little trouble. This is what i have so far and im wondering if you guys could look at it.




    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    Dim arrgrid(3, 3) As Integer
    Dim intwhosturn As Integer
    Dim intwhoswinner As Integer
    Call initgrid()
    Call setdifficulty(difficulty.medium)
    intwhosturn = 1
    For i As Integer = 0 To 2
    For j As Integer = 0 To 2
    arrgrid(i, j) = 0
    Next
    Next
    Call DrawGrid()
    If arrgrid(0, 0) = 1 Then
    Me.lblgrid00.Text = "O"
    ElseIf arrgrid(0, 0) = 2 Then
    Me.lblgrid00.Text = "X"
    Else
    Me.lblgrid00.Text = ""
    End If
    Call GridClick(0, 0)
    If (arrgrid(intRow, intCol) = 0) And (intwhoswinner = 0) Then

    If intwhosturn = 1 Then
    arrgrid(intRow, intCol) = 1
    intwhosturn = 2
    ElseIf intwhosturn = 2 Then
    arrgrid(intRow, intCol) = 2
    intwhosturn = 1
    End If

    Call DrawGrid()
    Call CheckWinLose()

    If (intwhosturn = 2) And (intwhoswinner = 0) Then

    End If
    If intwhoswinner = 3 Then
    MessageBox.Show("It's a draw")
    ElseIf intwhoswinner = 2 Then
    MessageBox.Show("You Lose")
    ElseIf intwhoswinner = 1 Then
    MessageBox.Show("You Win")
    End If
    Dim intOCount As Integer = 0
    Dim intXCount As Integer = 0
    Dim intTotalCount As Integer = 0
    For i As Integer = 0 To 2
    For j As Integer = 0 To 2
    If arrgrid(i, j) = 1 Then
    intOCount += 1
    intTotalCount += 1
    End If

    If arrgrid(i, j) = 2 Then
    intXCount += 1
    intTotalCount += 1
    End If
    Next

    If intOCount = 3 Then
    intwhoswinner = 1
    ElseIf intXCount = 3 Then
    intwhoswinner = 2
    End If

    intOCount = 0
    intXCount = 0
    Next
    If (intTotalCount = 9) And (intwhoswinner = 0) Then
    intwhoswinner = 3
    Else
    intTotalCount = 0
    End If
    If arrgrid(0, 0) = 1 And arrgrid(1, 1) = 1 And arrgrid(2, 2) = 1 Then
    intwhoswinner = 1
    ElseIf arrgrid(0, 0) = 2 And arrgrid(1, 1) = 2 And arrgrid(2, 2) = 2 Then
    intwhoswinner = 2
    ElseIf arrgrid(0, 2) = 1 And arrgrid(1, 1) = 1 And arrgrid(2, 0) = 1 Then
    intwhoswinner = 1
    ElseIf arrgrid(0, 2) = 2 And arrgrid(1, 1) = 2 And arrgrid(2, 0) = 2 Then
    intwhoswinner = 2
    End If


    End If

  2. #2
    G&G Moderator chemicalNova's Avatar
    Join Date
    Jun 2002
    Location
    Victoria, Australia
    Posts
    4,246

    Re: vb tic tac toe

    Please format the code. ( using [highlight=vb][/highlight] ).

    Then, zip your project up. Not only have you just slapped some code there, it doesn't really do anything. You call about 5 other functions in that part of the code.. what do they do?

    chem

    Visual Studio 6, Visual Studio.NET 2005, MASM

  3. #3
    Hyperactive Member singularis's Avatar
    Join Date
    Nov 2006
    Location
    Over There!
    Posts
    372

    Re: vb tic tac toe

    One more thing.... This is not VB code, this is VB.net code!
    If what I said was helpful, give me rep!

    My Complete Games: -- 2D Zone (Space Shooter game) || _2D Zone 2_ || Ninja Blob (2D platformer) || Dren (Co-op up to 4 player base defence game)

    My Projects: -- The Dread Engine (2D VB game Engine) || A* Path Finding


    An excellent site for learning DirectX7, 8 & 9 (for VB6, C# & VB.net) would be: directx4vb.vbgamer.com --- For my projects and games see: pieper.freehostia.com

  4. #4

    Thread Starter
    New Member
    Join Date
    May 2007
    Posts
    3

    Re: vb tic tac toe

    Im sorry, this is giving me a lot of trouble. I tried to do this using a write up online and thats what I came up with and obviously ran into a bunch of problems. Any help from you guys would be greatly appreciated and do you guys have a code for a simple tic tac toe game that I can look at and try to figure this out.

  5. #5
    Hyperactive Member singularis's Avatar
    Join Date
    Nov 2006
    Location
    Over There!
    Posts
    372

    Re: vb tic tac toe

    Yes.... but I wrote a Tic Tac Toe game about 2 years ago and my coding was terrible. I would not want you to learn from that , just look on the internet for sample code...
    If what I said was helpful, give me rep!

    My Complete Games: -- 2D Zone (Space Shooter game) || _2D Zone 2_ || Ninja Blob (2D platformer) || Dren (Co-op up to 4 player base defence game)

    My Projects: -- The Dread Engine (2D VB game Engine) || A* Path Finding


    An excellent site for learning DirectX7, 8 & 9 (for VB6, C# & VB.net) would be: directx4vb.vbgamer.com --- For my projects and games see: pieper.freehostia.com

  6. #6

    Thread Starter
    New Member
    Join Date
    May 2007
    Posts
    3

    Re: vb tic tac toe

    Honestly, anything would help right now. As long as it works and I can look at it I would apprepicate it if you could give it to me.

  7. #7
    Hyperactive Member singularis's Avatar
    Join Date
    Nov 2006
    Location
    Over There!
    Posts
    372

    Re: vb tic tac toe

    *cough* Try this link: http://www.cespage.com/vb/vbextut9.html *cough*
    If what I said was helpful, give me rep!

    My Complete Games: -- 2D Zone (Space Shooter game) || _2D Zone 2_ || Ninja Blob (2D platformer) || Dren (Co-op up to 4 player base defence game)

    My Projects: -- The Dread Engine (2D VB game Engine) || A* Path Finding


    An excellent site for learning DirectX7, 8 & 9 (for VB6, C# & VB.net) would be: directx4vb.vbgamer.com --- For my projects and games see: pieper.freehostia.com

  8. #8
    Frenzied Member zynder's Avatar
    Join Date
    Nov 2006
    Location
    localhost
    Posts
    1,434

    Re: vb tic tac toe

    Just to get you started with, create a control array of buttons then

    Code:
    Option Explicit
    Dim oClick As Boolean
    
    
    Private Sub Command1_Click(Index As Integer)
    If oClick Then
        Command1(Index).Caption = "O"
        oClick = False
    Else
        Command1(Index).Caption = "X"
        oClick = True
    End If
    End Sub
    
    Private Sub Form_Load()
        oClick = True
    End Sub

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