3 Replies - 1835 Views - Last Post: 18 October 2012 - 10:30 PM Rate Topic: -----

#1 the De-Coded-Man  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 31-August 12

i tried to make a tic tac toe game but getting a problem at conditions

Posted 24 September 2012 - 09:15 AM

I made and Tic Tac Toe game everything works fine till either X or O makes pairs.
But if no one get pair still it show Player 1 won...
I tried for DRAW condition but nothing happens, below is my code.
Dim cnt As Integer
Dim flag As Boolean
Private Sub Command1_Click()
If flag = False Then
Command1.Caption = "X"
flag = True
Else
Command1.Caption = "O"
flag = False
End If
win
End Sub

Private Sub Command10_Click()
Label3.Caption = ""
Label4.Caption = ""
End Sub

Private Sub Command11_Click()
Label3.Caption = ""
Label4.Caption = ""
End Sub

Private Sub Command2_Click()
If flag = False Then
Command2.Caption = "X"
flag = True
Else
Command2.Caption = "O"
flag = False
End If
win
End Sub

Private Sub Command3_Click()
If flag = False Then
Command3.Caption = "X"
flag = True
Else
Command3.Caption = "O"
flag = False
End If
win
End Sub

Private Sub Command4_Click()
If flag = False Then
Command4.Caption = "X"
flag = True
Else
Command4.Caption = "O"
flag = False
End If
win
End Sub

Private Sub Command5_Click()
If flag = False Then
Command5.Caption = "X"
flag = True
Else
Command5.Caption = "O"
flag = False
End If
win
End Sub

Private Sub Command6_Click()
If flag = False Then
Command6.Caption = "X"
flag = True
Else
Command6.Caption = "O"
flag = False
End If
win
End Sub

Private Sub Command7_Click()
If flag = False Then
Command7.Caption = "X"
flag = True
Else
Command7.Caption = "O"
flag = False
End If
win
End Sub

Private Sub Command8_Click()
If flag = False Then
Command8.Caption = "X"
flag = True
Else
Command8.Caption = "O"
flag = False
End If
win
End Sub

Private Sub Command9_Click()
If flag = False Then
Command9.Caption = "X"
flag = True
Else
Command9.Caption = "O"
flag = False
End If
win
End Sub

Private Sub win()
If Command1.Caption = "X" And Command2.Caption = "X" And Command3.Caption = "X" Then
MsgBox ("Player X wins")
Label3.Caption = Val(Label3.Caption) + Val(1)
Command1.Caption = ""
Command2.Caption = ""
Command3.Caption = ""
Command4.Caption = ""
Command5.Caption = ""
Command6.Caption = ""
Command7.Caption = ""
Command8.Caption = ""
Command9.Caption = ""
Else
cnt = Val(cnt) + Val(1)
End If
'Else
If Command1.Caption = "X" And Command4.Caption = "X" And Command7.Caption = "X" Then
MsgBox ("Player X wins")
Label3.Caption = Val(Label3.Caption) + Val(1)
Command1.Caption = ""
Command2.Caption = ""
Command3.Caption = ""
Command4.Caption = ""
Command5.Caption = ""
Command6.Caption = ""
Command7.Caption = ""
Command8.Caption = ""
Command9.Caption = ""
Else
cnt = Val(cnt) + Val(1)
End If
'Else
If Command1.Caption = "X" And Command5.Caption = "X" And Command9.Caption = "X" Then
MsgBox ("Player X wins")
Label3.Caption = Val(Label3.Caption) + Val(1)
Command1.Caption = ""
Command2.Caption = ""
Command3.Caption = ""
Command4.Caption = ""
Command5.Caption = ""
Command6.Caption = ""
Command7.Caption = ""
Command8.Caption = ""
Command9.Caption = ""
Else
cnt = Val(cnt) + Val(1)
End If
'Else
If Command2.Caption = "X" And Command5.Caption = "X" And Command8.Caption = "X" Then
MsgBox ("Player X wins")
Label3.Caption = Val(Label3.Caption) + Val(1)
Command1.Caption = ""
Command2.Caption = ""
Command3.Caption = ""
Command4.Caption = ""
Command5.Caption = ""
Command6.Caption = ""
Command7.Caption = ""
Command8.Caption = ""
Command9.Caption = ""
Else
cnt = Val(cnt) + Val(1)
End If
'Else
If Command3.Caption = "X" And Command6.Caption = "X" And Command9.Caption = "X" Then
MsgBox ("Player X wins")
Label3.Caption = Val(Label3.Caption) + Val(1)
Command1.Caption = ""
Command2.Caption = ""
Command3.Caption = ""
Command4.Caption = ""
Command5.Caption = ""
Command6.Caption = ""
Command7.Caption = ""
Command8.Caption = ""
Command9.Caption = ""
Else
cnt = Val(cnt) + Val(1)
End If
'Else
If Command4.Caption = "X" And Command5.Caption = "X" And Command6.Caption = "X" Then
MsgBox ("Player X wins")
Label3.Caption = Val(Label3.Caption) + Val(1)
Command1.Caption = ""
Command2.Caption = ""
Command3.Caption = ""
Command4.Caption = ""
Command5.Caption = ""
Command6.Caption = ""
Command7.Caption = ""
Command8.Caption = ""
Command9.Caption = ""
Else
cnt = Val(cnt) + Val(1)
End If
'Else
If Command7.Caption = "X" And Command8.Caption = "X" And Command9.Caption = "X" Then
MsgBox ("Player X wins")
Label3.Caption = Val(Label3.Caption) + Val(1)
Command1.Caption = ""
Command2.Caption = ""
Command3.Caption = ""
Command4.Caption = ""
Command5.Caption = ""
Command6.Caption = ""
Command7.Caption = ""
Command8.Caption = ""
Command9.Caption = ""
Else
cnt = Val(cnt) + Val(1)
End If
'Else
If Command3.Caption = "X" And Command5.Caption = "X" And Command7.Caption = "X" Then
MsgBox ("Player X wins")
Label3.Caption = Val(Label3.Caption) + Val(1)
Command1.Caption = ""
Command2.Caption = ""
Command3.Caption = ""
Command4.Caption = ""
Command5.Caption = ""
Command6.Caption = ""
Command7.Caption = ""
Command8.Caption = ""
Command9.Caption = ""
Else
cnt = Val(cnt) + Val(1)
End If

