home *** CD-ROM | disk | FTP | other *** search
/ PC World 1998 October / PCWorld_1998-10_cd.bin / software / prehled / komix / DATA.Z / TicTacToe_Cell.cls < prev    next >
Text File  |  1997-10-01  |  3KB  |  115 lines

  1. VERSION 1.0 CLASS
  2. BEGIN
  3.   MultiUse = -1  'True
  4. END
  5. Attribute VB_Name = "TicTacToe_Cell"
  6. Attribute VB_GlobalNameSpace = False
  7. Attribute VB_Creatable = False
  8. Attribute VB_PredeclaredId = False
  9. Attribute VB_Exposed = False
  10. '
  11. ' File          : TicTacToe_Cell.cls
  12. '
  13. ' Project       : demo
  14. ' Configuration : demo 1
  15. ' Phase         : Implementation 1
  16. ' System        : TicTacToe 1
  17. '
  18. ' Cell of the board.
  19. Option Explicit
  20.  
  21.  
  22. ' Inheritance attributes
  23.  
  24.  
  25. ' Association attributes
  26.  
  27. Private neighbour_ As New ClassSet
  28.  
  29.  
  30. ' User defined attributes
  31.  
  32. Private contents_ As String
  33. ' Has default value ""
  34.  
  35.  
  36. ' User defined methods
  37.  
  38. Public Sub TicTacToe_Cell_Constructor()
  39.     contents = ""
  40.     ' Start user section
  41.     ' End user section
  42. End Sub
  43.  
  44. Private Sub Class_Terminate()
  45.     ' Start user section
  46.     ' End user section
  47. End Sub
  48.  
  49. ' Returns the highest number of connected cells in a line,
  50. ' where each cell contains the same symbol as this cell.
  51. Public Function getMaxLine() As Integer
  52.     Dim i As Integer
  53.  
  54.     getMaxLine = getLine("N", contents) + getLine("S", contents) - 1
  55.  
  56.     i = getLine("E", contents) + getLine("W", contents) - 1
  57.     If getMaxLine < i Then getMaxLine = i
  58.  
  59.     i = getLine("NE", contents) + getLine("SW", contents) - 1
  60.     If getMaxLine < i Then getMaxLine = i
  61.  
  62.     i = getLine("NW", contents) + getLine("SE", contents) - 1
  63.     If getMaxLine < i Then getMaxLine = i
  64. End Function
  65.  
  66. ' Returns the highest number of connected cells in a line in a specific
  67. ' direction, where each cell contains the same specified symbol.
  68. Public Function getLine(dir As String, x As String) As Integer
  69.     getLine = 0
  70.  
  71.     If contents = x Then
  72.         getLine = 1
  73.         Dim temp As TicTacToe_Cell
  74.         Set temp = neighbour(dir)
  75.         If Not (temp Is Nothing) Then
  76.            getLine = getLine + temp.getLine(dir, x)
  77.         End If
  78.     End If
  79. End Function
  80.  
  81.  
  82. ' Access methods
  83.  
  84. Public Property Get contents() As String
  85.     contents = contents_
  86. End Property
  87.  
  88. Public Property Let contents(x As String)
  89.     contents_ = x
  90. End Property
  91.  
  92.  
  93. ' Association methods
  94.  
  95. Public Property Get neighbour(Direction As String) As TicTacToe_Cell
  96.     If neighbour_.ContainsKey(CStr(Direction)) Then
  97.         Set neighbour = neighbour_.Item(CStr(Direction))
  98.     Else
  99.         Set neighbour = Nothing
  100.     End If
  101. End Property
  102.  
  103. Public Sub AddNeighbour(x As TicTacToe_Cell, Direction As String)
  104.     If Not (x Is Nothing) Then
  105.         neighbour_.Add x, CStr(Direction)
  106.     End If
  107. End Sub
  108.  
  109. Public Sub RemoveNeighbour(Direction As String)
  110.     Dim temp As TicTacToe_Cell
  111.     Set temp = neighbour_.Item(CStr(Direction))
  112.     neighbour_.RemoveUsingKey(CStr(Direction))
  113. End Sub
  114.  
  115.