Go Back   Cyber Tech Help Support Forums > Software > Web Development & Graphic Design

Notices

Reply
 
Topic Tools
  #1  
Old August 29th, 2007, 10:43 AM
johnz14's Avatar
johnz14 johnz14 is offline
Senior Member
 
Join Date: Dec 2006
O/S: Windows XP Pro
Location: Australia
Posts: 282
Visual Basic 5.0 CCE

Hi, i need help in programming in visual basic 5.0 CCE. The problem i am having is in a game when a computer makes a move. My aim is to make the computer have random moves then if a certain move is made the move is auto countered. The name of the game is Tic-Tac-Toe. So far i have no idea on how to start the code to make a random move. All help is appreciated.
Reply With Quote
  #2  
Old August 29th, 2007, 08:07 PM
oracle128's Avatar
oracle128 oracle128 is offline
Α Ω
 
Join Date: Oct 2000
O/S: Windows XP Pro
Location: Melbourne, Australia
Age: 24
Posts: 9,401
Pseudo code:
-Pick random number between 1 and 9

-If player picked square 1, make move in square 2
-Else of player picked square 2, make move in square 1
-Etc

However I think you'll find that Tic-Tac-Toe AI isn't random or auto-countering at all. There is in fact a standard pattern of moves that should initially be made, followed by a focus on preventing a win by the human player - or, if this isn't necessary, continue following the attack pattern. If you code the AI right, it won't be possible to beat it.

See also here and here.
__________________
Oracle's backup tutorial

"A lot of people say games are addictive. Well, they're addictive in the sense that anything you like doing you repeat endlessly. But no one would say, 'Mr Kasparov, you have a chess problem,' or 'Tiger Woods, you have a golf addiction.'" - Ian Livingstone, Creative Director, Eidos.

"A problem well stated is a problem half solved" - Charles Franklin Kettering
Reply With Quote
  #3  
Old August 30th, 2007, 09:33 AM
johnz14's Avatar
johnz14 johnz14 is offline
Senior Member
 
Join Date: Dec 2006
O/S: Windows XP Pro
Location: Australia
Posts: 282
thx for your help, but in ur opinion which is easier:
graphical or text based. Because in my opinion image based is harder compared to text since most of the tutorials are text. Also could you give me examples of the Goto Event

Eg. If player picked square 1 then goto CounterMove
CounterMove:
If square 1 = X then
square 2 = O
Endif
and thats all i get up to, then when i play this error comes up.

Also if its not asking too much can i also get an example of the Or Event
E.g If square 1 = X then
square 2 or 3 or 4 or 5 or 7 or 9 = O
Endif
then another error occurs when i press play.
Reply With Quote
  #4  
Old August 30th, 2007, 03:25 PM
oracle128's Avatar
oracle128 oracle128 is offline
Α Ω
 
Join Date: Oct 2000
O/S: Windows XP Pro
Location: Melbourne, Australia
Age: 24
Posts: 9,401
Quote:
in ur opinion which is easier:
graphical or text based. Because in my opinion image based is harder compared to text since most of the tutorials are text.
In VB, graphics would actually easier. In most languages, text would be easier because there's more work in coding the graphical interface. In regards to the game mechanics and AI, it makes no difference, since the engine should be segregated from the interface method.

Quote:
Also could you give me examples of the Goto Event
Code:
If x=1 Then
Goto ONE
Else
Goto NOTONE
End If

ONE:
msgbox "One"
Goto END

NOTONE:
msgbox "Not One"

END:
msgbox "Finished"
Quote:
Also if its not asking too much can i also get an example of the Or Event
Code:
If x=1 Or x=2 Or x=3 Then
msgbox "One, two or three"
End If
Neither "Goto" or "Or" are events though.
__________________
Oracle's backup tutorial

"A lot of people say games are addictive. Well, they're addictive in the sense that anything you like doing you repeat endlessly. But no one would say, 'Mr Kasparov, you have a chess problem,' or 'Tiger Woods, you have a golf addiction.'" - Ian Livingstone, Creative Director, Eidos.

"A problem well stated is a problem half solved" - Charles Franklin Kettering

Last edited by oracle128; August 30th, 2007 at 03:28 PM.
Reply With Quote
  #5  
Old August 31st, 2007, 09:19 AM
johnz14's Avatar
johnz14 johnz14 is offline
Senior Member
 
Join Date: Dec 2006
O/S: Windows XP Pro
Location: Australia
Posts: 282
Umm not quite the Or statement i was looking for, could you possibly make one that has the properties in with it,
eg imgBox(Index).Picture
Reply With Quote
  #6  
Old August 31st, 2007, 05:59 PM
oracle128's Avatar
oracle128 oracle128 is offline
Α Ω
 
