|
|
|
|
|
|
|
Posted: Tue Oct 12, 2004 10:46 am
Talk about programming languages, programming tips or source codes in this thread.
|
 |
 |
|
|
|
|
|
|
|
|
|
|
|
|
Posted: Tue Oct 12, 2004 3:40 pm
I'm having trouble with my program of tic tac toe. I can't get it to work. It's just iritating me. I don't know what I'm missing.
Here is the code I have typed up:
Option Explicit 'Form-level variable Dim fbSquare1X As Boolean Dim fbSquare2X As Boolean Dim fbSquare3X As Boolean Dim fbSquare4X As Boolean Dim fbSquare5X As Boolean Dim fbSquare6X As Boolean Dim fbSquare7X As Boolean Dim fbSquare8X As Boolean Dim fbSquare9X As Boolean
Dim fbSquare1O As Boolean Dim fbSquare2O As Boolean Dim fbSquare3O As Boolean Dim fbSquare4O As Boolean Dim fbSquare5O As Boolean Dim fbSquare6O As Boolean Dim fbSquare7O As Boolean Dim fbSquare8O As Boolean Dim fbSquare9O As Boolean
Dim fbTie As Boolean Dim fbPlayerWon As Boolean Dim fbComputerWon As Boolean Dim fiTieScore As Integer Dim fiComputerScore As Integer Dim fiPlayerScore As Integer Dim fsWhoseTurnIsIt As String
Private Sub cmdQuit_Click() End End Sub
Private Sub cmdStart_Click()
cmdStart.Enabled = False lblStatus.Caption = "Your Turn."
Enable_Squares
Image1.Picture = imgEmpty.Picture Image2.Picture = imgEmpty.Picture Image3.Picture = imgEmpty.Picture Image4.Picture = imgEmpty.Picture Image5.Picture = imgEmpty.Picture Image6.Picture = imgEmpty.Picture Image7.Picture = imgEmpty.Picture Image8.Picture = imgEmpty.Picture Image9.Picture = imgEmpty.Picture
Timer1.Enabled = True
End Sub
Private Sub Form_Load()
'Set program defaults and initialize variables Timer1.Enabled = False fbTie = False fbPlayerWon = False fbComputerWon = False
fbSquare1X = False fbSquare2X = False fbSquare3X = False fbSquare4X = False fbSquare5X = False fbSquare6X = False fbSquare7X = False fbSquare8X = False fbSquare9X = False
fbSquare1O = False fbSquare2O = False fbSquare3O = False fbSquare4O = False fbSquare5O = False fbSquare6O = False fbSquare7O = False fbSquare8O = False fbSquare9O = False
lblPlayer.Caption = "0" lblComputer.Caption = "0" lblTie.Caption = "0" lblStatus.Caption = "Click start game to play."
Image1.Picture = imgEmpty.Picture Image2.Picture = imgEmpty.Picture Image3.Picture = imgEmpty.Picture Image4.Picture = imgEmpty.Picture Image5.Picture = imgEmpty.Picture Image6.Picture = imgEmpty.Picture Image7.Picture = imgEmpty.Picture Image8.Picture = imgEmpty.Picture Image9.Picture = imgEmpty.Picture
Disable_Squares
'You can toggle this variable for who starts 'the game off: computer or player fsWhoseTurnIsIt = "Player"
End Sub
Private Sub Image1_Click()
If fsWhoseTurnIsIt = "Player" Then If fbSquare1X = False And fbSquare1O = False Then Image1.Picture = imgX.Picture fbSquare1X = True Disable_Squares If Checkforwin = False Then fsWhoseTurnIsIt = "computer" lblStatus.Caption = "Computer is thinking..." End If End If End If
End Sub
Private Sub Image2_Click()
If fsWhoseTurnIsIt = "Player" Then If fbSquare2X = False And fbSquare2O = False Then Image2.Picture = imgX.Picture fbSquare2X = True Disable_Squares If Checkforwin = False Then fsWhoseTurnIsIt = "computer" lblStatus.Caption = "Computer is thinking..." End If End If End If
End Sub
Private Sub Image3_Click()
If fsWhoseTurnIsIt = "Player" Then If fbSquare3X = False And fbSquare3O = False Then Image3.Picture = imgX.Picture fbSquare3X = True Disable_Squares If Checkforwin = False Then fsWhoseTurnIsIt = "computer" lblStatus.Caption = "Computer is thinking..." End If End If End If
End Sub
Private Sub Image4_Click()
If fsWhoseTurnIsIt = "Player" Then If fbSquare4X = False And fbSquare4O = False Then Image4.Picture = imgX.Picture fbSquare4X = True Disable_Squares If Checkforwin = False Then fsWhoseTurnIsIt = "computer" lblStatus.Caption = "Computer is thinking..." End If End If End If
End Sub
Private Sub Image5_Click()
If fsWhoseTurnIsIt = "Player" Then If fbSquare5X = False And fbSquare5O = False Then Image5.Picture = imgX.Picture fbSquare5X = True Disable_Squares If Checkforwin = False Then fsWhoseTurnIsIt = "computer" lblStatus.Caption = "Computer is thinking..." End If End If End If
End Sub
Private Sub Image6_Click()
If fsWhoseTurnIsIt = "Player" Then If fbSquare6X = False And fbSquare6O = False Then Image6.Picture = imgX.Picture fbSquare6X = True Disable_Squares If Checkforwin = False Then fsWhoseTurnIsIt = "computer" lblStatus.Caption = "Computer is thinking..." End If End If End If
End Sub
Private Sub Image7_Click()
If fsWhoseTurnIsIt = "Player" Then If fbSquare7X = False And fbSquare7O = False Then Image7.Picture = imgX.Picture fbSquare7X = True Disable_Squares If Checkforwin = False Then fsWhoseTurnIsIt = "computer" lblStatus.Caption = "Computer is thinking..." End If End If End If
End Sub
Private Sub Image8_Click()
If fsWhoseTurnIsIt = "Player" Then If fbSquare8X = False And fbSquare8O = False Then Image8.Picture = imgX.Picture fbSquare8X = True Disable_Squares If Checkforwin = False Then fsWhoseTurnIsIt = "computer" lblStatus.Caption = "Computer is thinking..." End If End If End If
End Sub
Private Sub Image9_Click()
If fsWhoseTurnIsIt = "Player" Then If fbSquare9X = False And fbSquare9O = False Then Image9.Picture = imgX.Picture fbSquare9X = True Disable_Squares If Checkforwin = False Then fsWhoseTurnIsIt = "computer" lblStatus.Caption = "Computer is thinking..." End If End If End If
End Sub
Private Sub Timer1_Timer()
'GAME INTELLIGENCE If fsWhoseTurnIsIt = "computer" Then
'Computer is playing a defensive role by looking for potential 'winning combinations (by the player). 'There are a total of 8 possible winning combinations, but there 'are a total of 24 possible combinations prior to a player winning. 'So a player has a chance to win, I only test for 12 scenarios, 'leaving the rest up to chance (the DEFAULT SECTION) If (fbSquare1X = True And fbSquare3X = True) And _ (fbSquare2X = False And fbSquare2O = False) Then Image2.Picture = imgO.Picture fbSquare2O = True If Checkforwin = False Then fsWhoseTurnIsIt = "Player" lblStatus.Caption = "Your Turn." Enable_Squares End If ElseIf (fbSquare7X = True And fbSquare9X = True) And _ (fbSquare8X = False And fbSquare8O = False) Then Image8.Picture = imgO.Picture fbSquare2O = True If Checkforwin = False Then fsWhoseTurnIsIt = "Player" lblStatus.Caption = "Your Turn." Enable_Squares End If ElseIf (fbSquare4X = True And fbSquare5X = True) And _ (fbSquare6X = False And fbSquare6O = False) Then Image6.Picture = imgO.Picture fbSquare6O = True If Checkforwin = False Then fsWhoseTurnIsIt = "Player" lblStatus.Caption = "Your Turn." Enable_Squares End If ElseIf (fbSquare5X = True And fbSquare6X = True) And _ (fbSquare4X = False And fbSquare4O = False) Then Image4.Picture = imgO.Picture fbSquare4O = True If Checkforwin = False Then fsWhoseTurnIsIt = "Player" lblStatus.Caption = "Your Turn." Enable_Squares End If ElseIf (fbSquare8X = True And fbSquare9X = True) And _ (fbSquare7X = False And fbSquare7O = False) Then Image7.Picture = imgO.Picture fbSquare7O = True If Checkforwin = False Then fsWhoseTurnIsIt = "Player" lblStatus.Caption = "Your Turn." Enable_Squares End If ElseIf (fbSquare2X = True And fbSquare8X = True) And _ (fbSquare5X = False And fbSquare5O = False) Then Image5.Picture = imgO.Picture fbSquare5O = True If Checkforwin = False Then fsWhoseTurnIsIt = "Player" lblStatus.Caption = "Your Turn." Enable_Squares End If ElseIf (fbSquare1X = True And fbSquare4X = True) And _ (fbSquare7X = False And fbSquare7O = False) Then Image7.Picture = imgO.Picture fbSquare7O = True If Checkforwin = False Then fsWhoseTurnIsIt = "Player" lblStatus.Caption = "Your Turn." Enable_Squares End If ElseIf (fbSquare3X = True And fbSquare6X = True) And _ (fbSquare9X = False And fbSquare9O = False) Then Image9.Picture = imgO.Picture fbSquare9O = True If Checkforwin = False Then fsWhoseTurnIsIt = "Player" lblStatus.Caption = "Your Turn." Enable_Squares End If ElseIf (fbSquare6X = True And fbSquare9X = True) And _ (fbSquare3X = False And fbSquare3O = False) Then Image3.Picture = imgO.Picture fbSquare3O = True If Checkforwin = False Then fsWhoseTurnIsIt = "Player" lblStatus.Caption = "Your Turn." Enable_Squares End If ElseIf (fbSquare1X = True And fbSquare5X = True) And _ (fbSquare9X = False And fbSquare9O = False) Then Image9.Picture = imgO.Picture fbSquare9O = True If Checkforwin = False Then fsWhoseTurnIsIt = "Player" lblStatus.Caption = "Your Turn." Enable_Squares End If ElseIf (fbSquare5X = True And fbSquare9X = True) And _ (fbSquare1X = False And fbSquare1O = False) Then Image1.Picture = imgO.Picture fbSquare1O = True If Checkforwin = False Then fsWhoseTurnIsIt = "Player" lblStatus.Caption = "Your Turn." Enable_Squares End If ElseIf (fbSquare7X = True And fbSquare5X = True) And _ (fbSquare3X = False And fbSquare3O = False) Then Image3.Picture = imgO.Picture fbSquare3O = True If Checkforwin = False Then fsWhoseTurnIsIt = "Player" lblStatus.Caption = "Your Turn." Enable_Squares End If End If End If 'End fsWhoseTurnIsIt check
If fsWhoseTurnIsIt = "computer" Then
'DEFAULT SECTION 'If the computer has made it this far and there were no possible 'matches, then just select the first empty box it comes across. 'Even though I use this code for testing the program, I'm going to 'leave it in because I'm not testing for all defensive scenarios. If fbSquare1X = False And fbSquare1O = False Then Image1.Picture = imgO.Picture fbSquare1O = True If Checkforwin = False Then fsWhoseTurnIsIt = "Player" lblStatus.Caption = "Your Turn." Enable_Squares End If ElseIf fbSquare2X = False And fbSquare2O = False Then Image2.Picture = imgO.Picture fbSquare2O = True If Checkforwin = False Then fsWhoseTurnIsIt = "Player" lblStatus.Caption = "Your Turn." Enable_Squares End If ElseIf fbSquare3X = False And fbSquare3O = False Then Image3.Picture = imgO.Picture fbSquare3O = True If Checkforwin = False Then fsWhoseTurnIsIt = "Player" lblStatus.Caption = "Your Turn." Enable_Squares End If ElseIf fbSquare4X = False And fbSquare4O = False Then Image4.Picture = imgO.Picture fbSquare4O = True If Checkforwin = False Then fsWhoseTurnIsIt = "Player" lblStatus.Caption = "Your Turn." Enable_Squares End If ElseIf fbSquare5X = False And fbSquare5O = False Then Image5.Picture = imgO.Picture fbSquare5O = True If Checkforwin = False Then fsWhoseTurnIsIt = "Player" lblStatus.Caption = "Your Turn." Enable_Squares End If ElseIf fbSquare6X = False And fbSquare6O = False Then Image6.Picture = imgO.Picture fbSquare6O = True If Checkforwin = False Then fsWhoseTurnIsIt = "Player" lblStatus.Caption = "Your Turn." Enable_Squares End If ElseIf fbSquare7X = False And fbSquare7O = False Then Image7.Picture = imgO.Picture fbSquare7O = True If Checkforwin = False Then fsWhoseTurnIsIt = "Player" lblStatus.Caption = "Your Turn." Enable_Squares End If ElseIf fbSquare8X = False And fbSquare8O = False Then Image8.Picture = imgO.Picture fbSquare8O = True If Checkforwin = False Then fsWhoseTurnIsIt = "Player" lblStatus.Caption = "Your Turn." Enable_Squares End If ElseIf fbSquare9X = False And fbSquare9O = False Then Image9.Picture = imgO.Picture fbSquare9O = True If Checkforwin = False Then fsWhoseTurnIsIt = "Player" lblStatus.Caption = "Your Turn." Enable_Squares End If End If End If 'end fsWhoseTurnIsIt check
End Sub
Public Function Checkforwin() Dim liSquareOccupied As Integer 'First, check for a win by the player If fbSquare1X = True And fbSquare2X = True And fbSquare3X = _ True Then 'Across fbPlayerWon = True ElseIf fbSquare4X = True And fbSquare5X = True And fbSquare6X = _ True Then 'Across fbPlayerWon = True ElseIf fbSquare7X = True And fbSquare8X = True And fbSquare9X = _ True Then 'Across fbPlayerWon = True ElseIf fbSquare1X = True And fbSquare4X = True And fbSquare7X = _ True Then 'Up and down fbPlayerWon = True ElseIf fbSquare2X = True And fbSquare5X = True And fbSquare8X = _ True Then 'Up and down fbPlayerWon = True ElseIf fbSquare3X = True And fbSquare6X = True And fbSquare9X = _ True Then 'Up and down fbPlayerWon = True ElseIf fbSquare1X = True And fbSquare5X = True And fbSquare9X = _ True Then 'Diagonol fbPlayerWon = True ElseIf fbSquare3X = True And fbSquare5X = True And fbSquare7X = _ True Then 'Diagonol fbPlayerWon = True End If
'Next, check for a win by the computer If fbSquare1O = True And fbSquare2O = True And fbSquare3O = _ True Then 'Across fbComputerWon = True ElseIf fbSquare4O = True And fbSquare5O = True And fbSquare6O = _ True Then 'Across fbComputerWon = True ElseIf fbSquare7O = True And fbSquare8O = True And fbSquare9O = _ True Then 'Across fbComputerWon = True ElseIf fbSquare1O = True And fbSquare4O = True And fbSquare7O = _ True Then 'Up and down fbComputerWon = True ElseIf fbSquare2O = True And fbSquare5O = True And fbSquare8O = _ True Then 'Up and down fbComputerWon = True ElseIf fbSquare3O = True And fbSquare6O = True And fbSquare9O = _ True Then 'Up and down fbComputerWon = True ElseIf fbSquare1O = True And fbSquare5O = True And fbSquare9O = _ True Then 'Diagonol fbComputerWon = True ElseIf fbSquare3O = True And fbSquare5O = True And fbSquare7O = _ True Then 'Diagonol fbComputerWon = True End If
'And last, check for a tie game If fbComputerWon = False And fbPlayerWon = False Then If fbSquare1X = True Or fbSquare1O = True Then liSquaresOccupied = liSquaresOccupied + 1 End If If fbSquare2X = True Or fbSquare2O = True Then liSquaresOccupied = liSquaresOccupied + 1 End If If fbSquare3X = True Or fbSquare3O = True Then liSquaresOccupied = liSquaresOccupied + 1 End If If fbSquare4X = True Or fbSquare4O = True Then liSquaresOccupied = liSquaresOccupied + 1 End If If fbSquare5X = True Or fbSquare5O = True Then liSquaresOccupied = liSquaresOccupied + 1 End If If fbSquare6X = True Or fbSquare6O = True Then liSquaresOccupied = liSquaresOccupied + 1 End If If fbSquare7X = True Or fbSquare7O = True Then liSquaresOccupied = liSquaresOccupied + 1 End If If fbSquare8X = True Or fbSquare8O = True Then liSquaresOccupied = liSquaresOccupied + 1 End If If fbSquare9X = True Or fbSquare9O = True Then liSquaresOccupied = liSquaresOccupied + 1 End If 'If liSquaresOccupied = 9 (all squares are occupied) and the 'computer nor the player has won, then we have a tie game If liSquaresOccupied = 9 Then fbTie = True End If End If
'If a win or tie has occured, then increment a score. 'Turn off the timer and exit this routine If fbTie = True Or fbPlayerWon = True Or fbComputerWon = True Then Checkforwin = True If fbTie = True Then fiTieScore = fiTieScore + 1 lblTie.Caption = fiTieScore lblStatus.Caption = "Tie Game, click start game to play." fsWhoseTurnIsIt = "Player" ElseIf fbPlayerWon = True Then fiPlayerScore = fiPlayerScore + 1 lblPlayer.Caption = fiPlayerScore lblStatus.Caption = "You won, click start game to play." fsWhoseTurnIsIt = "Player" ElseIf fbComputerWon = True Then fiComputerScore = fiComputerScore + 1 lblComputer.Caption = fiComputerScore lblStatus.Caption = "Computer won, click start game to play." fsWhoseTurnIsIt = "Player" End If
cmdStart.Enabled = Ture
fbTie = False fbPlayerWon = False fbComputerWon = False fbSquare1X = False fbSquare2X = False fbSquare3X = False fbSquare4X = False fbSquare5X = False fbSquare6X = False fbSquare7X = False fbSquare8X = False fbSquare9X = False
fbSquare1O = False fbSquare2O = False fbSquare3O = False fbSquare4O = False fbSquare5O = False fbSquare6O = False fbSquare7O = False fbSquare8O = False fbSquare9O = False
Timer1.Enabled = False Exit Function Else Checkforwin = False End If
End Function
Public Sub Disable_Squares()
Image1.Enabled = False Image2.Enabled = False Image3.Enabled = False Image4.Enabled = False Image5.Enabled = False Image6.Enabled = False Image7.Enabled = False Image8.Enabled = False Image9.Enabled = False
End Sub
Public Sub Enable_Squares()
Image1.Enabled = True Image2.Enabled = True Image3.Enabled = True Image4.Enabled = True Image5.Enabled = True Image6.Enabled = True Image7.Enabled = True Image8.Enabled = True Image9.Enabled = True
End Sub
|
 |
 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Posted: Wed Oct 13, 2004 9:44 am
