Option Explicit On Option Strict On
Imports System Imports System.Drawing
Public Class ICards
#Region "Drawing Api/Enums"
'Used to initiate the drawing Private Declare Function cdtInit Lib "cards.dll" (ByRef width As Integer, ByRef height As Integer) As Boolean Private Declare Function cdtDraw Lib "cards.dll" (ByVal hdc As IntPtr, ByVal x As Integer, ByVal y As Integer, ByVal card As Integer, ByVal mode As Integer, ByVal Color As Long) As Boolean 'used to actually draw the card Private Declare Function cdtDrawExt Lib "cards.dll" (ByVal hdc As IntPtr, ByVal x As Integer, ByVal y As Integer, ByVal dx As Integer, ByVal dy As Integer, ByVal card As Integer, ByVal suit As Integer, ByVal color As Long) As Boolean
'used to close the drawing session Private Declare Sub cdtTerm Lib "cards.dll" ()
'乐博网www.lob.cn提示:此代码调用了cards.dll 在windows2003系统中
'系统盘下的windows/system32中找到cards.dll 大小352kb |在xp sp2下也发现同样的文件 大小为351k
Public Enum cardback sky = 54 blue = 55 fish = 56 frog = 57 redWhirl = 58 beach = 59 blueSquare = 60 purple = 61 desert = 62 astronaught = 63 orange = 64 cars = 65 x = 66 o = 67 End Enum 'holds the names of the card face Public Enum Face Ace Two Three Four Five Six Seven Eight Nine Ten Jack Queen King End Enum
'Just holds the names of the card suits Public Enum Suit Diamond Club Heart Spade End Enum
#End Region
#Region "Variables and Structures" 'Drawing Card Variables Private nSuit As Suit 'Holds the suit of the currently drawn card Private nFace As Face 'holds the face of the currently drawn card
Private width As Integer = 0 'This is the width of the card Private height As Integer = 0 'this is the height of the card
'This structure is used to keep track of where each card is Private Structure CardData Dim index As Integer Dim CardType As String Dim Location As String Dim PlayerID As String End Structure
'Public Variables Public isSet As Boolean 'used to determine if the class has bene initialised!
'Other Private Variables Private PlayerCount As Integer 'Holds the number of players in the game Private backstyle As Integer = 61 'holds the back flip view of the card
'Cards Variables '更多vb.net源码和实例,请关注{乐博网 www.lob.cn} Private deck(51) As String 'Holds all the cards Private activeDeck(51) As CardData 'Holds all the cards locations after been shuffled Private currentIndex As Integer 'This contains what current card number we are up to in the deck! #End Region
Public Sub setUp(ByVal nPlayers As Integer) 'if we are allready set we dont need to start again If isSet = True Then Exit Sub End If
Dim i As Integer 'counter Dim t As Integer 'counter Dim CardCount As Integer 'Another counter to determine what card number we are up to
PlayerCount = nPlayers
CardCount = 0
'these loops fill our array with all the cards For t = 0 To 3 For i = 0 To 12 Select Case t Case 0 deck(CardCount) = "h." & i + 1 Case 1 deck(CardCount) = "d." & i + 1 Case 2 deck(CardCount) = "s." & i + 1 Case 3 deck(CardCount) = "c." & i + 1 End Select CardCount = CardCount + 1 Next Next
'Now we must set up the drawing section cdtInit(width, height) Application.DoEvents()
isSet = True ' set the variable to true so we can tell that the class has been initialised! End Sub
Public Sub Shuffle(ByVal nTimes As Integer) 'this sub shuffles the deck and moves the values to activeDeck
Dim x As Integer Dim swap As String Dim r As Random = New Random
For p As Integer = 0 To nTimes For i As Integer = 0 To deck.GetUpperBound(0) x = r.Next(0, i)
swap = deck(x) deck(x) = deck(i) deck(i) = swap Next i Next p
For i As Integer = 0 To 51 activeDeck(i).index = i activeDeck(i).CardType = deck(i) activeDeck(i).Location = "." activeDeck(i).PlayerID = "." Next
End Sub
[1] [2] 下一页 |