'Else
If Command1.Caption = "O" And Command2.Caption = "O" And Command3.Caption = "O" Then
MsgBox ("Player O wins")
Label4.Caption = Val(Label4.Caption) + Val(1)
Command1.Caption = ""
Command2.Caption = ""
Command3.Caption = ""
Command4.Caption = ""
Command5.Caption = ""
Command6.Caption = ""
Command7.Caption = ""
Command8.Caption = ""
Command9.Caption = ""
Else
cnt = Val(cnt) + Val(1)
End If
'Else
If Command1.Caption = "O" And Command4.Caption = "O" And Command7.Caption = "O" Then
MsgBox ("Player O wins")
Label4.Caption = Val(Label4.Caption) + Val(1)
Command1.Caption = ""
Command2.Caption = ""
Command3.Caption = ""
Command4.Caption = ""
Command5.Caption = ""
Command6.Caption = ""
Command7.Caption = ""
Command8.Caption = ""
Command9.Caption = ""
Else
cnt = Val(cnt) + Val(1)
End If
'Else
If Command1.Caption = "O" And Command5.Caption = "O" And Command9.Caption = "O" Then
MsgBox ("Player O wins")
Label4.Caption = Val(Label4.Caption) + Val(1)
Command1.Caption = ""
Command2.Caption = ""
Command3.Caption = ""
Command4.Caption = ""
Command5.Caption = ""
Command6.Caption = ""
Command7.Caption = ""
Command8.Caption = ""
Command9.Caption = ""
Else
cnt = Val(cnt) + Val(1)
End If
'Else
If Command2.Caption = "O" And Command5.Caption = "O" And Command8.Caption = "O" Then
MsgBox ("Player O wins")
Label4.Caption = Val(Label4.Caption) + Val(1)
Command1.Caption = ""
Command2.Caption = ""
Command3.Caption = ""
Command4.Caption = ""
Command5.Caption = ""
Command6.Caption = ""
Command7.Caption = ""
Command8.Caption = ""
Command9.Caption = ""
Else
cnt = Val(cnt) + Val(1)
End If
'Else
If Command3.Caption = "O" And Command6.Caption = "O" And Command9.Caption = "O" Then
MsgBox ("Player O wins")
Label4.Caption = Val(Label4.Caption) + Val(1)
Command1.Caption = ""
Command2.Caption = ""
Command3.Caption = ""
Command4.Caption = ""
Command5.Caption = ""
Command6.Caption = ""
Command7.Caption = ""
Command8.Caption = ""
Command9.Caption = ""
Else
cnt = Val(cnt) + Val(1)
End If
'Else
If Command4.Caption = "O" And Command5.Caption = "O" And Command6.Caption = "O" Then
MsgBox ("Player O wins")
Label4.Caption = Val(Label4.Caption) + Val(1)
Command1.Caption = ""
Command2.Caption = ""
Command3.Caption = ""
Command4.Caption = ""
Command5.Caption = ""
Command6.Caption = ""
Command7.Caption = ""
Command8.Caption = ""
Command9.Caption = ""
Else
cnt = Val(cnt) + Val(1)
End If
'Else
If Command7.Caption = "O" And Command8.Caption = "O" And Command9.Caption = "O" Then
MsgBox ("Player O wins")
Label4.Caption = Val(Label4.Caption) + Val(1)
Command1.Caption = ""
Command2.Caption = ""
Command3.Caption = ""
Command4.Caption = ""
Command5.Caption = ""
Command6.Caption = ""
Command7.Caption = ""
Command8.Caption = ""
Command9.Caption = ""
Else
cnt = Val(cnt) + Val(1)
End If
'Else
If Command3.Caption = "O" And Command5.Caption = "O" And Command7.Caption = "O" Then
MsgBox ("Player O wins")
Label4.Caption = Val(Label4.Caption) + Val(1)
Command1.Caption = ""
Command2.Caption = ""
Command3.Caption = ""
Command4.Caption = ""
Command5.Caption = ""
Command6.Caption = ""
Command7.Caption = ""
Command8.Caption = ""
Command9.Caption = ""
Else
cnt = Val(cnt) + Val(1)
End If
If (Val(cnt) <> 1) Then
MsgBox ("Draw... Better Luck Next Time..."), vbInformation
End If
End Sub