Hmmm. I haven't done this before. But I'll copy the code and try it out.
|
 |
 |
|
|
|
|
|
|
|
|
|
|
|
|
Posted: Wed Oct 13, 2004 11:20 am
Ok. Thanks. If you find out what's wrong with my codding that'll be helpful.
|
 |
 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Posted: Wed Oct 13, 2004 11:25 am
I_am_void Ok. Thanks. If you find out what's wrong with my codding that'll be helpful. Hmmm. It appears your programming style is very different from mine. sweatdrop
|
 |
 |
|
|
|
|
|
|
|
|
|
|
|
|
Posted: Thu Oct 14, 2004 6:18 pm
takumi64x I_am_void Ok. Thanks. If you find out what's wrong with my codding that'll be helpful. Hmmm. It appears your programming style is very different from mine. sweatdrop Ahh. Darn. I just can't figure out what I'm missing or doing wrong. I checked my code and it should have worked.
|
 |
 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Posted: Fri Oct 15, 2004 11:07 pm
Void, do you have any VB6 books with you? Like VB6 Complete?
|
 |
 |
|
|
|
|
|
|
|
|
|
|
|
|
Posted: Sat Oct 16, 2004 12:24 am
If anyone needs help in VB6 database programming, just let me know. 3nodding
|
 |
 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Posted: Sat Oct 16, 2004 10:55 pm
