vb.net 发牌程序 2

前端之家收集整理的这篇文章主要介绍了vb.net 发牌程序 2前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

上一篇文章

发牌程序的代码

Imports System.Drawing

Public Class Form1

    Structure Poker
        Dim ID As Integer
        Dim Name As String
    End Structure

    Dim prePoker As List(Of Poker)
    Dim disorderPoker As List(Of Poker)

    Dim personPoker() As List(Of Poker)
    Private Sub Form1_Load(sender As Object,e As EventArgs) Handles MyBase.Load
        prePoker = New List(Of Poker)
        ComboBox1.Text = "3"
    End Sub

    Private Sub initPoker(ByVal intPokerCount As Integer)

        Dim pokerColor As String
        Dim pokerName As String

        Dim poker_id As Integer
        Dim poker_name As String

        Dim poker As New Poker
        For i As Integer = 0 To intPokerCount
            poker_id = i

            Dim intPokerName As Integer = i \ 4
            Select Case intPokerName
                Case 0
                    pokerName = "A"
                Case 1 To 8
                    pokerName = intPokerName.ToString
                Case 9
                    pokerName = "X"
                Case 10
                    pokerName = "J"
                Case 11
                    pokerName = "Q"
                Case 12
                    pokerName = "K"
                Case Else
                    pokerName = "Joker"
            End Select
            Dim intPokerColor As Integer = i Mod 4
            Select Case intPokerColor
                Case 0
                    pokerColor = "S"        '-Spade
                Case 1
                    pokerColor = "H"        '-Heart
                Case 2
                    pokerColor = "C"        '-Club
                Case Else
                    pokerColor = "D"        '-Diamond
            End Select
            If pokerName = "Joker" Then
                If intPokerColor = 0 Then
                    pokerColor = "B"        '-Big
                Else
                    pokerColor = "L"        '-Little
                End If
            End If
            poker_name = pokerColor & " " & pokerName
            poker.ID = poker_id
            poker.Name = poker_name

            prePoker.Add(poker)
        Next

    End Sub

    Private Sub Button1_Click(sender As Object,e As EventArgs) Handles Button1.Click
        Dim intPokerCount As Integer
        Dim intPersonCount As Integer

        Select Case ComboBox1.Text
            Case "3"
                intPokerCount = 53
                intPersonCount = 3
            Case Else
                intPokerCount = 51
                intPersonCount = 4
        End Select
        Call initPoker(intPokerCount)

        disorderPoker = New List(Of Poker)

        Call distributePoker()

        ReDim personPoker(intPersonCount)
        For i As Integer = 0 To intPersonCount - 1
            personPoker(i) = New List(Of Poker)
        Next

        Dim orderId As Integer
        For i As Integer = 0 To disorderPoker.Count - 1
            orderId = i Mod intPersonCount
            personPoker(orderId).Add(disorderPoker.Item(i))
        Next

        Call drawPoker()

    End Sub

    Private Sub distributePoker()
        Dim intPokerCount As Integer
        intPokerCount = prePoker.Count - 1

        Dim rand_PokerIndex As Integer
        Dim randSeed As New Random(Now.Millisecond)

        For i As Integer = intPokerCount To 0 Step -1
            rand_PokerIndex = randSeed.Next(i + 1)
            disorderPoker.Add(prePoker.Item(rand_PokerIndex))
            prePoker.RemoveAt(rand_PokerIndex)

        Next
    End Sub

    Private Sub drawPoker()
        Dim imgPath As String = ""
        Dim imgFolder As String = Application.StartupPath & "\poker\"
        Dim g As Graphics = PictureBox1.CreateGraphics
        g.Clear(PictureBox1.BackColor)

        Dim intPersonCount As Integer = personPoker.GetUpperBound(0)

        Dim leftMargin As Integer = 10
        Dim topMargin As Integer = 10

        For i As Integer = 0 To intPersonCount - 1
            For j As Integer = 0 To personPoker(i).Count - 1
                imgPath = imgFolder & personPoker(i)(j).ID & ".jpg"
                Dim bmp As New Bitmap(imgPath)
                g.DrawImage(bmp,New Point(leftMargin + j * 30,topMargin + i * 60))
                bmp.Dispose()
            Next

        Next
        g.Dispose()

    End Sub
End Class

运行时:




由于.net平台下C#和vb.NET很相似,本文也可以为C#爱好者提供参考。

学习更多vb.net知识,请参看vb.net 教程 目录

原文链接:https://www.f2er.com/vb/256363.html

猜你在找的VB相关文章