| 网站首页 | VB.Net实例分析 | .Net技术文摘 | 下载中心 | VB.Net书籍笔记 | .Net源码 | VBS脚本与组件调用 | Windows2008技术文摘 | 给我们留言 | 
最新公告:

  没有公告

您现在的位置: 乐博网 >> VB.Net实例分析 >> 游戏编程 >> 实例分析正文
最新推荐 更多内容
VB.Net扑克牌游戏的类
VB.Net扑克牌游戏的类
作者:Ilu    来源:乐博网整理     更新时间:2009-9-2

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] 下一页

  • 上一篇:

  • 下一篇: 没有了
  • 【字体: 】【打印此文】【关闭窗口
      相关文章:(只显示最新16条)
    小游戏开发(VB2010实例)
    VB.Net制作2D地图引擎
    VB.NET编写扑克牌游戏的实例
    VB.NET游戏开发的实例

    | 设为首页 | 加入收藏 | 联系站长 | | 友情链接 | 版权申明 |
    乐博网欢迎各种媒体转载我们的原创作品[转载请注明出处];我们鼓励更多VB.Net开发者一起加入研究与探讨;如发现文章访问错误、内容错误或版权疑问、内容有违相关法律(如涉及政治、色情、反动或散布虚假有害信息)等情况,请及时向我们举报,我们将及时纠正!
    联系邮箱:Shiny#vip.qq.com (#替换为@) QQ交流群: 40797788 [闽ICP备05014267号]