Is This A Good Question/Topic? 0
  • +

Replies To: i tried to make a tic tac toe game but getting a problem at conditions

#2 BobRodes  Icon User is offline

  • Your Friendly Local Curmudgeon
  • member icon

Reputation: 574
  • View blog
  • Posts: 2,989
  • Joined: 19-May 09

Re: i tried to make a tic tac toe game but getting a problem at conditions

Posted 25 September 2012 - 06:57 AM

I'm sorry, but I just can't make myself go to the trouble of answering your question directly. It's like you go into one of those houses where people are unable to throw away their stuff and they have stuff piled everywhere and they want you to help them find a piece of paper they've mislaid. The only response is to tell them they have to clean house, and to offer to help if they are willing.

I know that you're doing this because you lack experience, but you still need to understand that you can do this job with maybe 40 lines of code. If you want me to help you do that, then post back and I'll start giving you lessons.

Lesson 1 is control arrays. For a tutorial, google "vb6 control arrays". (Be careful to avoid all of Microsoft's pollution of google VB6 searches with VB.Net stuff.)

This post has been edited by BobRodes: 25 September 2012 - 07:00 AM

Was This Post Helpful? 1
  • +
  • -

#3 the De-Coded-Man  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 31-August 12

Re: i tried to make a tic tac toe game but getting a problem at conditions

Posted 26 September 2012 - 09:54 AM

View PostBobRodes, on 25 September 2012 - 06:57 AM, said:

I'm sorry, but I just can't make myself go to the trouble of answering your question directly. It's like you go into one of those houses where people are unable to throw away their stuff and they have stuff piled everywhere and they want you to help them find a piece of paper they've mislaid. The only response is to tell them they have to clean house, and to offer to help if they are willing.

I know that you're doing this because you lack experience, but you still need to understand that you can do this job with maybe 40 lines of code. If you want me to help you do that, then post back and I'll start giving you lessons.

Lesson 1 is control arrays. For a tutorial, google "vb6 control arrays". (Be careful to avoid all of Microsoft's pollution of google VB6 searches with VB.Net stuff.)


Thnx! i too got an idea about that clearing statements ex. Command1.Caption = ""
I should have made an function and then called it instead of whole the commands..
.
And Yes! i would like to learn more about VB, as our college don't teach us in depth..
Was This Post Helpful? 0
  • +
  • -

#4 BobRodes  Icon User is offline

  • Your Friendly Local Curmudgeon
  • member icon

Reputation: 574
  • View blog
  • Posts: 2,989
  • Joined: 19-May 09

Re: i tried to make a tic tac toe game but getting a problem at conditions

Posted 18 October 2012 - 10:30 PM

Sorry to be so slow to reply; had a rough spell at work. So excellent. Start by putting all your command buttons into a control array. Suppose you name them cmdSquare.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1