Join Date: Oct 2000
O/S: Windows XP Pro
Location: Melbourne, Australia
Age: 24
Posts: 9,401
Quote:
Originally Posted by johnz14 View Post
Umm not quite the Or statement i was looking for, could you possibly make one that has the properties in with it,
eg imgBox(Index).Picture
It's the same syntax.
If <condition1> Or <condition2> Or <condition3> Then
<Do this if true>
Else
<Do this if false>
End If
__________________
Oracle's backup tutorial

"A lot of people say games are addictive. Well, they're addictive in the sense that anything you like doing you repeat endlessly. But no one would say, 'Mr Kasparov, you have a chess problem,' or 'Tiger Woods, you have a golf addiction.'" - Ian Livingstone, Creative Director, Eidos.

"A problem well stated is a problem half solved" - Charles Franklin Kettering
Reply With Quote
  #7  
Old September 1st, 2007, 08:07 AM
johnz14's Avatar
johnz14 johnz14 is offline
Senior Member
 
Join Date: Dec 2006
O/S: Windows XP Pro
Location: Australia
Posts: 282
Thanks for the example but now i am having trouble with the program and i'm not sure how to fix it, i've gone through the step into process alot of times and i cannot figure out how to fix the problem. The problem is that when i play the game and then press a square the msgbox which is programmed pops up saying game is a draw when only one box has been picked. I gave programmed the Msgbox to pop up only when all squares are filled up when no X or O match up a line of 3.

If you would like to see the problem pm me and i'll send you the game.
All help appreciated.
Reply With Quote
  #8  
Old September 1st, 2007, 12:11 PM
oracle128's Avatar
oracle128 oracle128 is offline
Α Ω
 
Join Date: Oct 2000
O/S: Windows XP Pro
Location: Melbourne, Australia
Age: 24
Posts: 9,401
Just post the code for checking a win on the forum, in [code][/code] tags.
__________________
Oracle's backup tutorial

"A lot of people say games are addictive. Well, they're addictive in the sense that anything you like doing you repeat endlessly. But no one would say, 'Mr Kasparov, you have a chess problem,' or 'Tiger Woods, you have a golf addiction.'" - Ian Livingstone, Creative Director, Eidos.

"A problem well stated is a problem half solved" - Charles Franklin Kettering
Reply With Quote
  #9  
Old September 2nd, 2007, 05:10 AM
johnz14's Avatar
johnz14 johnz14 is offline
Senior Member
 
Join Date: Dec 2006
O/S: Windows XP Pro
Location: Australia
Posts: 282
Game Code

Ok i'll post the whole game code, atm i am having trouble, when i click a square it instantly goes X or O wins and im not sure how to fix this.

Option Explicit
Dim mStartSquare As Integer, mEndSquare As Integer, mDirection As Integer
Dim mXO(2) As String
Dim mBlank As Integer
Dim mCounter As Integer
Dim mXsInARow As Integer, mOsInARow As Integer
Dim mHumanPlayingAsX As Boolean
Dim mHumanMovedAlready As Boolean, mCompMovedAlready As Boolean
Dim mGameOver As Boolean
Dim mSquareValue(8) As Integer
Dim mRndChoice(8) As Integer
Dim mWin(8) As Integer
Dim mTie As Boolean
Dim mPlayer As String
Dim mCPU As String
Dim mEmpty As Boolean

Private Sub cmdStart_Click()
mCPU = imgO.Picture
mPlayer = imgX.Picture

If mHumanMovedAlready = True Then
Cls
Call ComputerTurn
Else
mHumanMovedAlready = False
End If
End Sub

Private Sub imgBox_Click(Index As Integer)
Dim mLoop As Integer
If imgBox(Index).Picture <> imgX.Picture And imgBox(Index).Picture <> imgO.Picture Then
mEmpty = True
If mEmpty = True Then
imgBox(Index).Picture = imgX.Picture
End If
Call CheckForWin

If mGameOver = False Then
Call ComputerTurn
For mLoop = 0 To 8
If imgBox(mLoop).Picture <> imgO.Picture And imgBox(mLoop).Picture <> imgX.Picture Then GoTo SkipTieCheck
Next mLoop
Call CheckForTieGame
SkipTieCheck:
End If
Else
MsgBox "Square has already been occupied", vbOKOnly, "Move cannot be made"
End If
End Sub

Private Sub mnuExit_Click()
End
End Sub

Private Sub mnuReset_Click()
mnuReset.Enabled = False
Form_Load
End Sub

