home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PC World 1998 October
/
PCWorld_1998-10_cd.bin
/
software
/
prehled
/
komix
/
DATA.Z
/
TicTacToe_GUI.frm
< prev
next >
Wrap
Text File
|
1997-10-01
|
13KB
|
429 lines
VERSION 5.00
Begin VB.Form TicTacToe_GUI
BackColor = &H00000000&
BorderStyle = 1 'Fixed Single
Caption = "Tic Tac Toe"
ClientHeight = 4170
ClientLeft = 8400
ClientTop = 2805
ClientWidth = 3585
FillColor = &H80000003&
BeginProperty Font
Name = "Terminal"
Size = 13.5
Charset = 255
Weight = 700
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
LinkTopic = "Form1"
MaxButton = 0 'False
ScaleHeight = 4170
ScaleWidth = 3585
Begin VB.Frame Board
BackColor = &H00000000&
ClipControls = 0 'False
Height = 3375
Left = -120
TabIndex = 1
Top = -240
Width = 3735
Begin VB.CommandButton CellButton
BeginProperty Font
Name = "Arial"
Size = 24
Charset = 0
Weight = 700
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 735
Index = 8
Left = 2280
TabIndex = 10
TabStop = 0 'False
Top = 2160
Width = 855
End
Begin VB.CommandButton CellButton
BeginProperty Font
Name = "Arial"
Size = 24
Charset = 0
Weight = 700
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 735
Index = 7
Left = 1440
TabIndex = 9
TabStop = 0 'False
Top = 2160
Width = 855
End
Begin VB.CommandButton CellButton
BeginProperty Font
Name = "Arial"
Size = 24
Charset = 0
Weight = 700
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 735
Index = 6
Left = 600
TabIndex = 8
TabStop = 0 'False
Top = 2160
Width = 855
End
Begin VB.CommandButton CellButton
BeginProperty Font
Name = "Arial"
Size = 24
Charset = 0
Weight = 700
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 735
Index = 5
Left = 2280
TabIndex = 7
TabStop = 0 'False
Top = 1440
Width = 855
End
Begin VB.CommandButton CellButton
BeginProperty Font
Name = "Arial"
Size = 24
Charset = 0
Weight = 700
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 735
Index = 4
Left = 1440
TabIndex = 6
TabStop = 0 'False
Top = 1440
Width = 855
End
Begin VB.CommandButton CellButton
BeginProperty Font
Name = "Arial"
Size = 24
Charset = 0
Weight = 700
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 735
Index = 3
Left = 600
TabIndex = 5
TabStop = 0 'False
Top = 1440
Width = 855
End
Begin VB.CommandButton CellButton
BeginProperty Font
Name = "Arial"
Size = 24
Charset = 0
Weight = 700
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 735
Index = 2
Left = 2280
TabIndex = 4
TabStop = 0 'False
Top = 720
Width = 855
End
Begin VB.CommandButton CellButton
BeginProperty Font
Name = "Arial"
Size = 24
Charset = 0
Weight = 700
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 735
Index = 1
Left = 1440
TabIndex = 3
TabStop = 0 'False
Top = 720
Width = 855
End
Begin VB.CommandButton CellButton
BeginProperty Font
Name = "Arial"
Size = 24
Charset = 0
Weight = 700
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 735
Index = 0
Left = 600
TabIndex = 2
TabStop = 0 'False
Top = 720
Width = 855
End
End
Begin VB.Label Result
Alignment = 2 'Center
BackColor = &H80000008&
BeginProperty Font
Name = "Arial"
Size = 18
Charset = 0
Weight = 700
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
ForeColor = &H0000FFFF&
Height = 855
Left = 0
TabIndex = 0
Top = 3360
Width = 3615
End
Begin VB.Menu GameMenu
Caption = "&Game"
Begin VB.Menu New
Caption = "&New"
Shortcut = ^N
End
End
Begin VB.Menu Opponent
Caption = "&Opponent"
Begin VB.Menu Oppo
Caption = "&Human"
Checked = -1 'True
Index = 0
Shortcut = ^H
End
Begin VB.Menu Oppo
Caption = "Computer &X"
Index = 1
Shortcut = ^X
End
Begin VB.Menu Oppo
Caption = "Computer &O"
Index = 2
Shortcut = ^O
End
End
End
Attribute VB_Name = "TicTacToe_GUI"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
'
' File : TicTacToe_GUI.frm
'
' Project : demo
' Configuration : demo 1
' Phase : Implementation 1
' System : TicTacToe 1
'
' User defined control GameMenu of TicTacToe_GameMenu
' User defined control New of TicTacToe_New
' User defined control Opponent of TicTacToe_OpponentMenu
' User defined control Oppo of TicTacToe_Opponent
' User defined control Oppo of TicTacToe_Opponent
' User defined control Oppo of TicTacToe_Opponent
' User defined control Board of TicTacToe_Board
' User defined control CellButton of TicTacToe_CellButton
' User defined control CellButton of TicTacToe_CellButton
' User defined control CellButton of TicTacToe_CellButton
' User defined control CellButton of TicTacToe_CellButton
' User defined control CellButton of TicTacToe_CellButton
' User defined control CellButton of TicTacToe_CellButton
' User defined control CellButton of TicTacToe_CellButton
' User defined control CellButton of TicTacToe_CellButton
' User defined control CellButton of TicTacToe_CellButton
' User defined control Result of TicTacToe_Result
' Graphical User Interface of the game.
Option Explicit
' Association attributes
Public computer_ As TicTacToe_Computer
Public game_ As TicTacToe_Game
' User defined attributes
Private numberOfCells_ As Integer
' Has default value 9
' User defined methods
Public Sub TicTacToe_GUI_Constructor(a_computer As TicTacToe_Computer, a_game As TicTacToe_Game)
numberOfCells = 9
Set computer = a_computer
Set game = a_game
' Start user section
game.startGame
' End user section
End Sub
Private Sub Form_Terminate()
' Start user section
' End user section
If Not (computer_ Is Nothing) Then
Set computer_.gui_ = Nothing
End If
If Not (game_ Is Nothing) Then
Set game_.gui_ = Nothing
End If
End Sub
' Disables all the buttons of the board.
Public Sub disableBoard()
Dim i As Integer
For i = 0 To (numberOfCells - 1)
CellButton(i).Enabled = False
Next i
End Sub
' Enables all the buttons of the board.
Public Sub enableBoard()
Dim i As Integer
For i = 0 To (numberOfCells - 1)
If CellButton(i).Caption = "" Then
CellButton(i).Enabled = True
End If
Next i
End Sub
' Clears the contents of all the buttons of the board.
Public Sub clearBoard()
Dim i As Integer
For i = 0 To (numberOfCells - 1)
CellButton(i).Caption = ""
Next i
End Sub
' Displays the specified result.
Public Sub displayResult(text As String)
Result.Caption = text
End Sub
' Events
' Initializes the window.
Private Sub Form_Initialize()
Dim game_temp As New TicTacToe_Game
Dim comp_temp As New TicTacToe_Computer
Me.TicTacToe_GUI_Constructor comp_temp, game_temp
game_temp.TicTacToe_Game_Constructor
comp_temp.TicTacToe_Computer_Constructor game_temp
End Sub
' Starts new game.
Public Sub New_Click()
game.startGame
computer.checkTurn
End Sub
' Sets opponent.
Public Sub Oppo_Click(Index As Integer)
Oppo(0).Checked = False
Oppo(1).Checked = False
Oppo(2).Checked = False
Oppo(Index).Checked = True
If Index > 0 Then
computer.id = Mid(game.players, Index, 1)
computer.checkTurn
Else
computer.id = ""
End If
End Sub
' Checks if cell is empty and sets it.
Public Sub CellButton_Click(Index As Integer)
If CellButton(Index).Enabled Then
CellButton(Index).Enabled = False
CellButton(Index).Caption = game.getActivePlayer
game.selectCell (Index)
computer.checkTurn
End If
End Sub
' Access methods
Public Property Get numberOfCells() As Integer
numberOfCells = numberOfCells_
End Property
Public Property Let numberOfCells(x As Integer)
numberOfCells_ = x
End Property
' Association methods
Public Property Get computer() As TicTacToe_Computer
Set computer = computer_
End Property
Public Property Set computer(x As TicTacToe_Computer)
If Not (x Is Nothing) Then
If x.gui Is Nothing Then
If Not (computer_ Is Nothing) Then
Set computer_.gui_ = Nothing
End If
Set computer_ = x
Set x.gui_ = Me
End If
End If
End Property
Public Property Get game() As TicTacToe_Game
Set game = game_
End Property
Public Property Set game(x As TicTacToe_Game)
If Not (x Is Nothing) Then
If x.gui Is Nothing Then
If Not (game_ Is Nothing) Then
Set game_.gui_ = Nothing
End If
Set game_ = x
Set x.gui_ = Me
End If
End If
End Property