Find all our projects in development below.
All source code is GNU General Public License (GPL)
Browsing TicTac.frm (20.90 KB)
VERSION 5.00
Begin VB.Form TicTacToeForm
BorderStyle = 1 'Fixed Single
Caption = "MindPower Tic Tac Toe - Game 0"
ClientHeight = 2805
ClientLeft = 1200
ClientTop = 1785
ClientWidth = 5790
ForeColor = &H80000008&
Icon = "TicTac.frx":0000
LinkTopic = "Form1"
MaxButton = 0 'False
PaletteMode = 1 'UseZOrder
ScaleHeight = 2805
ScaleWidth = 5790
StartUpPosition = 2 'CenterScreen
Begin VB.Frame Frame2
Caption = "Status"
Height = 855
Left = 2880
TabIndex = 14
Top = 1200
Width = 2775
Begin VB.Label Msg
AutoSize = -1 'True
Caption = "Your Turn."
Height = 195
Left = 120
TabIndex = 15
Top = 360
Width = 750
End
End
Begin VB.CommandButton Command2
Caption = "E&xit"
Height = 375
Left = 4320
TabIndex = 1
Top = 2280
Width = 1335
End
Begin VB.CommandButton Command1
Caption = "&New Game"
Height = 375
Left = 2880
TabIndex = 0
Top = 2280
Width = 1335
End
Begin VB.Frame Frame1
Caption = "Scores"
Height = 1095
Left = 2880
TabIndex = 11
Top = 0
Width = 2775
Begin VB.Label Label2
AutoSize = -1 'True
Caption = "Computer (O): 0"
Height = 195
Left = 120
TabIndex = 13
Top = 600
Width = 1110
End
Begin VB.Label Label1
AutoSize = -1 'True
Caption = "Human (X): 0"
Height = 195
Left = 120
TabIndex = 12
Top = 360
Width = 930
End
End
Begin VB.Line X2
BorderWidth = 3
Index = 9
Visible = 0 'False
X1 = 1920
X2 = 2520
Y1 = 1920
Y2 = 2520
End
Begin VB.Line X1
BorderWidth = 3
Index = 9
Visible = 0 'False
X1 = 2520
X2 = 1920
Y1 = 1920
Y2 = 2520
End
Begin VB.Shape O
BorderWidth = 4
Height = 615
Index = 9
Left = 1920
Shape = 3 'Circle
Top = 1920
Visible = 0 'False
Width = 615
End
Begin VB.Shape O
BorderWidth = 4
Height = 615
Index = 8
Left = 1080
Shape = 3 'Circle
Top = 1920
Visible = 0 'False
Width = 615
End
Begin VB.Shape O
BorderWidth = 4
Height = 615
Index = 7
Left = 240
Shape = 3 'Circle
Top = 1920
Visible = 0 'False
Width = 615
End
Begin VB.Shape O
BorderWidth = 4
Height = 615
Index = 6
Left = 1920
Shape = 3 'Circle
Top = 1080
Visible = 0 'False
Width = 615
End
Begin VB.Shape O
BorderWidth = 4
Height = 615
Index = 5
Left = 1080
Shape = 3 'Circle
Top = 1080
Visible = 0 'False
Width = 615
End
Begin VB.Shape O
BorderWidth = 4
Height = 615
Index = 4
Left = 240
Shape = 3 'Circle
Top = 1080
Visible = 0 'False
Width = 615
End
Begin VB.Shape O
BorderWidth = 4
Height = 615
Index = 3
Left = 1920
Shape = 3 'Circle
Top = 240
Visible = 0 'False
Width = 615
End
Begin VB.Shape O
BorderWidth = 4
Height = 615
Index = 2
Left = 1080
Shape = 3 'Circle
Top = 240
Visible = 0 'False
Width = 615
End
Begin VB.Line X1
BorderWidth = 3
Index = 8
Visible = 0 'False
X1 = 1680
X2 = 1080
Y1 = 1920
Y2 = 2520
End
Begin VB.Line X2
BorderWidth = 3
Index = 8
Visible = 0 'False
X1 = 1080
X2 = 1680
Y1 = 1920
Y2 = 2520
End
Begin VB.Line X1
BorderWidth = 3
Index = 7
Visible = 0 'False
X1 = 840
X2 = 240
Y1 = 1920
Y2 = 2520
End
Begin VB.Line X2
BorderWidth = 3
Index = 7
Visible = 0 'False
X1 = 240
X2 = 840
Y1 = 1920
Y2 = 2520
End
Begin VB.Line X1
BorderWidth = 3
Index = 6
Visible = 0 'False
X1 = 2520
X2 = 1920
Y1 = 1080
Y2 = 1680
End
Begin VB.Line X2
BorderWidth = 3
Index = 6
Visible = 0 'False
X1 = 1920
X2 = 2520
Y1 = 1080
Y2 = 1680
End
Begin VB.Line X1
BorderWidth = 3
Index = 5
Visible = 0 'False
X1 = 1680
X2 = 1080
Y1 = 1080
Y2 = 1680
End
Begin VB.Line X2
BorderWidth = 3
Index = 5
Visible = 0 'False
X1 = 1080
X2 = 1680
Y1 = 1080
Y2 = 1680
End
Begin VB.Line X1
BorderWidth = 3
Index = 4
Visible = 0 'False
X1 = 840
X2 = 240
Y1 = 1080
Y2 = 1680
End
Begin VB.Line X2
BorderWidth = 3
Index = 4
Visible = 0 'False
X1 = 240
X2 = 840
Y1 = 1080
Y2 = 1680
End
Begin VB.Line X1
BorderWidth = 3
Index = 3
Visible = 0 'False
X1 = 2520
X2 = 1920
Y1 = 240
Y2 = 840
End
Begin VB.Line X2
BorderWidth = 3
Index = 3
Visible = 0 'False
X1 = 1920
X2 = 2520
Y1 = 240
Y2 = 840
End
Begin VB.Line X1
BorderWidth = 3
Index = 2
Visible = 0 'False
X1 = 1680
X2 = 1080
Y1 = 240
Y2 = 840
End
Begin VB.Line X2
BorderWidth = 3
Index = 2
Visible = 0 'False
X1 = 1065
X2 = 1665
Y1 = 255
Y2 = 855
End
Begin VB.Line X1
BorderWidth = 3
Index = 1
Visible = 0 'False
X1 = 840
X2 = 240
Y1 = 240
Y2 = 840
End
Begin VB.Line X2
BorderWidth = 3
Index = 1
Visible = 0 'False
X1 = 240
X2 = 840
Y1 = 240
Y2 = 840
End
Begin VB.Shape O
BorderWidth = 4
Height = 615
Index = 1
Left = 240
Shape = 3 'Circle
Top = 240
Visible = 0 'False
Width = 615
End
Begin VB.Label Square
BorderStyle = 1 'Fixed Single
BeginProperty Font
Name = "MS Sans Serif"
Size = 8.25
Charset = 0
Weight = 700
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 855
Index = 1
Left = 120
TabIndex = 4
Top = 135
Width = 855
End
Begin VB.Label Square
BorderStyle = 1 'Fixed Single
BeginProperty Font
Name = "MS Sans Serif"
Size = 8.25
Charset = 0
Weight = 700
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 855
Index = 4
Left = 120
TabIndex = 7
Top = 960
Width = 855
End
Begin VB.Label Square
BorderStyle = 1 'Fixed Single
BeginProperty Font
Name = "MS Sans Serif"
Size = 8.25
Charset = 0
Weight = 700
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 855
Index = 3
Left = 1800
TabIndex = 6
Top = 135
Width = 855
End
Begin VB.Label Square
BorderStyle = 1 'Fixed Single
BeginProperty Font
Name = "MS Sans Serif"
Size = 8.25
Charset = 0
Weight = 700
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 855
Index = 2
Left = 960
TabIndex = 5
Top = 135
Width = 855
End
Begin VB.Label Square
BorderStyle = 1 'Fixed Single
BeginProperty Font
Name = "MS Sans Serif"
Size = 8.25
Charset = 0
Weight = 700
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 855
Index = 5
Left = 960
TabIndex = 8
Top = 960
Width = 855
End
Begin VB.Label Square
BorderStyle = 1 'Fixed Single
BeginProperty Font
Name = "MS Sans Serif"
Size = 8.25
Charset = 0
Weight = 700
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 855
Index = 6
Left = 1800
TabIndex = 9
Top = 960
Width = 855
End
Begin VB.Label Square
BorderStyle = 1 'Fixed Single
BeginProperty Font
Name = "MS Sans Serif"
Size = 8.25
Charset = 0
Weight = 700
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 855
Index = 7
Left = 120
TabIndex = 10
Top = 1800
Width = 855
End
Begin VB.Label Square
BorderStyle = 1 'Fixed Single
BeginProperty Font
Name = "MS Sans Serif"
Size = 8.25
Charset = 0
Weight = 700
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 855
Index = 8
Left = 960
TabIndex = 2
Top = 1800
Width = 855
End
Begin VB.Label Square
BorderStyle = 1 'Fixed Single
BeginProperty Font
Name = "MS Sans Serif"
Size = 8.25
Charset = 0
Weight = 700
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 855
Index = 9
Left = 1800
TabIndex = 3
Top = 1800
Width = 855
End
Begin VB.Menu mnuFile
Caption = "&File"
Begin VB.Menu NewGame
Caption = "&New Game..."
End
Begin VB.Menu TCPIPGame
Caption = "&TCP/IP Game..."
End
Begin VB.Menu Blank1
Caption = "-"
End
Begin VB.Menu mnuFileExit
Caption = "E&xit"
End
End
Begin VB.Menu mnuOptions
Caption = "&Options"
Begin VB.Menu mnuOptionsPlayX
Caption = "Play &X"
Checked = -1 'True
Shortcut = ^X
End
Begin VB.Menu mnuOptionsPlayO
Caption = "Play &O"
Shortcut = ^O
End
Begin VB.Menu mnuOptionsSep1
Caption = "-"
End
Begin VB.Menu mnuOptionsLevel
Caption = "Level &1"
Checked = -1 'True
Index = 1
Shortcut = +{F1}
End
Begin VB.Menu mnuOptionsLevel
Caption = "Level &2"
Index = 2
Shortcut = +{F2}
End
Begin VB.Menu mnuOptionsLevel
Caption = "Level &3"
Index = 3
Shortcut = +{F3}
End
Begin VB.Menu Blank2
Caption = "-"
End
Begin VB.Menu ClearScores
Caption = "&Clear Scores"
Shortcut = %{BKSP}
End
End
Begin VB.Menu AboutMenu
Caption = "&About"
Begin VB.Menu CreditsMenu
Caption = "&Credits..."
End
Begin VB.Menu AboutTicTacToe
Caption = "About &Tic Tac Toe..."
End
End
End
Attribute VB_Name = "TicTacToeForm"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Dim ComputerWins, HumanWins
Dim ComputerLett, HumanLett
Dim GameNum
Sub DrawSquare(i As Integer)
Select Case Board(i)
Case PlayerX
X1(i).Visible = True
X2(i).Visible = True
Case PlayerO
O(i).Visible = True
End Select
End Sub
Private Sub AboutTicTacToe_Click()
About.Show 1
End Sub
Private Sub ClearScores_Click()
HumanWins = 0
ComputerWins = 0
Label1.Caption = "Human (" + HumanLett + "): " & HumanWins
Label2.Caption = "Computer (" + ComputerLett + "): " & ComputerWins
End Sub
Private Sub Command1_Click()
StartNewGame
End Sub
Private Sub Command2_Click()
End
End Sub
Private Sub CreditsMenu_Click()
Credits.Show 1
End Sub
Private Sub Form_Load()
SkillLevel = 1
PlayerX = PLAYER_HUMAN
PlayerO = PLAYER_COMPUTER
ComputerWins = 0
HumanWins = 0
GameNum = 0
ComputerLett = "O"
HumanLett = "X"
StartNewGame
End Sub
Function GameOver() As Integer
Dim pl As Integer
pl = Winner()
If pl = PLAYER_NONE Then
GameOver = False
Exit Function
End If
GameInProgress = False
If pl = PlayerX Then
Msg.Caption = "X Wins."
If PlayerX = PLAYER_HUMAN Then HumanWins = HumanWins + 1
If PlayerX = PLAYER_COMPUTER Then ComputerWins = ComputerWins + 1
Label1.Caption = "Human (" + HumanLett + "): " & HumanWins
Label2.Caption = "Computer (" + ComputerLett + "): " & ComputerWins
ElseIf pl = PlayerO Then
Msg.Caption = "O Wins."
If PlayerO = PLAYER_HUMAN Then HumanWins = HumanWins + 1
If PlayerO = PLAYER_COMPUTER Then ComputerWins = ComputerWins + 1
Label1.Caption = "Human (" + HumanLett + "): " & HumanWins
Label2.Caption = "Computer (" + ComputerLett + "): " & ComputerWins
Else
Msg.Caption = "No One Wins."
End If
Beep
GameOver = True
End Function
Sub MakeComputerMove()
Dim Square As Integer
Msg.Caption = "The Computer's Turn."
MousePointer = vbHourglass
Square = PickComputerMove
Board(Square) = NextPlayer
DrawSquare Square
NextPlayer = PLAYER_HUMAN
MousePointer = vbDefault
End Sub
Sub MakeHumanMove()
Msg.Caption = "Your Turn."
End Sub
Private Sub Form_Terminate()
End
End Sub
Private Sub mnuFileExit_Click()
End
End Sub
Private Sub mnuOptionsLevel_Click(Index As Integer)
mnuOptionsLevel(SkillLevel).Checked = False
SkillLevel = Index
mnuOptionsLevel(SkillLevel).Checked = True
StartNewGame
End Sub
Private Sub mnuOptionsPlayO_Click()
PlayerX = PLAYER_COMPUTER
PlayerO = PLAYER_HUMAN
mnuOptionsPlayX.Checked = False
mnuOptionsPlayO.Checked = True
ComputerLett = "X"
HumanLett = "O"
Label1.Caption = "Human (" + HumanLett + "): " & HumanWins
Label2.Caption = "Computer (" + ComputerLett + "): " & ComputerWins
StartNewGame
End Sub
Private Sub mnuOptionsPlayX_Click()
PlayerX = PLAYER_HUMAN
PlayerO = PLAYER_COMPUTER
mnuOptionsPlayX.Checked = True
mnuOptionsPlayO.Checked = False
ComputerLett = "O"
HumanLett = "X"
Label1.Caption = "Human (" + HumanLett + "): " & HumanWins
Label2.Caption = "Computer (" + ComputerLett + "): " & ComputerWins
StartNewGame
End Sub
Sub PlayerHasMoved()
If NextPlayer = PLAYER_COMPUTER Then
MakeComputerMove
If GameOver() Then Exit Sub
End If
MakeHumanMove
End Sub
Private Sub NewGame_Click()
StartNewGame
End Sub
Private Sub Square_Click(Index As Integer)
If Not GameInProgress Then StartNewGame: Exit Sub
If NextPlayer <> PLAYER_HUMAN Then Exit Sub
If Board(Index) <> PLAYER_NONE Then Exit Sub
Board(Index) = NextPlayer
DrawSquare Index
If GameOver() Then Exit Sub
NextPlayer = PLAYER_COMPUTER
PlayerHasMoved
End Sub
Sub StartNewGame()
Dim i As Integer
For i = 1 To NUM_SQUARES
Board(i) = PLAYER_NONE
X1(i).Visible = False
X2(i).Visible = False
O(i).Visible = False
Next i
NextPlayer = PlayerX
GameInProgress = True
GameNum = GameNum + 1
Caption = "MindPower Tic Tac Toe - Game " & GameNum
PlayerHasMoved
End Sub
Function Winner() As Integer
Dim i As Integer
For i = 1 To 7 Step 3
If Board(i) <> PLAYER_NONE Then
If Board(i) = Board(i + 1) And Board(i) = Board(i + 2) Then
Winner = Board(i)
Exit Function
End If
End If
Next i
For i = 1 To 3
If Board(i) <> PLAYER_NONE Then
If Board(i) = Board(i + 3) And Board(i) = Board(i + 6) Then
Winner = Board(i)
Exit Function
End If
End If
Next i
If Board(1) <> PLAYER_NONE Then
If Board(1) = Board(5) And Board(1) = Board(9) Then
Winner = Board(1)
Exit Function
End If
End If
If Board(3) <> PLAYER_NONE Then
If Board(3) = Board(5) And Board(3) = Board(7) Then
Winner = Board(3)
Exit Function
End If
End If
Winner = PLAYER_NONE
For i = 1 To NUM_SQUARES
If Board(i) = PLAYER_NONE Then Exit Function
Next i
Winner = PLAYER_DRAW
End Function
Private Sub TCPIPGame_Click()
TicTacToeConnForm.Show 1
End Sub