Private Sub XWins()
Call GameOver
MsgBox ("X wins!")
' 3 Lines of X
' Horizontal 0,1,2
If imgBox(0).Picture And imgBox(1).Picture And imgBox(2).Picture = imgX.Picture Then
imgBox(0).Picture = imgH.Picture
imgBox(1).Picture = imgH.Picture
imgBox(2).Picture = imgH.Picture
End If
' 3,4,5
If imgBox(3).Picture And imgBox(4).Picture And imgBox(5).Picture = imgX.Picture Then
imgBox(3).Picture = imgH.Picture
imgBox(4).Picture = imgH.Picture
imgBox(5).Picture = imgH.Picture
End If
' 6,7,8
If imgBox(6).Picture And imgBox(7).Picture And imgBox(8).Picture = imgX.Picture Then
imgBox(6).Picture = imgH.Picture
imgBox(7).Picture = imgH.Picture
imgBox(8).Picture = imgH.Picture
End If

' Vertical 0,3,6
If imgBox(0).Picture And imgBox(3).Picture And imgBox(6).Picture = imgX.Picture Then
imgBox(0).Picture = imgV.Picture
imgBox(3).Picture = imgV.Picture
imgBox(6).Picture = imgV.Picture
End If
' 1,4,7
If imgBox(1).Picture And imgBox(4).Picture And imgBox(7).Picture = imgX.Picture Then
imgBox(1).Picture = imgV.Picture
imgBox(4).Picture = imgV.Picture
imgBox(7).Picture = imgV.Picture
End If
' 3,5,8
If imgBox(3).Picture And imgBox(5).Picture And imgBox(8).Picture = imgX.Picture Then
imgBox(3).Picture = imgV.Picture
imgBox(5).Picture = imgV.Picture
imgBox(8).Picture = imgV.Picture
End If

' Diagonal Left 0,4,8
If imgBox(0).Picture And imgBox(4).Picture And imgBox(8).Picture = imgX.Picture Then
imgBox(0).Picture = imgDL.Picture
imgBox(4).Picture = imgDL.Picture
imgBox(8).Picture = imgDL.Picture
End If

' Diagonal Right 2,4,6
If imgBox(2).Picture And imgBox(4).Picture And imgBox(6).Picture = imgX.Picture Then
imgBox(2).Picture = imgDR.Picture
imgBox(4).Picture = imgDR.Picture
imgBox(6).Picture = imgDR.Picture
End If
End Sub


Private Sub OWins()
Call GameIsOver
MsgBox ("O Wins!")

' 3 lines of O
' Horizontal 0,1,2
If imgBox(0).Picture And imgBox(1).Picture And imgBox(2).Picture = imgO.Picture Then
imgBox(0).Picture = imgH.Picture
imgBox(1).Picture = imgH.Picture
imgBox(2).Picture = imgH.Picture
End If
' 3,4,5
If imgBox(3).Picture And imgBox(4).Picture And imgBox(5).Picture = imgO.Picture Then
imgBox(3).Picture = imgH.Picture
imgBox(4).Picture = imgH.Picture
imgBox(5).Picture = imgH.Picture
End If
' 6,7,8
If imgBox(6).Picture And imgBox(7).Picture And imgBox(8).Picture = imgO.Picture Then
imgBox(6).Picture = imgH.Picture
imgBox(7).Picture = imgH.Picture
imgBox(8).Picture = imgH.Picture
End If

' Vertical 0,3,6
If imgBox(0).Picture And imgBox(3).Picture And imgBox(6).Picture = imgO.Picture Then
imgBox(0).Picture = imgV.Picture
imgBox(3).Picture = imgV.Picture
imgBox(6).Picture = imgV.Picture
End If
' 1,4,7
If imgBox(1).Picture And imgBox(4).Picture And imgBox(7).Picture = imgO.Picture Then
imgBox(1).Picture = imgV.Picture
imgBox(4).Picture = imgV.Picture
imgBox(7).Picture = imgV.Picture
End If
' 3,5,8
If imgBox(3).Picture And imgBox(5).Picture And imgBox(8).Picture = imgO.Picture Then
imgBox(3).Picture = imgV.Picture
imgBox(5).Picture = imgV.Picture
imgBox(8).Picture = imgV.Picture
End If

' Diagonal Left 0,4,8
If imgBox(0).Picture And imgBox(4).Picture And imgBox(8).Picture = imgO.Picture Then
imgBox(0).Picture = imgDL.Picture
imgBox(4).Picture = imgDL.Picture
imgBox(8).Picture = imgDL.Picture
End If

' Diagonal Right 2,4,6
If imgBox(2).Picture And imgBox(4).Picture And imgBox(6).Picture = imgO.Picture Then
imgBox(2).Picture = imgDR.Picture
imgBox(4).Picture = imgDR.Picture
imgBox(6).Picture = imgDR.Picture
End If
End Sub


