home *** CD-ROM | disk | FTP | other *** search
Visual Basic class definition | 2001-09-09 | 4.0 KB | 167 lines |
- VERSION 1.0 CLASS
- BEGIN
- MultiUse = -1 'True
- Persistable = 0 'NotPersistable
- DataBindingBehavior = 0 'vbNone
- DataSourceBehavior = 0 'vbNone
- MTSTransactionMode = 0 'NotAnMTSObject
- END
- Attribute VB_Name = "CBoard"
- Attribute VB_GlobalNameSpace = False
- Attribute VB_Creatable = True
- Attribute VB_PredeclaredId = False
- Attribute VB_Exposed = False
- Attribute VB_Ext_KEY = "SavedWithClassBuilder6" ,"Yes"
- Attribute VB_Ext_KEY = "Top_Level" ,"Yes"
- '-----------------------------------------------------------------------------
- ' This is a part of the BeeGrid ActiveX control.
- ' Copyright ⌐ 2000 Stinga
- ' All rights reserved.
- '
- ' You have a right to use and distribute the BeeGrid sample files in original
- ' form or modified, provided that you agree that Stinga has no warranty,
- ' obligations, or liability for any sample application files.
- '-----------------------------------------------------------------------------
- Option Explicit
-
- Private mariCards(51) As Integer
-
- Public Board As Long
- Public Dealer As String
- Public Vulnerability As String
-
- Public North As CBridgePlayer
- Public South As CBridgePlayer
- Public West As CBridgePlayer
- Public East As CBridgePlayer
-
-
-
- Private Sub SetCards(iFirstCard As Integer, Player As CBridgePlayer)
- Dim i%
- Dim ariTmp(12) As Integer
-
- For i = 0 To 12
- ariTmp(i) = mariCards(i + iFirstCard)
- Next
-
- Call Sort(ariTmp())
-
- Set Player = New CBridgePlayer
-
- For i = 12 To 0 Step -1
- Select Case ariTmp(i)
- Case Is < 14 'clubs
- Player.Clubs = Player.Clubs & CardSign(ariTmp(i))
- Case 14 To 26 'diamonds
- Player.Diamonds = Player.Diamonds & CardSign(ariTmp(i) - 13)
- Case 27 To 39 'hearts
- Player.Hearts = Player.Hearts & CardSign(ariTmp(i) - 26)
- Case Else 'spades
- Player.Spades = Player.Spades & CardSign(ariTmp(i) - 39)
- End Select
- Next
- End Sub
- Private Function CardSign(iValue As Integer) As String
-
- Select Case iValue
- Case Is < 9
- CardSign = Trim(iValue + 1)
- Case 9: CardSign = "T"
- Case 10: CardSign = "J"
- Case 11: CardSign = "Q"
- Case 12: CardSign = "K"
- Case 13: CardSign = "A"
- End Select
- End Function
-
-
-
-
-
- Private Sub Sort(arVal() As Integer)
- On Error GoTo SortErr
-
- Dim iRowMin As Integer, iRowNext As Integer, iRow As Integer, iFrom As Integer, iTo As Integer
-
- iFrom = LBound(arVal)
- iTo = UBound(arVal)
-
- For iRow = iFrom To iTo
- iRowMin = iRow
- For iRowNext = iRow To iTo
- If arVal(iRowNext) < arVal(iRowMin) Then iRowMin = iRowNext
- Next
-
- If iRowMin > iRow Then Call Swap(arVal(iRow), arVal(iRowMin))
- Next
- Exit Sub
-
- SortErr:
- MsgBox Error
- Exit Sub
- End Sub
-
- Private Sub Shuffle(ai() As Integer)
- Dim iFirst As Long, iLast As Long
-
- iFirst = LBound(ai): iLast = UBound(ai)
- ' Randomize array
- Dim i As Long, iRnd As Long
-
- For i = iLast To iFirst + 1 Step -1
- ' Swap random element with last element
- iRnd = CInt(Rnd * 51)
- Swap ai(i), ai(iRnd)
- Next
- End Sub
-
- Public Sub Deal()
- Dim i As Integer, j As Integer
- Dim lTmpVul As Long, arVul As Variant
- 'set board info
- Dealer = Choose((Board Mod 4) + 1, "N", "E", "S", "W")
- arVul = Array("-", "N-S", "E-W", "All")
- lTmpVul = ((Board Mod 4) + ((Board Mod 16) \ 4)) Mod 4
- Vulnerability = arVul(lTmpVul)
- Board = Board + 1
- 'shuffle cards
- For i = 0 To 30
- Shuffle mariCards
- Next
-
- SetCards 0, North
- SetCards 13, South
- SetCards 26, West
- SetCards 39, East
- End Sub
-
-
- Private Sub Swap(i1 As Integer, i2 As Integer)
- Dim i As Integer
-
- i = i2
- i2 = i1
- i1 = i
- End Sub
-
-
- Private Sub Class_Initialize()
- Dim i%
-
- For i = 0 To 51
- mariCards(i) = i + 1
- Next i
-
- End Sub
-
-
- Private Sub Class_Terminate()
- Set North = Nothing
- Set South = Nothing
- Set West = Nothing
- Set East = Nothing
- End Sub
-
-
-