home *** CD-ROM | disk | FTP | other *** search
Visual Basic class definition | 1997-10-01 | 2.7 KB | 115 lines |
- VERSION 1.0 CLASS
- BEGIN
- MultiUse = -1 'True
- END
- Attribute VB_Name = "TicTacToe_Cell"
- Attribute VB_GlobalNameSpace = False
- Attribute VB_Creatable = False
- Attribute VB_PredeclaredId = False
- Attribute VB_Exposed = False
- '
- ' File : TicTacToe_Cell.cls
- '
- ' Project : demo
- ' Configuration : demo 1
- ' Phase : Implementation 1
- ' System : TicTacToe 1
- '
- ' Cell of the board.
- Option Explicit
-
-
- ' Inheritance attributes
-
-
- ' Association attributes
-
- Private neighbour_ As New ClassSet
-
-
- ' User defined attributes
-
- Private contents_ As String
- ' Has default value ""
-
-
- ' User defined methods
-
- Public Sub TicTacToe_Cell_Constructor()
- contents = ""
- ' Start user section
- ' End user section
- End Sub
-
- Private Sub Class_Terminate()
- ' Start user section
- ' End user section
- End Sub
-
- ' Returns the highest number of connected cells in a line,
- ' where each cell contains the same symbol as this cell.
- Public Function getMaxLine() As Integer
- Dim i As Integer
-
- getMaxLine = getLine("N", contents) + getLine("S", contents) - 1
-
- i = getLine("E", contents) + getLine("W", contents) - 1
- If getMaxLine < i Then getMaxLine = i
-
- i = getLine("NE", contents) + getLine("SW", contents) - 1
- If getMaxLine < i Then getMaxLine = i
-
- i = getLine("NW", contents) + getLine("SE", contents) - 1
- If getMaxLine < i Then getMaxLine = i
- End Function
-
- ' Returns the highest number of connected cells in a line in a specific
- ' direction, where each cell contains the same specified symbol.
- Public Function getLine(dir As String, x As String) As Integer
- getLine = 0
-
- If contents = x Then
- getLine = 1
- Dim temp As TicTacToe_Cell
- Set temp = neighbour(dir)
- If Not (temp Is Nothing) Then
- getLine = getLine + temp.getLine(dir, x)
- End If
- End If
- End Function
-
-
- ' Access methods
-
- Public Property Get contents() As String
- contents = contents_
- End Property
-
- Public Property Let contents(x As String)
- contents_ = x
- End Property
-
-
- ' Association methods
-
- Public Property Get neighbour(Direction As String) As TicTacToe_Cell
- If neighbour_.ContainsKey(CStr(Direction)) Then
- Set neighbour = neighbour_.Item(CStr(Direction))
- Else
- Set neighbour = Nothing
- End If
- End Property
-
- Public Sub AddNeighbour(x As TicTacToe_Cell, Direction As String)
- If Not (x Is Nothing) Then
- neighbour_.Add x, CStr(Direction)
- End If
- End Sub
-
- Public Sub RemoveNeighbour(Direction As String)
- Dim temp As TicTacToe_Cell
- Set temp = neighbour_.Item(CStr(Direction))
- neighbour_.RemoveUsingKey(CStr(Direction))
- End Sub
-
-