Private Sub Draw()
mTie = True
Call GameOver
MsgBox ("Game is a draw!")
End Sub


Private Sub GameOver()
mGameOver = True
lblText.Caption = "Play Again, Press Start If So?"
Call cmdStart_Click
End Sub

Private Sub CheckForTieGame()
Dim mIndex As Integer
Dim mSpace As Integer

For mIndex = 0 To 8
If imgBox(mIndex).Picture = imgBlank.Picture Then mSpace = mSpace + 1
Next mIndex

If mSpace = 0 Then
Call Draw
End If
End Sub

Private Sub CompSquareSelection()
Dim mIndex As Integer
Dim mHighVal As Integer
Dim mCounter As Integer
Dim mFinalChoice As Integer

mCounter = 0
mHighVal = 0
For mIndex = 0 To 8
If mSquareValue(mIndex) = mHighVal Then
mRndChoice(mCounter) = mIndex
mCounter = mCounter + 1
End If

If mSquareValue(mIndex) > mHighVal Then
mHighVal = mSquareValue(mIndex)

For mCounter = 1 To 8
mRndChoice(mCounter) = 0
Next mCounter
mRndChoice(0) = mIndex
mCounter = 1
End If

Next mIndex

mIndex = Int(Rnd * mCounter)
imgBox(mRndChoice(mIndex)).Picture = imgO.Picture
mHumanMovedAlready = False
End Sub

Private Sub CheckForWin()
' 3 lines of X
' Horizontal 0,1,2
If imgBox(0).Picture And imgBox(1).Picture And imgBox(2).Picture = imgX.Picture Then
Call XWins
End If
' 3,4,5
If imgBox(3).Picture And imgBox(4).Picture And imgBox(5).Picture = imgX.Picture Then
Call XWins
End If
' 6,7,8
If imgBox(6).Picture And imgBox(7).Picture And imgBox(8).Picture = imgX.Picture Then
Call XWins
End If

' Vertical 0,3,6
If imgBox(0).Picture And imgBox(3).Picture And imgBox(6).Picture = imgX.Picture Then
Call XWins
End If
' 1,4,7
If imgBox(1).Picture And imgBox(4).Picture And imgBox(7).Picture = imgX.Picture Then
Call XWins
End If
' 3,5,8
If imgBox(3).Picture And imgBox(5).Picture And imgBox(8).Picture = imgX.Picture Then
Call XWins
End If

' Diagonal Left 0,4,8
If imgBox(0).Picture And imgBox(4).Picture And imgBox(8).Picture = imgX.Picture Then
Call XWins
End If

' Diagonal Right 2,4,6
If imgBox(2).Picture And imgBox(4).Picture And imgBox(6).Picture = imgX.Picture Then
Call XWins
End If

' 3 lines of O
' Horizontal 0,1,2
If imgBox(0).Picture And imgBox(1).Picture And imgBox(2).Picture = imgO.Picture Then
Call OWins
End If
' 3,4,5
If imgBox(3).Picture And imgBox(4).Picture And imgBox(5).Picture = imgO.Picture Then
Call OWins
End If
' 6,7,8
If imgBox(6).Picture And imgBox(7).Picture And imgBox(8).Picture = imgO.Picture Then
Call OWins
End If

' Vertical 0,3,6
If imgBox(0).Picture And imgBox(3).Picture And imgBox(6).Picture = imgO.Picture Then
Call OWins
End If
' 1,4,7
If imgBox(1).Picture And imgBox(4).Picture And imgBox(7).Picture = imgO.Picture Then
Call OWins
End If
' 3,5,8
If imgBox(3).Picture And imgBox(5).Picture And imgBox(8).Picture = imgO.Picture Then
Call OWins
End If

' Diagonal Left 0,4,8
If imgBox(0).Picture And imgBox(4).Picture And imgBox(8).Picture = imgO.Picture Then
Call OWins
End If

' Diagonal Right 2,4,6
If imgBox(2).Picture And imgBox(4).Picture And imgBox(6).Picture = imgO.Picture Then
Call OWins
End If
End Sub

Private Sub ComputerTurn()
Dim mLoop As Integer

If mGameOver = False Then
Call CompAI
Call CompSquareSelection
Call CheckForWin
For mLoop = 0 To 8
If imgBox(mLoop).Picture <> imgO.Picture And imgBox(mLoop).Picture <> imgX.Picture Then GoTo SkipTieCheck
Next mLoop
Call CheckForTieGame
SkipTieCheck:
End If
End Sub

Private Sub CompAI()

Dim mXOSquare As Integer
Dim mIndex As Integer
Dim mSpace As Integer

