home *** CD-ROM | disk | FTP | other *** search
Visual Basic class definition | 1997-10-01 | 2.5 KB | 119 lines |
- VERSION 1.0 CLASS
- BEGIN
- MultiUse = -1 'True
- END
- Attribute VB_Name = "TicTacToe_Computer"
- Attribute VB_GlobalNameSpace = False
- Attribute VB_Creatable = False
- Attribute VB_PredeclaredId = False
- Attribute VB_Exposed = False
- '
- ' File : TicTacToe_Computer.cls
- '
- ' Project : demo
- ' Configuration : demo 1
- ' Phase : Implementation 1
- ' System : TicTacToe 1
- '
- ' The computer opponent.
- Option Explicit
-
-
- ' Inheritance attributes
-
-
- ' Association attributes
-
- Public gui_ As TicTacToe_GUI
-
- Public game_ As TicTacToe_Game
-
-
- ' User defined attributes
-
- Private id_ As String
- ' Has default value ""
-
-
- ' User defined methods
-
- Public Sub TicTacToe_Computer_Constructor(a_game As TicTacToe_Game)
- id = ""
- Set game = a_game
- ' Start user section
- ' End user section
- End Sub
-
- Private Sub Class_Terminate()
- ' Start user section
- ' End user section
- End Sub
-
- ' Checks if it's its turn.
- Public Sub checkTurn()
- If id = game.getActivePlayer Then selectCell
- End Sub
-
- ' Chooses a good empty cell.
- Public Sub selectCell()
- Dim i As Integer
- Dim maxi, temp As Integer
- Dim selection As Integer
- selection = -1
-
- For i = 0 To (gui.numberOfCells - 1)
- If game.board(i).contents = "" Then
- temp = getMaxValue(i)
- If maxi < temp Or selection = -1 Then
- maxi = temp
- selection = i
- End If
- End If
- Next i
-
- If selection <> -1 Then gui.CellButton_Click (selection)
- End Sub
-
- ' Determines the strategic value of the specified empty cell.
- Public Function getMaxValue(x As Integer) As Integer
- Dim i As Integer
- Dim temp As Integer
- getMaxValue = -1
-
- For i = 1 To Len(game.players)
- game.board(x).contents = Mid(game.players, i, 1)
- temp = game.board(x).getMaxLine
- If getMaxValue < temp Or getMaxValue = -1 Then getMaxValue = temp
- Next i
- game.board(x).contents = ""
- End Function
-
-
- ' Access methods
-
- Public Property Get id() As String
- id = id_
- End Property
-
- Public Property Let id(x As String)
- id_ = x
- End Property
-
-
- ' Association methods
-
- Public Property Get gui() As TicTacToe_GUI
- Set gui = gui_
- 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
- Set game_ = x
- End If
- End Property
-
-