Professional Documents
Culture Documents
00
Begin VB.Form frmTicTacToe
Caption
=
"About Tic Tac Toe"
ClientHeight
=
3225
ClientLeft
=
135
ClientTop
=
420
ClientWidth
=
4665
LinkTopic
=
"Form1"
ScaleHeight
=
3225
ScaleWidth
=
4665
StartUpPosition =
2 'CenterScreen
Begin VB.CommandButton cmdResetScore
Caption
=
"Reset the ScoreBoard"
Height
=
372
Left
=
2520
TabIndex
=
11
Top
=
2640
Width
=
1932
End
Begin VB.Frame fraPlayFirst
Caption
=
"First to Play"
Height
=
1092
Left
=
2520
TabIndex
=
1
Top
=
120
Width
=
1932
Begin VB.OptionButton optXPlayer
Caption
=
"X - Player 1"
Height
=
252
Left
=
240
TabIndex
=
3
Top
=
360
Value
=
-1 'True
Width
=
1212
End
Begin VB.OptionButton optOPlayer
Caption
=
"O - Player 2"
Height
=
252
Left
=
240
TabIndex
=
2
Top
=
720
Width
=
1212
End
End
Begin VB.Frame FraScoreBoard
Caption
=
"ScoreBoard"
Height
=
1212
Left
=
2520
TabIndex
=
4
Top
=
1320
Width
=
1932
Begin VB.Label Label4
Alignment
=
2 'Center
Caption
=
":"
BeginProperty Font
Name
=
"Arial"
Size
=
18
Charset
=
238
Weight
=
700
Underline
=
0
'False
Italic
=
0
'False
Strikethrough
=
0
'False
EndProperty
Height
=
400
Left
=
720
TabIndex
=
10
Top
=
720
Width
=
492
End
Top
Width
=
=
240
696
End
Begin VB.Label lblX
Alignment
=
Caption
=
BeginProperty Font
Name
Size
Charset
Weight
Underline
Italic
Strikethrough
EndProperty
Height
=
Left
=
TabIndex
=
Top
=
Width
=
End
End
Begin VB.CommandButton
Caption
=
Height
=
Left
=
TabIndex
=
Top
=
Visible
=
Width
=
End
Begin VB.Line Line4
X1
=
X2
=
Y1
=
Y2
=
End
Begin VB.Line Line3
X1
=
X2
=
Y1
=
Y2
=
End
Begin VB.Line Line2
X1
=
X2
=
Y1
=
Y2
=
End
Begin VB.Line Line1
X1
=
X2
=
Y1
=
Y2
=
End
Begin VB.Line linWin
BorderColor
=
BorderWidth
=
Index
=
Visible
=
X1
=
X2
=
Y1
=
Y2
=
End
Begin VB.Line linWin
BorderColor
=
BorderWidth
=
Index
=
2 'Center
"X"
=
=
=
=
=
=
=
"Arial"
18
238
400
0
'False
0
'False
0
'False
492
120
5
240
696
cmdNewGame
"Start a New Game"
372
120
0
2640
0
'False
1812
480
1680
1080
1080
480
1680
1560
1560
1320
1320
720
1920
840
840
720
1920
&H00FF0000&
2
3
0
'False
240
1920
480
2160
&H00FF0000&
2
7
Visible
X1
X2
Y1
Y2
=
=
=
=
=
0
'False
1560
1560
2160
480
End
Begin VB.Line linWin
BorderColor
=
&H00FF0000&
BorderWidth
=
2
Index
=
6
Visible
=
0
'False
X1
=
1080
X2
=
1080
Y1
=
2160
Y2
=
480
End
Begin VB.Line linWin
BorderColor
=
&H00FF0000&
BorderWidth
=
2
Index
=
5
Visible
=
0
'False
X1
=
600
X2
=
600
Y1
=
2160
Y2
=
480
End
Begin VB.Line linWin
BorderColor
=
&H00FF0000&
BorderWidth
=
2
Index
=
4
Visible
=
0
'False
X1
=
240
X2
=
1920
Y1
=
2160
Y2
=
480
End
Begin VB.Line linWin
BorderColor
=
&H00FF0000&
BorderWidth
=
2
Index
=
2
Visible
=
0
'False
X1
=
240
X2
=
1920
Y1
=
1800
Y2
=
1800
End
Begin VB.Line linWin
BorderColor
=
&H00FF0000&
BorderWidth
=
2
Index
=
1
Visible
=
0
'False
X1
=
240
X2
=
1920
Y1
=
1320
Y2
=
1320
End
Begin VB.Line linWin
BorderColor
=
&H00FF0000&
BorderWidth
=
2
Index
=
0
Visible
=
0
'False
X1
=
240
X2
=
1920
Y1
=
840
Y2
=
840
End
Begin VB.Label lblStartMsg
Caption
=
"Click the game grid to start!"
Height
=
375
Left
TabIndex
Top
Width
=
=
=
=
120
12
2640
1815
End
Begin VB.Label lblPlayGround
Alignment
=
2 'Center
Caption
=
"X"
BeginProperty Font
Name
=
"MS Sans Serif"
Size
=
9.75
Charset
=
0
Weight
=
700
Underline
=
0
'False
Italic
=
0
'False
Strikethrough
=
0
'False
EndProperty
ForeColor
=
&H000000FF&
Height
=
375
Index
=
8
Left
=
1380
TabIndex
=
21
Top
=
1680
Width
=
375
End
Begin VB.Label lblPlayGround
Alignment
=
2 'Center
Caption
=
"X"
BeginProperty Font
Name
=
"MS Sans Serif"
Size
=
9.75
Charset
=
0
Weight
=
700
Underline
=
0
'False
Italic
=
0
'False
Strikethrough
=
0
'False
EndProperty
ForeColor
=
&H000000FF&
Height
=
375
Index
=
7
Left
=
900
TabIndex
=
20
Top
=
1680
Width
=
375
End
Begin VB.Label lblPlayGround
Alignment
=
2 'Center
Caption
=
"X"
BeginProperty Font
Name
=
"MS Sans Serif"
Size
=
9.75
Charset
=
0
Weight
=
700
Underline
=
0
'False
Italic
=
0
'False
Strikethrough
=
0
'False
EndProperty
ForeColor
=
&H000000FF&
Height
=
375
Index
=
6
Left
=
420
TabIndex
=
19
Top
=
1680
Width
=
375
End
Begin VB.Label lblPlayGround
Alignment
=
2 'Center
Caption
=
"X"
BeginProperty Font
Name
Size
Charset
Weight
Underline
Italic
Strikethrough
EndProperty
ForeColor
=
Height
=
Index
=
Left
=
TabIndex
=
Top
=
Width
=
=
=
=
=
=
=
=
End
Begin VB.Label lblPlayGround
Alignment
=
2 'Center
Caption
=
"X"
BeginProperty Font
Name
=
"MS Sans Serif"
Size
=
9.75
Charset
=
0
Weight
=
700
Underline
=
0
'False
Italic
=
0
'False
Strikethrough
=
0
'False
EndProperty
ForeColor
=
&H000000FF&
Height
=
375
Index
=
3
Left
=
420
TabIndex
=
17
Top
=
1200
Width
=
375
End
Begin VB.Label lblPlayGround
Alignment
=
2 'Center
Caption
=
"X"
BeginProperty Font
Name
=
"MS Sans Serif"
Size
=
9.75
Charset
=
0
Weight
=
700
Underline
=
0
'False
Italic
=
0
'False
Strikethrough
=
0
'False
EndProperty
ForeColor
=
&H000000FF&
Height
=
375
Index
=
2
Left
=
1380
TabIndex
=
16
Top
=
720
Width
=
375
End
Begin VB.Label lblPlayGround
Alignment
=
2 'Center
Caption
=
"X"
BeginProperty Font
Name
=
"MS Sans Serif"
Size
=
9.75
Charset
=
0
Weight
=
700
Underline
=
0
'False
Italic
=
0
'False
Strikethrough
=
0
'False
EndProperty
ForeColor
=
&H000000FF&
Height
Index
Left
TabIndex
Top
Width
=
=
=
=
=
=
375
1
900
15
720
375
End
Begin VB.Label lblPlayGround
Alignment
=
2 'Center
Caption
=
"X"
BeginProperty Font
Name
=
"MS Sans Serif"
Size
=
9.75
Charset
=
0
Weight
=
700
Underline
=
0
'False
Italic
=
0
'False
Strikethrough
=
0
'False
EndProperty
ForeColor
=
&H000000FF&
Height
=
375
Index
=
0
Left
=
420
TabIndex
=
14
Top
=
720
Width
=
375
End
Begin VB.Label lblPlayGround
Alignment
=
2 'Center
Caption
=
"X"
BeginProperty Font
Name
=
"MS Sans Serif"
Size
=
9.75
Charset
=
0
Weight
=
700
Underline
=
0
'False
Italic
=
0
'False
Strikethrough
=
0
'False
EndProperty
ForeColor
=
&H000000FF&
Height
=
375
Index
=
4
Left
=
900
TabIndex
=
13
Top
=
1200
Width
=
375
End
End
Attribute VB_Name = "frmTicTacToe"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
' Scoring arrays
' These are added to determine when
' a player has won
Dim iXPos(3, 3) As Integer
Dim iOPos(3, 3) As Integer
' Determines who plays next AND
' Used as boolean test variable
Dim sPlaySign As String
' Counts the number of moves
Dim iMove As Integer
' Scoreboard variables
Dim iXScore As Integer
Dim iOScore As Integer
' Get ready to play another game
Sub InitPlayGround()
Dim i As Integer
Dim j As Integer
' Erase any playing grid symbols
For i = 1 To 3
For j = 1 To 3
lblPlayGround((i - 1) * 3 + j - 1).Caption = ""
iXPos(i, j) = 0
iOPos(i, j) = 0
Next j
Next i
' Erase any win lines
For i = 0 To 7
linWin(i).Visible = False
Next i
' Set the next player to the appropriate sign
If optOPlayer.Value = True Then
sPlaySign = "O"
Else
sPlaySign = "X"
End If
' Number of moves so far is zero
iMove = 0
' The game isn't started until a player
' clicks the playing grid
' Display the label, not the command button
cmdNewGame.Visible = False
End Sub
Private Sub cmdNewGame_Click()
' This button is only visible after someone clicks the
' playing grid and is reset to not visible
' after a win or draw
If MsgBox("Do you want to end the current game?", _
vbYesNo, "Start a New Game?") = vbYes Then Call InitPlayGround
End Sub
Private Sub cmdResetScore_Click()
If MsgBox("Do you want to reset the score?", _
vbYesNo, "Reset the Scoreboard?") = vbYes Then
iXScore = 0
iOScore = 0
lblXScore.Caption = iXScore
lblOScore.Caption = iOScore
End If
End Sub
Private Sub Form_Load()
iXScore = 0
iOScore = 0
Call InitPlayGround
End Sub
' Called when a player clicks any square in the grid
Private Sub lblPlayGround_Click(Index As Integer)
' Controls display of error message if starting player
' is changed after a game starts and
' allows a game to be restarted
cmdNewGame.Visible = True
' Calls routine that checks for winner and updates
' the playing grid with the correct symbol
GamePlay (Index)
End Sub