' vertical Row 0,1,2
If imgBox(0).Picture = imgX.Picture And imgBox(1).Picture = imgX.Picture Then
imgO.Picture = imgBox(2).Picture
End If
If imgBox(0).Picture = imgX.Picture And imgBox(2).Picture = imgX.Picture Then
imgO.Picture = imgBox(1).Picture
End If
If imgBox(1).Picture = imgX.Picture And imgBox(2).Picture = imgX.Picture Then
imgO.Picture = imgBox(0).Picture
End If
' Row 3,4,5
If imgBox(3).Picture = imgX.Picture And imgBox(4).Picture = imgX.Picture Then
imgO.Picture = imgBox(5).Picture
End If
If imgBox(4).Picture = imgX.Picture And imgBox(5).Picture = imgX.Picture Then
imgO.Picture = imgBox(6).Picture
End If
If imgBox(3).Picture = imgX.Picture And imgBox(5).Picture = imgX.Picture Then
imgO.Picture = imgBox(4).Picture
End If
' Row 6,7,8
If imgBox(6).Picture = imgX.Picture And imgBox(7).Picture = imgX.Picture Then
imgO.Picture = imgBox(8).Picture
End If
If imgBox(6).Picture = imgX.Picture And imgBox(8).Picture = imgX.Picture Then
imgO.Picture = imgBox(7).Picture
End If
If imgBox(7).Picture = imgX.Picture And imgBox(8).Picture = imgX.Picture Then
imgO.Picture = imgBox(6).Picture
End If

' horizontal Row 0,3,6
If imgBox(0).Picture = imgX.Picture And imgBox(3).Picture = imgX.Picture Then
imgO.Picture = imgBox(6).Picture
End If
If imgBox(3).Picture = imgX.Picture And imgBox(6).Picture = imgX.Picture Then
imgO.Picture = imgBox(0).Picture
End If
If imgBox(0).Picture = imgX.Picture And imgBox(6).Picture = imgX.Picture Then
imgO.Picture = imgBox(3).Picture
End If
' Row 1,4,7
If imgBox(1).Picture = imgX.Picture And imgBox(4).Picture = imgX.Picture Then
imgO.Picture = imgBox(7).Picture
End If
If imgBox(1).Picture = imgX.Picture And imgBox(7).Picture = imgX.Picture Then
imgO.Picture = imgBox(4).Picture
End If
If imgBox(4).Picture = imgX.Picture And imgBox(7).Picture = imgX.Picture Then
imgO.Picture = imgBox(1).Picture
End If
' Row 2,5,8
If imgBox(2).Picture = imgX.Picture And imgBox(5).Picture = imgX.Picture Then
imgO.Picture = imgBox(8).Picture
End If
If imgBox(2).Picture = imgX.Picture And imgBox(8).Picture = imgX.Picture Then
imgO.Picture = imgBox(5).Picture
End If
If imgBox(5).Picture = imgX.Picture And imgBox(8).Picture = imgX.Picture Then
imgO.Picture = imgBox(2).Picture
End If

' diagonal left
If imgBox(0).Picture = imgX.Picture And imgBox(4).Picture = imgX.Picture Then
imgO.Picture = imgBox(8).Picture
End If
If imgBox(4).Picture = imgX.Picture And imgBox(8).Picture = imgX.Picture Then
imgO.Picture = imgBox(0).Picture
End If
If imgBox(0).Picture = imgX.Picture And imgBox(8).Picture = imgX.Picture Then
imgO.Picture = imgBox(4).Picture
End If

'diagonal right
If imgBox(2).Picture = imgX.Picture And imgBox(4).Picture = imgX.Picture Then
imgO.Picture = imgBox(6).Picture
End If
If imgBox(4).Picture = imgX.Picture And imgBox(6).Picture = imgX.Picture Then
imgO.Picture = imgBox(0).Picture
End If
If imgBox(2).Picture = imgX.Picture And imgBox(6).Picture = imgX.Picture Then
imgO.Picture = imgBox(4).Picture
End If
End If
End Sub
Reply With Quote
  #10  
Old September 2nd, 2007, 12:46 PM
oracle128's Avatar
oracle128 oracle128 is offline
Α Ω
 
Join Date: Oct 2000
O/S: Windows XP Pro
Location: Melbourne, Australia
Age: 24
Posts: 9,401
Code:
Private Sub CheckForWin()
' 3 lines of X
' Horizontal 0,1,2
If imgBox(0).Picture And imgBox(1).Picture And imgBox(2).Picture = imgX.Picture Then
Call XWins
End If
Note the line I highlighted - this If condition will always evaluate to TRUE. Remember how I posted the syntax for an If condition, with Or's:
Code:
If <condition1> Or <condition2> Or <condition3> Then
Now translate that into your code:
Code:
If imgBox(0).Picture And imgBox(1).Picture And imgBox(2).Picture = imgX.Picture Then
You have 3 conditions here, in plain English:
Is imgBox(0).Picture true?
And, is imgBox(1).Picture true?
And, is imgBox(2).Picture equal to imgX.Picture?

