Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. How to flip/turn cards over

How to flip/turn cards over

Scheduled Pinned Locked Moved Visual Basic
tutorialdatabasegame-devlounge
17 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Y Offline
    Y Offline
    ymilan
    wrote on last edited by
    #1

    I have a solitaire game and got drag and drop to work.   The thing is the random cards display every other card with a different backing to simulate the back of the card.   I would like the player that when they move or click the backed card, it turns over to it's original card.   Here's an example of my code:   Note I set 001h as an example to test. Private Sub Image1_MouseDown(Index As Integer, Button As Integer, Shift As Integer, _ X As Single, Y As Single)          Image1(Index).Drag vbBeginDrag End Sub Private Sub Image1_MouseMove(Index As Integer, Button As Integer, Shift As Integer, _ X As Single, Y As Single) If Image1(Index).Picture = LoadPicture("C:\Program1\Back.gif") Then Image1(Index).Picture = LoadPicture("C:\Program1\001h.gif") MsgBox ("ok") End If End Sub

    K L 2 Replies Last reply
    0
    • Y ymilan

      I have a solitaire game and got drag and drop to work.   The thing is the random cards display every other card with a different backing to simulate the back of the card.   I would like the player that when they move or click the backed card, it turns over to it's original card.   Here's an example of my code:   Note I set 001h as an example to test. Private Sub Image1_MouseDown(Index As Integer, Button As Integer, Shift As Integer, _ X As Single, Y As Single)          Image1(Index).Drag vbBeginDrag End Sub Private Sub Image1_MouseMove(Index As Integer, Button As Integer, Shift As Integer, _ X As Single, Y As Single) If Image1(Index).Picture = LoadPicture("C:\Program1\Back.gif") Then Image1(Index).Picture = LoadPicture("C:\Program1\001h.gif") MsgBox ("ok") End If End Sub

      K Offline
      K Offline
      Kschuler
      wrote on last edited by
      #2

      You didn't ask a question.

      Y 1 Reply Last reply
      0
      • Y ymilan

        I have a solitaire game and got drag and drop to work.   The thing is the random cards display every other card with a different backing to simulate the back of the card.   I would like the player that when they move or click the backed card, it turns over to it's original card.   Here's an example of my code:   Note I set 001h as an example to test. Private Sub Image1_MouseDown(Index As Integer, Button As Integer, Shift As Integer, _ X As Single, Y As Single)          Image1(Index).Drag vbBeginDrag End Sub Private Sub Image1_MouseMove(Index As Integer, Button As Integer, Shift As Integer, _ X As Single, Y As Single) If Image1(Index).Picture = LoadPicture("C:\Program1\Back.gif") Then Image1(Index).Picture = LoadPicture("C:\Program1\001h.gif") MsgBox ("ok") End If End Sub

        L Offline
        L Offline
        Luc Pattyn
        wrote on last edited by
        #3

        In a card game I would keep all cards in memory, rather than reading them from disk every time. :)

        Luc Pattyn [Forum Guidelines] [My Articles]


        DISCLAIMER: this message may have been modified by others; it may no longer reflect what I intended, and may contain bad advice; use at your own risk and with extreme care.


        Y 1 Reply Last reply
        0
        • K Kschuler

          You didn't ask a question.

          Y Offline
          Y Offline
          ymilan
          wrote on last edited by
          #4

          I want to know how to flip the cards with backing.gif over to the original card in the random pile.   I have one face up, the next one face down, etc.

          K D 2 Replies Last reply
          0
          • Y ymilan

            I want to know how to flip the cards with backing.gif over to the original card in the random pile.   I have one face up, the next one face down, etc.

            K Offline
            K Offline
            Kschuler
            wrote on last edited by
            #5

            Okay. So wouldn't that mean you have a card with the back image and when you want it to flip you show the front image?

            Y 1 Reply Last reply
            0
            • Y ymilan

              I want to know how to flip the cards with backing.gif over to the original card in the random pile.   I have one face up, the next one face down, etc.

              D Offline
              D Offline
              Dave Kreskowiak
              wrote on last edited by
              #6

              You'd have to draw each frame the animation yourself. That's all it is. A series of still images that give the illusion of flipping a card.

              A guide to posting questions on CodeProject[^]
              Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
                   2006, 2007, 2008

              Y 1 Reply Last reply
              0
              • K Kschuler

                Okay. So wouldn't that mean you have a card with the back image and when you want it to flip you show the front image?

                Y Offline
                Y Offline
                ymilan
                wrote on last edited by
                #7

                The card with the back image is from the loadpicture("aaaa.gif") but the original picture bitmap formed in design view is the suit card.

                1 Reply Last reply
                0
                • D Dave Kreskowiak

                  You'd have to draw each frame the animation yourself. That's all it is. A series of still images that give the illusion of flipping a card.

                  A guide to posting questions on CodeProject[^]
                  Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
                       2006, 2007, 2008

                  Y Offline
                  Y Offline
                  ymilan
                  wrote on last edited by
                  #8

                  Trying to understand completely what you are saying: Basically, I have random cards of all suits on the left of the form.   Each other card has a back.gif to show the back of the card.   Each card is in an array of 52 cards.   When a user clicks the backing card, I want the let's say queen of hearts to show up, hence image1(12), that picture; before they drag the card. I tried this with If image1(index).picture = loadpicture("C:\backing.gif") Then image1(12).picture = loadpicture("C:\queenhearts.gif") and so forth; I would write all the images and set them to the correct gifs.   At runtime, nothing worked when I clicked those cards.... I even thought of trying image1_click(Index As Integer), but that didn't work either. Any ideas on how to within the same routine, to turn the cards or set them to the proper gif when the user clicks on them?   Seems so simple, but I'm still confused.

                  1 Reply Last reply
                  0
                  • L Luc Pattyn

                    In a card game I would keep all cards in memory, rather than reading them from disk every time. :)

                    Luc Pattyn [Forum Guidelines] [My Articles]


                    DISCLAIMER: this message may have been modified by others; it may no longer reflect what I intended, and may contain bad advice; use at your own risk and with extreme care.


                    Y Offline
                    Y Offline
                    ymilan
                    wrote on last edited by
                    #9

                    and pardon my less knowledge, but how would you do this?

                    L 1 Reply Last reply
                    0
                    • Y ymilan

                      and pardon my less knowledge, but how would you do this?

                      L Offline
                      L Offline
                      Luc Pattyn
                      wrote on last edited by
                      #10

                      Start a collection of images (array, List, Dictionary, ...) and load it using Image.FromStream at the start of the app. :)

                      Luc Pattyn [Forum Guidelines] [My Articles]


                      DISCLAIMER: this message may have been modified by others; it may no longer reflect what I intended, and may contain bad advice; use at your own risk and with extreme care.


                      Y 1 Reply Last reply
                      0
                      • L Luc Pattyn

                        Start a collection of images (array, List, Dictionary, ...) and load it using Image.FromStream at the start of the app. :)

                        Luc Pattyn [Forum Guidelines] [My Articles]


                        DISCLAIMER: this message may have been modified by others; it may no longer reflect what I intended, and may contain bad advice; use at your own risk and with extreme care.


                        Y Offline
                        Y Offline
                        ymilan
                        wrote on last edited by
                        #11

                        I already have an array of images in design view; it would be redundant to load them, wouldn't it?

                        L 1 Reply Last reply
                        0
                        • Y ymilan

                          I already have an array of images in design view; it would be redundant to load them, wouldn't it?

                          L Offline
                          L Offline
                          Luc Pattyn
                          wrote on last edited by
                          #12

                          I don't know as I am not familiar with your entire code base. However it does not match well with the code shown in your original post. :)

                          Luc Pattyn [Forum Guidelines] [My Articles]


                          DISCLAIMER: this message may have been modified by others; it may no longer reflect what I intended, and may contain bad advice; use at your own risk and with extreme care.


                          Y 1 Reply Last reply
                          0
                          • L Luc Pattyn

                            I don't know as I am not familiar with your entire code base. However it does not match well with the code shown in your original post. :)

                            Luc Pattyn [Forum Guidelines] [My Articles]


                            DISCLAIMER: this message may have been modified by others; it may no longer reflect what I intended, and may contain bad advice; use at your own risk and with extreme care.


                            Y Offline
                            Y Offline
                            ymilan
                            wrote on last edited by
                            #13

                            You're right; I changed some of the code.   I'm thinking that on mousedown event, somewhere I would flip the backing cards over when the user presses the mouse down on the card.   How would I do that?   Here it is: Option Explicit Public Sub FormLoad() End Sub Private Sub Exit_Click()       MsgBox ("Thank you for playing.   Good Bye.") End End Sub Private Sub Start_Click()       Image2.Visible = False       Dim Selected As Boolean       Dim arrDeck(52)       Dim Cardcount As Integer       Dim Counter As Integer       Dim Index As Integer                Do While Cardcount <= 52             arrDeck(Cardcount) = Cardcount             Cardcount = Cardcount + 1       Loop       Dim swap As Integer       Dim posn1 As Integer       Dim posn2 As Integer       Randomize       For swap = 0 To 50          ' Get two random positions          posn1 = Int(52 * Rnd)          posn2 = Int(52 * Rnd)          ' Swap pictures at these positions             If (posn1 <> posn2) Then                   KingH(0).Picture = Image1(posn1).Picture                   KingH(0).Tag = Image1(posn1).Tag                   Image1(posn1).Picture = Image1(posn2).Picture                   Image1(posn1).Tag = Image1(posn2).Tag                   Image1(posn2).Picture = KingH(0).Picture                   Image1(posn2).Tag = KingH(0).Tag             End If       Next swap Start_Game.Refresh             For Counter = 0 To 50     &nbs

                            L 1 Reply Last reply
                            0
                            • Y ymilan

                              You're right; I changed some of the code.   I'm thinking that on mousedown event, somewhere I would flip the backing cards over when the user presses the mouse down on the card.   How would I do that?   Here it is: Option Explicit Public Sub FormLoad() End Sub Private Sub Exit_Click()       MsgBox ("Thank you for playing.   Good Bye.") End End Sub Private Sub Start_Click()       Image2.Visible = False       Dim Selected As Boolean       Dim arrDeck(52)       Dim Cardcount As Integer       Dim Counter As Integer       Dim Index As Integer                Do While Cardcount <= 52             arrDeck(Cardcount) = Cardcount             Cardcount = Cardcount + 1       Loop       Dim swap As Integer       Dim posn1 As Integer       Dim posn2 As Integer       Randomize       For swap = 0 To 50          ' Get two random positions          posn1 = Int(52 * Rnd)          posn2 = Int(52 * Rnd)          ' Swap pictures at these positions             If (posn1 <> posn2) Then                   KingH(0).Picture = Image1(posn1).Picture                   KingH(0).Tag = Image1(posn1).Tag                   Image1(posn1).Picture = Image1(posn2).Picture                   Image1(posn1).Tag = Image1(posn2).Tag                   Image1(posn2).Picture = KingH(0).Picture                   Image1(posn2).Tag = KingH(0).Tag             End If       Next swap Start_Game.Refresh             For Counter = 0 To 50     &nbs

                              L Offline
                              L Offline
                              Luc Pattyn
                              wrote on last edited by
                              #14

                              Hi, I have several comments: 1.

                              For Counter = 0 To 50
                              Counter = Counter + 1
                              Image1(Counter).Picture = LoadPicture("C:\Program1\Back.gif")
                              Next Counter

                              you are incrementing Counter twice: once explicitly, once implicitly in the For statement. If that is what you want, you should adapt the for statement and add "Step 2" for clarity. And you are loading that image from file over and over. 2. I would keep the state of the game in my own data structures, independent of the GUI; I might choose to have an integer array storing the card numbers (0-51), a bool array storing a front/back flag, etc. Then perform the game rules on that data, and when something changes update the GUI. So e.g. the initial card shuffle would occur in data arrays, not in PictureBoxes. 3. I would keep all the card images in a single Image array, and load that once at app start. You seem to get all cards loaded in the PictureBoxes through the Designer (that is a lot of unnecessary work, such things are much easier in code). :)

                              Luc Pattyn [Forum Guidelines] [My Articles]


                              DISCLAIMER: this message may have been modified by others; it may no longer reflect what I intended, and may contain bad advice; use at your own risk and with extreme care.


                              Y 1 Reply Last reply
                              0
                              • L Luc Pattyn

                                Hi, I have several comments: 1.

                                For Counter = 0 To 50
                                Counter = Counter + 1
                                Image1(Counter).Picture = LoadPicture("C:\Program1\Back.gif")
                                Next Counter

                                you are incrementing Counter twice: once explicitly, once implicitly in the For statement. If that is what you want, you should adapt the for statement and add "Step 2" for clarity. And you are loading that image from file over and over. 2. I would keep the state of the game in my own data structures, independent of the GUI; I might choose to have an integer array storing the card numbers (0-51), a bool array storing a front/back flag, etc. Then perform the game rules on that data, and when something changes update the GUI. So e.g. the initial card shuffle would occur in data arrays, not in PictureBoxes. 3. I would keep all the card images in a single Image array, and load that once at app start. You seem to get all cards loaded in the PictureBoxes through the Designer (that is a lot of unnecessary work, such things are much easier in code). :)

                                Luc Pattyn [Forum Guidelines] [My Articles]


                                DISCLAIMER: this message may have been modified by others; it may no longer reflect what I intended, and may contain bad advice; use at your own risk and with extreme care.


                                Y Offline
                                Y Offline
                                ymilan
                                wrote on last edited by
                                #15

                                Thanks for the expert comments: Questions: 1.   I would like to keep what I have done in design view instead of writing more code to load those pics.   I have Dimmed an array at the beginning to create the card deck; I cannot redundantly load the image array twice; the compiler won't let me; says it's already there. 2.   In response to your #1, I wanted every other card to have the back.gif, so in essence it is flipped over. Am I actually loading the same image twice with my code?   I thought using the For statement would at least start the counting from 0-51, but I wanted the counter to change the back of every other card.   Your comment about boolean flags makes sense.   I'm not asking you to write my code, but this isn't for a school assignment; it is a birthday present to my Mom, so help on boolean code would be very much appreciated.   Hence, perhaps I can have a face up as a boolean, and a face down.   How and where would I implement that; at loadform? Much appreciation in advance.

                                L 1 Reply Last reply
                                0
                                • Y ymilan

                                  Thanks for the expert comments: Questions: 1.   I would like to keep what I have done in design view instead of writing more code to load those pics.   I have Dimmed an array at the beginning to create the card deck; I cannot redundantly load the image array twice; the compiler won't let me; says it's already there. 2.   In response to your #1, I wanted every other card to have the back.gif, so in essence it is flipped over. Am I actually loading the same image twice with my code?   I thought using the For statement would at least start the counting from 0-51, but I wanted the counter to change the back of every other card.   Your comment about boolean flags makes sense.   I'm not asking you to write my code, but this isn't for a school assignment; it is a birthday present to my Mom, so help on boolean code would be very much appreciated.   Hence, perhaps I can have a face up as a boolean, and a face down.   How and where would I implement that; at loadform? Much appreciation in advance.

                                  L Offline
                                  L Offline
                                  Luc Pattyn
                                  wrote on last edited by
                                  #16

                                  I don't understand your game nor your code, however I am convinced I would program card games quite differently, as I explained. Obviously you are entitled to your way of doing it, I won't be able to help you much, I wish you success. :)

                                  Luc Pattyn [Forum Guidelines] [My Articles]


                                  DISCLAIMER: this message may have been modified by others; it may no longer reflect what I intended, and may contain bad advice; use at your own risk and with extreme care.


                                  Y 1 Reply Last reply
                                  0
                                  • L Luc Pattyn

                                    I don't understand your game nor your code, however I am convinced I would program card games quite differently, as I explained. Obviously you are entitled to your way of doing it, I won't be able to help you much, I wish you success. :)

                                    Luc Pattyn [Forum Guidelines] [My Articles]


                                    DISCLAIMER: this message may have been modified by others; it may no longer reflect what I intended, and may contain bad advice; use at your own risk and with extreme care.


                                    Y Offline
                                    Y Offline
                                    ymilan
                                    wrote on last edited by
                                    #17

                                    Thanks, but it works so far....maybe I did too much in design view.

                                    1 Reply Last reply
                                    0
                                    Reply
                                    • Reply as topic
                                    Log in to reply
                                    • Oldest to Newest
                                    • Newest to Oldest
                                    • Most Votes


                                    • Login

                                    • Don't have an account? Register

                                    • Login or register to search.
                                    • First post
                                      Last post
                                    0
                                    • Categories
                                    • Recent
                                    • Tags
                                    • Popular
                                    • World
                                    • Users
                                    • Groups