首页 > 编程语言 > 详细

随机打乱数组算法-扑克洗牌

时间:2015-11-24 21:14:34      阅读:338      评论:0      收藏:0      [点我收藏+]

技术分享

Option Explicit
Dim Poker(53) As Long
Private Sub Command1_Click()
    Dim i&, j&, n&
    Print "---初始化扑克---"
    For i = 65 To 68    花色
        For j = 1 To 13 点数
            Poker(n) = CLng("&h" & Chr(i) & Hex(j))
            n = n + 1
        Next j
    Next i
    大小王
    Poker(52) = &HF1: Poker(53) = &HF2
    Call ShowPoker
End Sub
Private Sub Command2_Click()
    Dim i&, j&, r&, m&
    Print "---洗牌---"
    j = 53
    For i = 0 To 53
        r = Rnd * j
        m = Poker(j)
        Poker(j) = Poker(r)
        Poker(r) = m
        j = j - 1
    Next i
    Call ShowPoker
End Sub
Private Sub ShowPoker()
    Dim i&, j&
    For i = 0 To 53
        j = j + 1
        If Poker(i) >= &HA1 And Poker(i) <= &HAD Then
            Me.ForeColor = &H80FF&
        ElseIf Poker(i) >= &HB1 And Poker(i) <= &HBD Then
            Me.ForeColor = &HC000&
        ElseIf Poker(i) >= &HC1 And Poker(i) <= &HCD Then
            Me.ForeColor = vbBlue
        ElseIf Poker(i) >= &HD1 And Poker(i) <= &HDD Then
            Me.ForeColor = &HFF00FF
        Else
            Me.ForeColor = &HFF&
        End If
        Print Hex(Poker(i)) & " ";
        If j Mod 13 = 0 Then Print
    Next i
    Print
    Print
End Sub

 

随机打乱数组算法-扑克洗牌

原文:http://www.cnblogs.com/xiii/p/4992827.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!