Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

read cards from online poker game

chaos75chaos75 Member Posts: 11
how could i get the cards delt in a online poker game into my program?

Comments

  • DrMartenDrMarten Member Posts: 748
    : how could i get the cards delt in a online poker game into my program?

    Why not just scan in a pack of cards?

    Regards,

    Dr M.

  • DrMartenDrMarten Member Posts: 748
    [b][red]This message was edited by DrMarten at 2006-4-27 13:37:0[/red][/b][hr]

    ======================================================================
    Hi,

    Note i have put the full code in here including the
    WINDOWS FORM DESIGNER GENERATE CODE section.

    Cut&Paste THE MAIN CODE to a completely empty CODE WINDOW.

    The first two sections are each a CLASS.

    These are named Card.Vb and DeckOfCards.Vb respectively.
    You need to CUT&PASTE these seperately.

    Go to PROJECT>>AddClass at the top of your window and name them as i have put them for this code to work.

    If you email me at e5117204@tees.ac.uk i will send you the full program and code (or/and the card images folder) as a zip file., otherwise supply your own pictures to match the filenames.

    1c=Ace of Clubs
    1d=Ace of Diamonds
    1s=Ace of Spades
    1h=Ace of Hearts

    ....and so on up to 11 for Jack, 12 for Queen and 13 for a King card.


    Regards,

    Dr M.
    ======================================================================

    [code]
    Public Class Card
    Private theCards As DeckOfCards
    Private cardImage As Image
    Private cardSuit As String
    Private cardValue As Integer
    Private cardX As Integer
    Private cardY As Integer
    Private cardWidth As Integer
    Private cardHeight As Integer

    Public Sub New(ByVal newCardImage As Image, _
    ByVal newCardSuit As String, _
    ByVal newCardX As Integer, _
    ByVal newCardY As Integer, _
    ByVal newCards As DeckOfCards)
    cardImage = newCardImage
    cardSuit = newCardSuit
    cardX = newCardX
    cardY = newCardY
    cardWidth = 48
    cardHeight = 70
    theCards = newCards
    theCards.Add(Me)
    End Sub
    'Methods
    Public Sub DisplaySuit(ByVal theSuit As String, _
    ByVal paper As Graphics)
    'Receives drawing area details from deckofcards class code
    Dim myImage As Image = cardImage
    'If card is of required suit
    If Me.cardSuit = theSuit Then
    'Display card on screen (within picture box)
    paper.DrawImage(myImage, cardX, cardY, Me.cardWidth, Me.cardHeight)
    End If
    End Sub
    Public Sub RemoveCards(ByVal theCards As DeckOfCards)
    theCards.Remove(Me)
    End Sub
    End Class
    [/code]

    [blue] Then for a DECK we do.>> [/blue]
    [code]
    Public Class DeckOfCards
    Private cardList As ArrayList
    'Constructor
    Public Sub New()
    cardList = New ArrayList
    End Sub
    'Methods
    Public Sub Add(ByVal aCard As Card)
    'Adds an individual card to the array
    cardList.Add(aCard)
    End Sub
    Public Sub Remove(ByVal aCard As Card)
    'Removes an individual card from the array
    cardList.Remove(aCard)
    End Sub
    Public Sub DisplaySuit(ByVal theSuit As String, _
    ByVal paper As Graphics)
    'Passes each card and drawing area details to card class
    Dim index As Integer = 0
    While index < cardList.Count
    CType(cardList.Item(index), Card).DisplaySuit(theSuit, paper)
    index = index + 1
    End While
    End Sub
    Public Sub RemoveCards(ByVal theCards As DeckOfCards)
    Dim index As Integer
    Dim theCount As Integer
    theCount = cardList.Count - 1
    For index = theCount To 0 Step -1
    CType(cardList.Item(index), Card).RemoveCards(theCards)
    Next
    End Sub
    Public ReadOnly Property Count() As Integer
    Get
    Return cardList.Count
    End Get
    End Property
    End Class
    [/code]

    [blue][b] MAIN CODE.
    [code]
    Imports Microsoft.VisualBasic.ControlChars

    Public Class frmCardsArrayList
    Inherits System.Windows.Forms.Form

    Private theDeck As DeckOfCards
    Private displayPaper As Graphics
    Private aCard As Card

    #Region " Windows Form Designer generated code "

    Public Sub New()
    MyBase.New()

    'This call is required by the Windows Form Designer.
    InitializeComponent()

    'Add any initialization after the InitializeComponent() call
    displayPaper = picDisplay.CreateGraphics
    theDeck = New DeckOfCards

    End Sub

    'Form overrides dispose to clean up the component list.
    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
    If disposing Then
    If Not (components Is Nothing) Then
    components.Dispose()
    End If
    End If
    MyBase.Dispose(disposing)
    End Sub

    'Required by the Windows Form Designer
    Private components As System.ComponentModel.IContainer

    'NOTE: The following procedure is required by the Windows Form Designer
    'It can be modified using the Windows Form Designer.
    'Do not modify it using the code editor.
    Friend WithEvents btnExit As System.Windows.Forms.Button
    Friend WithEvents picDisplay As System.Windows.Forms.PictureBox
    Friend WithEvents btnLoad As System.Windows.Forms.Button
    Friend WithEvents btnHearts As System.Windows.Forms.Button
    Friend WithEvents btnClubs As System.Windows.Forms.Button
    Friend WithEvents btnDiamonds As System.Windows.Forms.Button
    Friend WithEvents btnSpades As System.Windows.Forms.Button
    Friend WithEvents lblListCount As System.Windows.Forms.Label
    Friend WithEvents btnRemove As System.Windows.Forms.Button
    Private Sub InitializeComponent()
    Me.btnExit = New System.Windows.Forms.Button
    Me.btnHearts = New System.Windows.Forms.Button
    Me.picDisplay = New System.Windows.Forms.PictureBox
    Me.btnLoad = New System.Windows.Forms.Button
    Me.btnClubs = New System.Windows.Forms.Button
    Me.btnDiamonds = New System.Windows.Forms.Button
    Me.btnSpades = New System.Windows.Forms.Button
    Me.lblListCount = New System.Windows.Forms.Label
    Me.btnRemove = New System.Windows.Forms.Button
    Me.SuspendLayout()
    '
    'btnExit
    '
    Me.btnExit.BackColor = System.Drawing.Color.FromArgb(CType(255, Byte), CType(192, Byte), CType(255, Byte))
    Me.btnExit.Font = New System.Drawing.Font("Times New Roman", 12.0!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
    Me.btnExit.Location = New System.Drawing.Point(600, 120)
    Me.btnExit.Name = "btnExit"
    Me.btnExit.Size = New System.Drawing.Size(56, 26)
    Me.btnExit.TabIndex = 13
    Me.btnExit.Text = "Exit"
    '
    'btnHearts
    '
    Me.btnHearts.BackColor = System.Drawing.Color.FromArgb(CType(255, Byte), CType(192, Byte), CType(255, Byte))
    Me.btnHearts.Font = New System.Drawing.Font("Times New Roman", 12.0!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
    Me.btnHearts.Location = New System.Drawing.Point(240, 88)
    Me.btnHearts.Name = "btnHearts"
    Me.btnHearts.Size = New System.Drawing.Size(88, 26)
    Me.btnHearts.TabIndex = 14
    Me.btnHearts.Text = "Hearts"
    '
    'picDisplay
    '
    Me.picDisplay.Location = New System.Drawing.Point(5, 5)
    Me.picDisplay.Name = "picDisplay"
    Me.picDisplay.Size = New System.Drawing.Size(660, 75)
    Me.picDisplay.TabIndex = 15
    Me.picDisplay.TabStop = False
    '
    'btnLoad
    '
    Me.btnLoad.BackColor = System.Drawing.Color.FromArgb(CType(255, Byte), CType(192, Byte), CType(255, Byte))
    Me.btnLoad.Font = New System.Drawing.Font("Times New Roman", 12.0!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
    Me.btnLoad.Location = New System.Drawing.Point(440, 88)
    Me.btnLoad.Name = "btnLoad"
    Me.btnLoad.Size = New System.Drawing.Size(128, 26)
    Me.btnLoad.TabIndex = 16
    Me.btnLoad.Text = "Load Cards"
    '
    'btnClubs
    '
    Me.btnClubs.BackColor = System.Drawing.Color.FromArgb(CType(255, Byte), CType(192, Byte), CType(255, Byte))
    Me.btnClubs.Font = New System.Drawing.Font("Times New Roman", 12.0!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
    Me.btnClubs.Location = New System.Drawing.Point(336, 88)
    Me.btnClubs.Name = "btnClubs"
    Me.btnClubs.Size = New System.Drawing.Size(88, 26)
    Me.btnClubs.TabIndex = 17
    Me.btnClubs.Text = "Clubs"
    '
    'btnDiamonds
    '
    Me.btnDiamonds.BackColor = System.Drawing.Color.FromArgb(CType(255, Byte), CType(192, Byte), CType(255, Byte))
    Me.btnDiamonds.Font = New System.Drawing.Font("Times New Roman", 12.0!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
    Me.btnDiamonds.Location = New System.Drawing.Point(240, 120)
    Me.btnDiamonds.Name = "btnDiamonds"
    Me.btnDiamonds.Size = New System.Drawing.Size(88, 26)
    Me.btnDiamonds.TabIndex = 18
    Me.btnDiamonds.Text = "Diamonds"
    '
    'btnSpades
    '
    Me.btnSpades.BackColor = System.Drawing.Color.FromArgb(CType(255, Byte), CType(192, Byte), CType(255, Byte))
    Me.btnSpades.Font = New System.Drawing.Font("Times New Roman", 12.0!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
    Me.btnSpades.Location = New System.Drawing.Point(336, 120)
    Me.btnSpades.Name = "btnSpades"
    Me.btnSpades.Size = New System.Drawing.Size(88, 26)
    Me.btnSpades.TabIndex = 19
    Me.btnSpades.Text = "Spades"
    '
    'lblListCount
    '
    Me.lblListCount.Font = New System.Drawing.Font("Times New Roman", 12.0!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
    Me.lblListCount.Location = New System.Drawing.Point(8, 88)
    Me.lblListCount.Name = "lblListCount"
    Me.lblListCount.Size = New System.Drawing.Size(176, 56)
    Me.lblListCount.TabIndex = 20
    Me.lblListCount.Text = "List Count:"
    Me.lblListCount.TextAlign = System.Drawing.ContentAlignment.MiddleLeft
    '
    'btnRemove
    '
    Me.btnRemove.BackColor = System.Drawing.Color.FromArgb(CType(255, Byte), CType(192, Byte), CType(255, Byte))
    Me.btnRemove.Font = New System.Drawing.Font("Times New Roman", 12.0!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
    Me.btnRemove.Location = New System.Drawing.Point(440, 120)
    Me.btnRemove.Name = "btnRemove"
    Me.btnRemove.Size = New System.Drawing.Size(128, 26)
    Me.btnRemove.TabIndex = 21
    Me.btnRemove.Text = "Remove Cards"
    '
    'frmCardsArrayList
    '
    Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
    Me.BackColor = System.Drawing.Color.White
    Me.ClientSize = New System.Drawing.Size(672, 157)
    Me.Controls.Add(Me.btnRemove)
    Me.Controls.Add(Me.lblListCount)
    Me.Controls.Add(Me.btnSpades)
    Me.Controls.Add(Me.btnDiamonds)
    Me.Controls.Add(Me.btnClubs)
    Me.Controls.Add(Me.btnLoad)
    Me.Controls.Add(Me.btnHearts)
    Me.Controls.Add(Me.btnExit)
    Me.Controls.Add(Me.picDisplay)
    Me.Name = "frmCardsArrayList"
    Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen
    Me.Text = "Playing Cards Array List"
    Me.ResumeLayout(False)

    End Sub

    #End Region


    Private Sub btnHearts_Click(ByVal sender As System.Object, _
    ByVal e As System.EventArgs) _
    Handles btnHearts.Click
    'Pass appropriate suit and drawing area detail
    'to DeckOfCards class method DisplaySuit
    theDeck.DisplaySuit("hearts", displayPaper)
    End Sub
    Private Sub btnClubs_Click(ByVal sender As System.Object, _
    ByVal e As System.EventArgs) _
    Handles btnClubs.Click
    'Pass appropriate suit and drawing area detail
    'to DeckOfCards class method DisplaySuit
    theDeck.DisplaySuit("clubs", displayPaper)
    End Sub
    Private Sub btnDiamonds_Click(ByVal sender As System.Object, _
    ByVal e As System.EventArgs) _
    Handles btnDiamonds.Click
    'Pass appropriate suit and drawing area detail
    'to DeckOfCards class method DisplaySuit
    theDeck.DisplaySuit("diamonds", displayPaper)
    End Sub
    Private Sub btnSpades_Click(ByVal sender As System.Object, _
    ByVal e As System.EventArgs) _
    Handles btnSpades.Click
    'Pass appropriate suit and drawing area detail
    'to DeckOfCards class method DisplaySuit
    theDeck.DisplaySuit("spades", displayPaper)
    End Sub
    Private Sub btnLoad_Click(ByVal sender As System.Object, _
    ByVal e As System.EventArgs) _
    Handles btnLoad.Click
    'Declare local variables required
    'Card details
    Dim cardName As String
    Dim cardImage As Image
    Dim theSuits() As String = {"hearts", "clubs", "diamonds", "spades"}
    'For Loop control variables
    Dim theSuit As Integer
    Dim theRank As Integer

    'For each suit
    For theSuit = 0 To 3
    'For each card in the suit
    For theRank = 1 To 13
    'Identify card name.
    'Example: On FIRST inner loop - theSuit = 0; theRank = 1
    '1.ToString = "1"; theSuits(0).Substring(0,1) = "h"
    'Gives: "1" & "h" & ".png" = 1h.png
    cardName = theRank.ToString & theSuits(theSuit).Substring(0, 1) & ".png"
    'Get the required image from file
    cardImage = Image.FromFile(cardName)
    'Create a new instance of card.
    'Example: On SECOND inner loop:
    ' cardImage = 2h.png
    ' theSuits(theSuit) = theSuits(0) = hearts
    ' (theRank - 1) * 51 = 51 [cards X value]
    ' 5 [cards Y value]
    aCard = New Card(cardImage, theSuits(theSuit), (theRank - 1) * 51, 5, theDeck)
    Next
    Next
    'Display array list size
    lblListCount.Text = "List Count: " & theDeck.Count
    End Sub
    Private Sub btnRemove_Click(ByVal sender As System.Object, _
    ByVal e As System.EventArgs) _
    Handles btnRemove.Click
    'Remove all cards from array list
    theDeck.RemoveCards(theDeck)
    'Display array list size
    lblListCount.Text = "List Count: " & theDeck.Count
    'Repaint drawing area
    displayPaper.Clear(Color.White)
    End Sub
    Private Sub btnExit_Click(ByVal sender As System.Object, _
    ByVal e As System.EventArgs) _
    Handles btnExit.Click
    'Terminate program
    End
    End Sub
    End Class
    [/code]



    Regards,

    Dr M.





Sign In or Register to comment.