The first 2 conditions will always be true. imgBox(0).Picture is always true. imgBox(1).Picture is always true. imgBox(2).Picture = imgX.Picture will only be true if there's an X in it. But since you have each possible combination covered, in both X and O, it's always going to result to a win first move.
__________________
Oracle's backup tutorial

"A lot of people say games are addictive. Well, they're addictive in the sense that anything you like doing you repeat endlessly. But no one would say, 'Mr Kasparov, you have a chess problem,' or 'Tiger Woods, you have a golf addiction.'" - Ian Livingstone, Creative Director, Eidos.

"A problem well stated is a problem half solved" - Charles Franklin Kettering
Reply With Quote
  #11  
Old September 3rd, 2007, 09:16 PM
johnz14's Avatar
johnz14 johnz14 is offline
Senior Member
 
Join Date: Dec 2006
O/S: Windows XP Pro
Location: Australia
Posts: 282
Thanks alot Oracle i was struggling alot on that, but now the coding is going to get complicated because im not really sure what property to use that has a boolean result.

The only one i know of is enabled, i'll try it out and see what happens.
btw thanks again.
Reply With Quote
  #12  
Old September 4th, 2007, 08:24 AM
oracle128's Avatar
oracle128 oracle128 is offline
Α Ω
 
Join Date: Oct 2000
O/S: Windows XP Pro
Location: Melbourne, Australia
Age: 24
Posts: 9,401
Why not try this?
Code:
If imgBox(0).Picture = imgX.Picture And imgBox(1).Picture = imgX.Picture And imgBox(2).Picture = imgX.Picture Then
__________________
Oracle's backup tutorial

"A lot of people say games are addictive. Well, they're addictive in the sense that anything you like doing you repeat endlessly. But no one would say, 'Mr Kasparov, you have a chess problem,' or 'Tiger Woods, you have a golf addiction.'" - Ian Livingstone, Creative Director, Eidos.

"A problem well stated is a problem half solved" - Charles Franklin Kettering
Reply With Quote
  #13  
Old September 4th, 2007, 09:48 PM
johnz14's Avatar
johnz14 johnz14 is offline
Senior Member
 
Join Date: Dec 2006
O/S: Windows XP Pro
Location: Australia
Posts: 282
Could you help me load a help file, i'm not sure how to start the code on the help file.
By the way what format does the help file need to be to load up in Visual Basic 5.0 CCE.
Reply With Quote
  #14  
Old September 5th, 2007, 04:47 AM
oracle128's Avatar
oracle128 oracle128 is offline
Α Ω
 
Join Date: Oct 2000
O/S: Windows XP Pro
Location: Melbourne, Australia
Age: 24
Posts: 9,401
You can make CHM with something like this.
I don't how how VB5 CCE can include a help file, or even if it can since it's meant for ActiveX components. If you have to include a help file you should ask the teacher how to do it.
__________________
Oracle's backup tutorial

"A lot of people say games are addictive. Well, they're addictive in the sense that anything you like doing you repeat endlessly. But no one would say, 'Mr Kasparov, you have a chess problem,' or 'Tiger Woods, you have a golf addiction.'" - Ian Livingstone, Creative Director, Eidos.

"A problem well stated is a problem half solved" - Charles Franklin Kettering
Reply With Quote
  #15  
Old September 7th, 2007, 03:22 AM
johnz14's Avatar
johnz14 johnz14 is offline
Senior Member
 
Join Date: Dec 2006
O/S: Windows XP Pro
Location: Australia
Posts: 282
Oh i've also been struggling with this win bug. When i did a trial on the game it worked perfectly when it was a tie, but when X or O won and there was a spare square left i was still allowed to pick that empty square. Below is evidence of this.
-->


I've tried adding in the code
Code:
If X wins then
lblSq(index).enabled = false
but still doesnt seem to work, and i've also tried
Code:
If X wins then
lblSq(0).enabled and lblSq(1).enabled = false and lblSq(2).enabled = false and lblSq(3).enabled = false and lblSq(4).enabled = false and lblSq(5).enabled = false and lblSq(6).enabled = false and lblSq(7).enabled = false and lblSq(8).enabled = false
But still doesnt fix the problem.

And my code of the whole game is below
Code:
Public mChance As Integer
Public mLineNo As Integer
Dim mCompMove As Integer

Private Function Opening_move()
If lblSq(4).Caption <> "X" Then
    lblSq(4).Caption = "O"