takumi64x Void, do you have any VB6 books with you? Like VB6 Complete? I have 'VB for the absolute beginner' right now. When I get paid I'm going to get another VB book.
|
 |
 |
|
|
|
|
|
|
|
|
|
|
|
|
Posted: Sat Oct 16, 2004 11:42 pm
I_am_void takumi64x Void, do you have any VB6 books with you? Like VB6 Complete? I have 'VB for the absolute beginner' right now. When I get paid I'm going to get another VB book. I've never seen that book before. Oh, well. There are so many VB6 books out there. Maybe the next thing I should get is VB.Net.
|
 |
 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Posted: Sun Oct 17, 2004 12:28 pm
takumi64x I_am_void takumi64x Void, do you have any VB6 books with you? Like VB6 Complete? I have 'VB for the absolute beginner' right now. When I get paid I'm going to get another VB book. I've never seen that book before. Oh, well. There are so many VB6 books out there. Maybe the next thing I should get is VB.Net. I want to get that. Hopefully I can get it when I get paid.
|
 |
 |
|
|
|
|
|
|
|
|
|
|
|
|
Posted: Tue Oct 19, 2004 12:34 pm
I still have a lot to learn before getting a job. xp
|
 |
 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Posted: Tue Oct 19, 2004 7:50 pm
takumi64x I still have a lot to learn before getting a job. xp I have a job, but it's only two paper routes and the landscaping bussiness my step father has started.
|
 |
 |
|
|
|
|
|
|
|
|
|
|
|
|
Posted: Wed Oct 20, 2004 4:02 am
I_am_void takumi64x I still have a lot to learn before getting a job. xp I have a job, but it's only two paper routes and the landscaping bussiness my step father has started. You're lucky. sad
|
 |
 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Posted: Wed Oct 20, 2004 6:02 pm
takumi64x I_am_void takumi64x I still have a lot to learn before getting a job. xp I have a job, but it's only two paper routes and the landscaping bussiness my step father has started. You're lucky. sad The paper route job is a pain right now since it's starting to rain alot and I have to get up at 1am for work.
|
 |
 |
|
|
|
|
|
|
|
|
 |
|
|