dcsimg
Results 1 to 14 of 14

Thread: [RESOLVED] Blackjack is NOT Solitaire

  1. #1

    Thread Starter
    Addicted Member colossus1958's Avatar
    Join Date
    Oct 2011
    Location
    Florence, KY, USA
    Posts
    208

    Resolved [RESOLVED] Blackjack is NOT Solitaire

    I know the title is by no means news to anyone, but I haven't seen any good tutorials around for making a solitaire game (just Blackjack in the old Card Game Starter Kit). All anyone seems to be able to do is copy Klondike (or some existing game). I'm trying to create a game I invented, so verbatim code is not going to be available. I've already been able to create my Card and Deck classes, but for the life of me I cannot figure out how to display the cards on the board. I am currently working on the game logic (on paper) while I await inspiration on the card layout (or tips, hint, hint).

    If you know of a good source for what is bogging me down I would appreciate hearing about it. Please do not provide code yourselves. If I am given the right direction I can do it myself, but I feel like a blind man searching for a black cat in a coal cellar at midnight.LOL
    All it takes for evil to triumph is for good men to stop programming. (My apologies to Edmund Burke)

  2. #2
    I don't do your homework! opus's Avatar
    Join Date
    Jun 2000
    Location
    Good Old Europe
    Posts
    3,863

    Re: Blackjack is NOT Solitaire

    Did you, by any chance, use the search button of this forum?
    If you have created your deck already, I suggest you search for the needed graphic routines to display the image of one of your cards. If you do one, you can do all.
    You're welcome to rate this post!
    If your problem is solved, please use the Mark thread as resolved button


    Wait, I'm too old to hurry!

  3. #3
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    34,889

    Re: Blackjack is NOT Solitaire

    How will the cards be displayed? There appears to be a couple different alternatives, depending on what the layout should be. If they are all in stacks, then a series of pictureboxes would make most sense for holding the cards. If they have to display overlapped, then a picturebox may or may not be the most appropriate container, but if it is, it will be larger than a single card. The other alternative is to have a panel, or some such, on which to draw, and draw all the cards in whatever location they should be drawn. If they are all in stacks, this will be more work, and harder to work with, than the pictureboxes, but if they are overlapped, then this will probably be easier to deal with than the pictureboxes.
    My usual boring signature: Nothing

  4. #4

    Thread Starter
    Addicted Member colossus1958's Avatar
    Join Date
    Oct 2011
    Location
    Florence, KY, USA
    Posts
    208

    Re: Blackjack is NOT Solitaire

    I have multiple stacks of Pictureboxes. I can use BringToFront method to keep the top-most card available for viewing. What I don't see is a way to display the cards in the first place. I'll post the Card, Deck and Main classes below. Maybe you can see what I'm missing.

    Code:
    Namespace SpeedFramework
    
        'Private m_CardWidth As Integer = 72
        'Private m_CardHeight As Integer = 104
        'Private m_CardFace As Image
        'Private m_CardBack As Image
        'Private m_IsCardUp As Boolean
        'Private m_CardValue As FaceValue
        Public Enum Suit
            Hearts
            Spades
            Diamonds
            Clubs
        End Enum
        Public Enum FaceValue
            Ace = 14
            Two = 2
            Three = 3
            Four = 4
            Five = 5
            Six = 6
            Seven = 7
            Eight = 8
            Nine = 9
            Ten = 10
            Jack = 11
            Queen = 12
            King = 13
        End Enum
        Public Class Card
            Private _suitProp As Suit
            Private _faceValProp As FaceValue
            Private _isCardUpProp As Boolean
    
            Public Property Suit() As Suit
                Get
                    Return _suitProp
                End Get
                Set(value As Suit)
                    _suitProp = value
                End Set
            End Property
            Public Property FaceVal() As FaceValue
                Get
                    Return _faceValProp
                End Get
                Set(value As FaceValue)
                    _faceValProp = value
                End Set
            End Property
            Public Property IsCardUp() As Boolean
                Get
                    Return _isCardUpProp
                End Get
                Set(value As Boolean)
                    _isCardUpProp = value
                End Set
            End Property
            
            Public Sub New(ByVal suitProp As Suit, ByVal faceValProp As FaceValue, ByVal isCardUpProp As Boolean)
                Me._suitProp = suitProp
                Me._faceValProp = faceValProp
                Me._isCardUpProp = isCardUpProp
            End Sub
            Public Overloads Overrides Function ToString() As String
                Return _faceValProp.ToString & _suitProp.ToString
            End Function
        End Class
    End Namespace
    
    Imports System.Collections.Generic
    Namespace SpeedFramework
        Public Class Deck
            'creates a list of cards
            Protected Cards As New List(Of Card)
            
            Default Public ReadOnly Property _position(ByVal position As Integer) As Card
                Get
                    Return Cards(position)
                End Get
            End Property
            Public Sub New()
                For Each suit As Suit In System.Enum.GetValues(GetType(Suit))
                    For Each faceVal As FaceValue In System.Enum.GetValues(GetType(FaceValue))
                        Cards.Add(New Card(suit, faceVal, True))
                    Next
                Next
            End Sub
            Public Function Draw() As Card
                Dim card As Card = Cards(0)
                Cards.RemoveAt(0)
                Return card
            End Function
            Public Sub Shuffle()
                Dim rendom As New Random
                Dim i As Integer = 0
                While i < Cards.Count
                    Dim index1 As Integer = i
                    Dim index2 As Integer = rendom.Next
                    SwapCard(index1, index2)
                    i = i + 1
                End While
            End Sub
            Private Sub SwapCard(ByVal index1 As Integer, ByVal index2 As Integer)
                Dim card As Card = Cards(index1)
                Cards(index1) = Cards(index2)
                Cards(index2) = card
            End Sub
    
        End Class
    End Namespace
    
    Imports System.Collections.Generic
    Namespace SpeedFramework
        Public Class Deck
            'creates a list of cards
            Protected Cards As New List(Of Card)
            
            Default Public ReadOnly Property _position(ByVal position As Integer) As Card
                Get
                    Return Cards(position)
                End Get
            End Property
            Public Sub New()
                For Each suit As Suit In System.Enum.GetValues(GetType(Suit))
                    For Each faceVal As FaceValue In System.Enum.GetValues(GetType(FaceValue))
                        Cards.Add(New Card(suit, faceVal, True))
                    Next
                Next
            End Sub
            Public Function Draw() As Card
                Dim card As Card = Cards(0)
                Cards.RemoveAt(0)
                Return card
            End Function
            Public Sub Shuffle()
                Dim rendom As New Random
                Dim i As Integer = 0
                While i < Cards.Count
                    Dim index1 As Integer = i
                    Dim index2 As Integer = rendom.Next
                    SwapCard(index1, index2)
                    i = i + 1
                End While
            End Sub
            Private Sub SwapCard(ByVal index1 As Integer, ByVal index2 As Integer)
                Dim card As Card = Cards(index1)
                Cards(index1) = Cards(index2)
                Cards(index2) = card
            End Sub
    
        End Class
    End Namespace
    All it takes for evil to triumph is for good men to stop programming. (My apologies to Edmund Burke)

  5. #5
    Frenzied Member
    Join Date
    Oct 2012
    Location
    Tampa, FL
    Posts
    1,187

    Re: Blackjack is NOT Solitaire

    You mean you are not sure how to paint the cards? You are going to need to draw them yourself. For whichever card you pull for example, you would have to look at the enumeration you have set, and based on that enumeration, draw a club, heart, etc as well as the card number in onpaint and the font color (red,black).

    If I were doing this, I would not start out with a ton of existing pictureboxes. I would keep a list of picturebox and draw on the paint handler, or inherit them, (keep a list of them), and force them to paint based on properties set in your inherited picturebox class. I love going with the list to track items created, because it is easy to manage, add, remove at any point in time, just look at the list.

  6. #6
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    34,889

    Re: Blackjack is NOT Solitaire

    I'd go looking for bitmaps of existing cards. Jay is right, of course, but since I suck at drawing, there is no way that I'd try to do the art myself. I would guess that there are probably loads of image libraries out there for card decks, many of them probably free.

    Since you are using a picturebox, then displaying the card is just a matter of setting the proper image to the picturebox. If you draw them yourself, then you'd handle the Paint event, but if you can get an image library of cards (or make them all yourself in a drawing program), then you don't have to handle any event, just set the proper image for the picturebox.

    However, it sounds like you have a stack of cards with only the top one visible. If that's the case, you shouldn't be creating a picturebox for each one. Instead, create a single picturebox and swap images in and out. Maintaining a bunch of controls is going to be more costly than having just one control and changing what it displays.
    My usual boring signature: Nothing

  7. #7

    Thread Starter
    Addicted Member colossus1958's Avatar
    Join Date
    Oct 2011
    Location
    Florence, KY, USA
    Posts
    208

    Re: Blackjack is NOT Solitaire

    I'm not using GDI+, but JPG images stored in a folder in my startup path. I have tried painting to the form surface before and had more problems than I have now because I do not truly understand it. For instance, once I've painted an image on the form how do I move it from one place to another? Also, how do I get "cards" that are "underneath" other cards to appear when one is moved?
    All it takes for evil to triumph is for good men to stop programming. (My apologies to Edmund Burke)

  8. #8
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    34,889

    Re: Blackjack is NOT Solitaire

    Don't.

    You have a picturebox where the card is. Set the card image as the image for the picturebox. When you "move" the card, all you really do is swap the picturebox image for the image of the next card. The card objects all hold their own image, so when one is the "top" card, it puts its image into the picturebox. Nothing gets moved, and there is only the one picturebox displaying whichever card is on top.

    Of course, there would be no animation with that. The card would be one thing, then it would be another. Real animation would require considerably more graphics work, but that can wait for later...or not at all if you find it doesn't matter. After all, the human brain likes to add animation in places where there really isn't any, so it may look just fine.

    Drawing directly onto the form, or onto a panel on the form, would certainly require more work. You'd have to keep a list of Rectangles where the cards are located on the screen. It's certainly possible, but a bit harder to do.
    My usual boring signature: Nothing

  9. #9
    Frenzied Member
    Join Date
    Oct 2012
    Location
    Tampa, FL
    Posts
    1,187

    Re: Blackjack is NOT Solitaire

    Quote Originally Posted by Shaggy Hiker View Post
    but since I suck at drawing, there is no way that I'd try to do the art myself. I would guess that there are probably loads of image libraries out there for card decks, many of them probably free.
    Im not artsy fartsy myself, but I imagine you could have 4 pre-existing images, one for each suit.

    For example only, (this is from wikipedia, check on licensing) cut this into four images:
    Name:  600px-French_suits.svg.png