Else
    lblSq(8).Caption = "O"
End If
    mCompMove = mCompMove + 1
End Function
Private Function Perform_Check(mCheck As String)
Dim mIndex As Integer
    For mIndex = 0 To 6 Step 3
        If lblSq(mIndex).Caption = mCheck And lblSq(mIndex + 1).Caption = mCheck And lblSq(mIndex + 2).Caption = "" Then
            lblSq(mIndex + 2).Caption = "O"
            mCompMove = mCompMove + 1
            Exit Function
        End If
        If lblSq(mIndex).Caption = mCheck And lblSq(mIndex + 1).Caption = "" And lblSq(mIndex + 2).Caption = mCheck Then
            lblSq(mIndex + 1).Caption = "O"
            mCompMove = mCompMove + 1
            Exit Function
        End If
        If lblSq(mIndex).Caption = "" And lblSq(mIndex + 1).Caption = mCheck And lblSq(mIndex + 2).Caption = mCheck Then
            lblSq(mIndex + 0).Caption = "O"
            mCompMove = mCompMove + 1
            Exit Function
        End If
    Next mIndex
    For mIndex = 0 To 2                  'checks vertically 3 times 3 coloumns
If lblSq(mIndex).Caption = mCheck And lblSq(mIndex + 3).Caption = mCheck And lblSq(mIndex + 6).Caption = "" Then
    lblSq(mIndex + 6).Caption = "O"
    mCompMove = mCompMove + 1
    Exit Function
End If
If lblSq(mIndex).Caption = mCheck And lblSq(mIndex + 3).Caption = "" And lblSq(mIndex + 6).Caption = mCheck Then
    lblSq(mIndex + 3).Caption = "O"
    mCompMove = mCompMove + 1
    Exit Function
End If
If lblSq(mIndex).Caption = "" And lblSq(mIndex + 3).Caption = mCheck And lblSq(mIndex + 6).Caption = mCheck Then
    lblSq(mIndex + 0).Caption = "O"
    mCompMove = mCompMove + 1
    Exit Function
End If
Next mIndex
'check diagonal from upper right to lower left
If lblSq(2).Caption = ch And lblSq(4).Caption = mCheck And lblSq(6).Caption = "" Then
    lblSq(6).Caption = "O"
    mCompMove = mCompMove + 1
    Exit Function
End If
'check diagonal from upper right to lower left, 2nd condition
If lblSq(2).Caption = "" And lblSq(4).Caption = mCheck And lblSq(6).Caption = mCheck Then
    lblSq(2).Caption = "O"
    mCompMove = mCompMove + 1
    Exit Function
End If
'check diagonal from upper left to lower right
If lblSq(0).Caption = "" And lblSq(4).Caption = mCheck And lblSq(8).Caption = mCheck Then
    lblSq(0).Caption = "O"
    mCompMove = mCompMove + 1
    Exit Function
End If
'check diagonal from lower right to upper left
If lblSq(8).Caption = "" And lblSq(4).Caption = mCheck And lblSq(0).Caption = mCheckh Then
    lblSq(8).Caption = "O"
    mCompMove = mCompMove + 1
    Exit Function
End If

End Function
Private Function Perform_Win_Check(mCheckWin As String)
Dim mIndex As Integer
For mIndex = 0 To 6 Step 3       'horizontal check
    If lblSq(mIndex).Caption = mCheckWin And lblSq(mIndex + 1).Caption = mCheckWin And lblSq(mIndex + 2).Caption = mCheckWin Then
        linLine(mIndex / 3).Visible = True
        mLineNo = mIndex / 3
        If mCheckWin = "O" Then
            MsgBox "Computer Wins, You lose"
        Else
            MsgBox "You win, Computer loses"
        End If
    End If
Next mIndex
For mIndex = 0 To 2              'vertical check
    If lblSq(mIndex).Caption = mCheckWin And lblSq(mIndex + 3).Caption = mCheckWin And lblSq(mIndex + 6).Caption = mCheckWin Then
        linLine(mIndex + 3).Visible = True
        mLineNo = mIndex + 3
        If mCheckWin = "O" Then
            MsgBox "Computer Wins, You lose"
        Else
            MsgBox "You win, Computer loses"
        End If
    End If
Next mIndex
'two diagonal checks
If lblSq(0).Caption = mCheckWin And lblSq(4).Caption = mCheckWin And lblSq(8).Caption = mCheckWin Then
    linLine(6).Visible = True
    mLineNo = 6
    If mCheckWin = "O" Then
        MsgBox "Computer Wins, You lose"
    Else
        MsgBox "You win, Computer loses"
    End If
