There are numerous poker games, play around with a game varies. Programming enthusiasts like to write some of the local multi-play poker games. Then, write your own poker game where to start? Poker game programming key has two points: First, draw poker face; Second, the rules of poker game algorithm. Beginner poker game programming enthusiasts from some simple games, started to borrow some of the existing resources. This paper borrows the Cards.dll and simple Windows comes with the 21 point game as an example, the initial method of poker programming.
one surface rendering
Cards.dll cards support Windows comes with games such as Solitaire (card game). If we know how to use Cards.dll the API function, then we will be able to play the same as the Windows built-in draw poker face. We need to use one of three basic functions: cdtInit,
lebron james jerseys, cdtDrawExt, and cdtTerm. And the need for two variables: width and height for the initialization function to initialize cdtInit. These interface functions are given below the statement and the parameter.
Private width As Integer = 0
Private height As Integer = 0
Declare Function cdtInit Lib \> Parameter Description: width, height back card default width and height, in units of pixels.
Declare Function cdtDrawExt Lib \Integer, _
ByVal mode As Integer, ByVal color As Long) As Boolean
Parameter Description: hdc (handle to a device context) handle;
x, y coordinates specify the upper left corner position cards;
dx, dy specify the width and height of a license;
card need to draw cards ,0-51 [A (flowers, boxes, hearts, spades), 2, ..., K]; 53-65 cards on the back;
mode specified drawing mode for the card is 0,
minnesota twins jerseys, card face down to 1;
color specifies the background color.
Declare Sub cdtTerm Lib \
We need to start calling the game on cards.dll cdtInit initialize, so that we can use other functions cards.dll the cdtDrawEx; each draw a card, we have to adjust a cdtDrawExt function; when we ended game, one call to end the cards.dll cdtTerm use.
II
algorithm rules of the game is blackjack players to get more points than the sum of the dealer, but more than twenty points will constitute a bust, and lose the bet. J, Q, K count 10 points, A can be considered 1 point or 11 points, total face value of the remaining points by a license. \The beginning of each player two cards, one out, a dark, where less than twenty points that option Bo card. If the first two cards are an option for the card pairs.
For simplicity, the program only two players in the Dealer and the Player, have invented a license, no betting process, does not record the win or lose, do not support the card and double points and so on. Blackjack game, a card as long as there are four attributes that: Face card size, Suit Cards suit, Count points, FaceUp card surface is up. So,
cheap kobe bryant jersey, here we do not use the Card and Card class structure.
Structure card
Public face As Integer
Public suit As Integer
Public count As Integer
Public faceup As Boolean
End Structure
the game starts, we must first take a the cards, then wash card, specify the brand from the beginning a few launching. Shuffling to obtain real time random number, random number generation with My.Computer.Clock.TickCount for seed.
Dim Deck () As card
Deck = New card (51) {}
Dim TopCard As Integer
Private 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 = t + dt Then Exit Do
Loop
End Sub
Private Sub Button1_Click (ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Button1.Visible = False
Label1.Text = \\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 (\. 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 (\
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 (\Refresh ()
delay (1000)
cdtDrawExt (MyBase.CreateGraphics.GetHdc, 220,
st louis rams jerseys, 10, 75, 100,
wholesale jerseys, (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 (\2
idcard = 2
Button2.Visible = True
Button3.Visible = True
End Sub
Private 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 (\If playerAce> = 1 Then
playerCount -= 10
playerAce -= 1
Label2.Text = playerCount.ToString
Label2.Refresh ()
Else
MsgBox (\Player loss! \Button3_Click (ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
Button2.Visible = False
Button3.Visible = False
dealERPlay ()
End Sub
Private Sub dealerPlay ()
Do
If dealerCount 21 And dealerAce = 1 Then dealerCount -= 10: dealerAce -= 1
If Deck (TopCard). face = 0 And dealerCount = 52 Then Shuffle (): MsgBox (\)
idcard + = 1
Else
Exit Do
End If
Loop
Label1.Text = dealerCount.ToString
Label1.Refresh ()
If dealerCount dealerCount Then
MsgBox (\> Else
MsgBox (\br> The results are shown below:
Third, practice and improve
the programming, we use a schema Card, Card of the Face value of (A, 2, ..., K) and Suit value (Club, Diamond, Heart, Spade) 0-12 and 0-3 with the values expressed. Also been simplified rules of the game, only two players, nor does the player attributes (such as: wealth, bet, the licensee, the licensee points, etc.) is described. Practice shows that the better approach is to use the Card, player classes, Face and Suit enumeration type with the data. These,
cheap barca jersey, we can gradually add the perfect programming.