Views: 68
Size:  22.7 KB



    Then you can use the paint event and call e.graphics.drawimage (Depending on how many times you want to show the suit image) 3 times with the proper XY placement for the suit image, and then call drawstring for drawing the card number. I would not want to have 52 resource images, but I guess that would be a lot simpler and I probably need my head checked out lol.
    Last edited by jayinthe813; Jun 25th, 2014 at 06:02 PM.

  10. #10
    I don't do your homework! opus's Avatar
    Join Date
    Jun 2000
    Location
    Good Old Europe
    Posts
    3,863

    Re: Blackjack is NOT Solitaire

    If you managed to do the painting of one card in a specific position the step to show in while moving isn't real hard, but you do need that first step.
    I would use a single picturebox, replicating your realworld table where your cards are.
    You can draw the different "stacks" of cards in the correct position as you would lay the cards on the table.
    You want to see if cards are beneath the top one, then draw each cards in the "stack" with a sligth offset.
    .......
    I have more suggestions, but you need to do the first step.
    You're welcome to rate this post!
    If your problem is solved, please use the Mark thread as resolved button


    Wait, I'm too old to hurry!

  11. #11

    Thread Starter
    Addicted Member colossus1958's Avatar
    Join Date
    Oct 2011
    Location
    Florence, KY, USA
    Posts
    208

    Re: Blackjack is NOT Solitaire

    If I use a List of Images to hold the Bitmaps associated with the "Faces" of my cards, why does this declaration not produce an image:
    Code:
    Dim nDeck As New Deck
    nDeck.Shuffle()
    pbA1.Image = nDeck.Draw().Face
    Deck is the class name that contains the following items:

    Code:
    Protected Cards As New List(Of Card)
    Public imgsFaces As New List(Of Image)
    Public imgsBacks As New List(Of Image)
    
    Public Sub New()
        imgsFaces.AddRange(Main.FaceImages.Images.Cast(Of Image))
        imgsBacks.Add(My.Resources.CardBackBlue)
        imgsBacks.Add(My.Resources.CardBackGreen)
        imgsBacks.Add(My.Resources.CardBackRed)
        Cards.Add(New Card(imgsFaces(0), imgsBacks(0), True, 1))
        Cards.Add(New Card(imgsFaces(1), imgsBacks(0), True, 1))
        Cards.Add(New Card(imgsFaces(2), imgsBacks(0), True, 1))
        Cards.Add(New Card(imgsFaces(3), imgsBacks(0), True, 1))
        ... 'etc
    End Sub
    
    Public Function Draw() As Card
        Dim card As Card = Cards(0)
        Cards.RemoveAt(0)
        Return card
    End Function
    What am I missing?
    All it takes for evil to triumph is for good men to stop programming. (My apologies to Edmund Burke)

  12. #12
    I don't do your homework! opus's Avatar
    Join Date
    Jun 2000
    Location
    Good Old Europe
    Posts
    3,863

    Re: Blackjack is NOT Solitaire

    ? There is no code that does actual drawing, the Function Draw i only returning a card instanc.
    You're welcome to rate this post!
    If your problem is solved, please use the Mark thread as resolved button


    Wait, I'm too old to hurry!

  13. #13

    Thread Starter
    Addicted Member colossus1958's Avatar
    Join Date
    Oct 2011
    Location
    Florence, KY, USA
    Posts
    208

    Re: Blackjack is NOT Solitaire

    That's OK everybody. I figured out what was wrong (kinda). I'll post the complete code when I get through with it and you can trash it (LOL).
    All it takes for evil to triumph is for good men to stop programming. (My apologies to Edmund Burke)

  14. #14
    I don't do your homework! opus's Avatar
    Join Date
    Jun 2000
    Location
    Good Old Europe
    Posts
    3,863

    Re: [RESOLVED] Blackjack is NOT Solitaire

    It looks to me as if you are using a similar Card example to the one I started with (the code post #4). In post #11 it looks like yopu did some adoptions.
    All you have so far is a ordered list of cards, from which you the functions Draw always takes to topmost element (index 0). In your case the first draw would always show imgsFaces(0), i you would paint it somewhere.
    In order to get different cards you need to use the Shuffle Function of the original code before you tra to get the first card!
    Additionally, if you are using the Card-class from post#4 ,the New Sub doesn't take Images!!
    You're welcome to rate this post!
    If your problem is solved, please use the Mark thread as resolved button


    Wait, I'm too old to hurry!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width