End If
If lblSq(2).Caption = mCheckWin And lblSq(4).Caption = mCheckWin And lblSq(6).Caption = mCheckWin Then
    linLine(7).Visible = True
    mLineNo = 7
    If mCheckWin = "O" Then
        MsgBox "Computer Wins, You lose"
    Else
        MsgBox "You win, Computer loses"
    End If
End If
End Function

Private Function Second_move()
Perform_Check ("X")
If mCompMove = 1 Then
    If lblSq(5).Caption = "X" And lblSq(7).Caption = "X" Then
        lblSq(8).Caption = "O"
        mCompMove = mCompMove + 1
    End If
    If lblSq(0).Caption = "X" And lblSq(8).Caption = "X" Then
        lblSq(1).Caption = "O"
        mCompMove = mCompMove + 1
    End If
    If lblSq(2).Caption = "X" And lblSq(6).Caption = "X" Then
        lblSq(1).Caption = "O"
        mCompMove = mCompMove + 1
    End If
    If lblSq(0).Caption = "X" And lblSq(4).Caption = "X" Then
        lblSq(6).Caption = "O"
        mCompMove = mCompMove + 1
    End If
    If lblSq(0).Caption = "X" And lblSq(7).Caption = "X" Then
        lblSq(6).Caption = "O"
        mCompMove = mCompMove + 1
    End If
    If lblSq(2).Caption = "X" And lblSq(7).Caption = "X" Then
        lblSq(8).Caption = "O"
        mCompMove = mCompMove + 1
    End If
    If lblSq(5).Caption = "X" And lblSq(6).Caption = "X" Then
        lblSq(8).Caption = "O"
        mCompMove = mCompMove + 1
    End If
    If lblSq(3).Caption = "X" And lblSq(5).Caption = "X" Then
        lblSq(0).Caption = "O"
        mCompMove = mCompMove + 1
    End If
    If lblSq(1).Caption = "X" And lblSq(7).Caption = "X" Then
        lblSq(0).Caption = "O"
        mCompMove = mCompMove + 1
    End If
End If
    If mCompMove = 1 Then
        Seek_Empty_Fill
    End If
End Function
Private Function Seek_Empty_Fill()
Dim mIndex As Integer
For mIndex = 0 To 8
    If lblSq(mIndex).Caption <> "X" And lblSq(mIndex).Caption <> "O" And flag = 0 Then
        lblSq(mIndex).Caption = "O"
        mCompMove = mCompMove + 1
        Exit For
    End If
Next mIndex
End Function
Private Function Third_move()
Perform_Check ("O")
If mCompMove = 2 Then
    Perform_Check ("X")
End If
If lblSq(0).Caption = "O" And lblSq(4).Caption = "O" And lblSq(3).Caption = "" And mCompMove = 2 Then
    lblSq(3).Caption = "O"
    mCompMove = mCompMove + 1
End If
If lblSq(0).Caption = "X" And lblSq(7).Caption = "X" And lblSq(2).Caption = "" And mCompMove = 2 Then
    lblSq(6).Caption = "O"
    mCompMove = mCompMove + 1
End If
If mCompMove = 2 Then
    Seek_Empty_Fill
End If
End Function
Private Function Forth_move()
Perform_Check ("O")
If mCompMove = 3 Then
    Perform_Check ("X")
End If
If mCompMove = 3 Then
    Seek_Empty_Fill
End If
End Function

Private Sub Form_Load()
     frmTicTacToe.Show
     frmLoadMenu.Hide
End Sub

Private Sub lblSq_Click(index As Integer)
If lblSq(index).Caption = "" Then
    lblSq(index).Caption = "X"
    If mCompMove = 4 Then
        MsgBox "Looks like we have a draw"
    End If
    If mCompMove = 3 Then
        Forth_move
    End If
    If mCompMove = 2 Then
        Third_move
    End If
    If mCompMove = 1 Then
        Second_move
    End If
    If mCompMove = 0 Then
        Opening_move
    End If
End If
    Perform_Win_Check ("X")
    Perform_Win_Check ("O")
End Sub

Private Sub mnuExit_Click()
    End
End Sub

Private Sub mnuHelp_Click()
    frmHelp.Show
End Sub

Private Sub mnuNewGame_Click()
Dim mIndex As Integer
mChance = mChance + 1
mCompMove = 0
linLine(mLineNo).Visible = False
lblSq(index).Enabled = True
    For mIndex = 0 To 8
        lblSq(mIndex).Caption = ""
    Next mIndex
        If mChance Mod 2 = 0 Then
            Opening_move
        End If
End Sub

Last edited by johnz14; September 7th, 2007 at 03:32 AM.
Reply With Quote
Reply

Bookmarks

Topic Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 06:26 PM.

[ RSS ]