J、Q、K算10点,A可算1点或11点,其余按牌面值计点数。
“BlackJack”是由一张A和J、Q、K或10所组成。
开始时每人发两张牌,一张明,一张暗,凡点数不足二十一点,可选择博牌。
如果首两张牌是对子可选择分牌。
为简化起见,程序中只有两个玩家Dealer和Player,都发明牌,无下注过程,不记录输赢,不支持分牌和加倍等。
二十一点游戏中,一张牌只要有四个属性说明:Face牌面大小、Suit牌面花色,Count点数,FaceUp牌面是否向上。
因此,这里我们不用Card 类而用Card结构。
Structure cardPublic face As IntegerPublic suit As IntegerPublic count As IntegerPublic faceup As BooleanEnd Structure 游戏开始时,我们首先要取一副牌,然后将牌洗好,指定从第几张牌开始发起。
洗牌时为取得真正的随机数,用My.Computer.Clock.TickCount作产生随机数的种子。
Dim Deck() As cardDeck = New card(51) {}Dim TopCard As IntegerPrivate Sub GetDeck() Dim i, j As Integer For i = 0 To 3 For j = 0 To 12 Deck(j + 13 * i).face = j Deck(j + 13 * i).suit = i If j 10 Then Deck(j + 13 * i).count = j + 1 Else Deck(j + 13 * i).count = 10 End If Deck(j + 13 * i).faceup = False Next NextEnd SubPrivate Sub Shuffle() Dim i, j, k As Integer Dim tc As card For k = 1 To 500 i = CType(My.Computer.Clock.TickCount * Rnd(), Integer) Mod 52 j = CType(Int(Rnd() * 52), Integer) tc = Deck(i) Deck(i) = Deck(j) Deck(j) = tc Next topcard = 0End Sub游戏界面中,我们设置三个命令按钮,两个标签。
Button1为“发牌”、Button2为“要牌”、Button3为“停牌”。
Label1记录庄家点数,Label2记录玩家点数。
游戏过程中,如果一副牌发完,立即重洗一副牌,并弹出消息对话框告知。
以下列出三个按钮单击事件代码。
其中庄家游戏过程中,为简化起见,未曾使用游戏技巧。
Dim playerCount As Integer = 0Dim playerAce As Integer = 0Dim dealerCount As Integer = 0Dim dealerAce As Integer = 0Dim ipcard, idcard As IntegerPrivate Sub delay(ByVal dt As Integer) Dim t As Integer t = My.Computer.Clock.TickCount Do If My.Computer.Clock.TickCount = t + dt Then Exit Do LoopEnd SubPrivate Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Button1.Visible = False Label1.Text=”” Label2.Text=”” Label1.Refresh() Label2.Refresh() MyBase.CreateGraphics.Clear(Color.DarkGreen) dealerAce = 0 playerAce = 0 dealerCount = 0 playerCount = 0 cdtDrawExt(MyBase.CreateGraphics.GetHdc, 200, 200, 75, 100, (Deck(TopCard).face * 4 + Deck(TopCard).suit), 0, 0) playerCount += Deck(TopCard).count If Deck(TopCard).face = 0 Then playerCount += 10 : playerAce += 1 TopCard += 1 If TopCard = 52 Then Shuffle() : MsgBox("NEW DECK!") Label2.Text = playerCount.ToString Label2.Refresh() delay(1000) cdtDrawExt(MyBase.CreateGraphics.GetHdc, 200, 10, 75, 100, (Deck(TopCard).face * 4 + Deck(TopCard).suit), 0, 0) dealerCount += Deck(TopCard).count If Deck(TopCard).face = 0 Then dealerCount += 10 : dealerAce += 1 TopCard += 1 If TopCard = 52 Then Shuffle() : MsgBox("NEW DECK!") Label1.Text = dealerCount.ToString Label1.Refresh() delay(1000) cdtDrawExt(MyBase.CreateGraphics.GetHdc, 220, 200, 75, 100, (Deck(TopCard).face * 4 + Deck(TopCard).suit), 0, 0) playerCount += Deck(TopCard).count If Deck(TopCard).face = 0 And playerAce = 0 Then playerCount += 10 : playerAce += 1 TopCard += 1 If TopCard = 52 Then Shuffle() : MsgBox("NEW DECK!") Label2.Text = playerCount.ToString Label2.Refresh() delay(1000) cdtDrawExt(MyBase.CreateGraphics.GetHdc, 220, 10, 75, 100, (Deck(TopCard).face * 4 + Deck(TopCard).suit), 0, 0) dealerCount += Deck(TopCard).count If Deck(TopCard).face = 0 And dealerAce = 0 Then dealerCount += 10 : dealerAce += 1 TopCard += 1 If TopCard = 52 Then Shuffle() : MsgBox("NEW DECK!") Label1.Text = dealerCount.ToString Label1.Refresh() delay(1000) ipcard = 2 idcard = 2 Button2.Visible = True Button3.Visible = TrueEnd SubPrivate Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click cdtDrawExt(MyBase.CreateGraphics.GetHdc, 200 + 20 * ipcard, 200, 75, 100, (Deck(TopCard).face * 4 + Deck(TopCard).suit), 0, 0) playerCount += Deck(TopCard).count If Deck(TopCard).face = 0 Then playerCount += 10 : playerAce += 1 TopCard += 1 If TopCard = 52 Then Shuffle() : MsgBox("NEW DECK!") ipcard += 1 Label2.Text = playerCount.ToString Label2.Refresh() If playerCount 21 Then If playerAce = 1 Then playerCount -= 10 playerAce -= 1 Label2.Text = playerCount.ToString Label2.Refresh() Else MsgBox("player loss!") Button1.Visible = True Button2.Visible = False Button3.Visible = False End If End IfEnd SubPrivate Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click Button2.Visible = False Button3.Visible = False dealerPlay()End SubPrivate Sub dealerPlay() Do If dealerCount 17 Then cdtDrawExt(MyBase.CreateGraphics.GetHdc, 200 + 20 * idcard, 10, 75, 100, (Deck(TopCard).face * 4 + Deck(TopCard).suit), 0, 0) dealerCount += Deck(TopCard).count If dealerCount 21 And dealerAce = 1 Then dealerCount -= 10 : dealerAce -= 1 If Deck(TopCard).face = 0 And dealerCount = 11 Then dealerCount += 10 TopCard += 1 If TopCard = 52 Then Shuffle() : MsgBox("NEW DECK!") idcard += 1 Else Exit Do End IfLoopLabel1.Text = dealerCount.ToStringLabel1.Refresh()If dealerCount = 21 Then If playerCount dealerCount Then MsgBox("player win!") Else MsgBox("Dealer win!") End IfElse MsgBox("player win!")End IfButton1.Visible = TrueButton2.Visible = FalseButton3.Visible = FalseEnd Sub (转自www.***.com) 21点游戏vb源代码 请高手帮忙啊 菲律宾博彩业,金鲨银鲨游戏,打鱼游戏机 阿布扎比博彩公司,网上博彩网站 维也纳博彩公司,网上博彩网站 布拉格博彩公司,网上博彩网站 巴拿马城博彩公司,网上博彩网站 弗里敦博彩公司,网上博彩网站 都柏林博彩公司,网上博彩网站 第比利斯博彩公司,网上博彩网站 科伦坡博彩公司,网上博彩网站 里加博彩公司,网上博彩网站 维尔纽斯 博彩公司,网上博彩网站 洛美博彩公司,网上博彩网站 萨格勒布博彩公司,网上博彩网站 巴尼亚卢卡博彩公司,网上博彩网站