Pairs (matching card game) vb.net 2010
Pairs (matching card game) vb.net 2010
Pairs (matching card game) vb.net 2010
Pairs (matching card game) vb.net 2010
Pairs (matching card game) vb.net 2010
Pairs (matching card game) vb.net 2010 Pairs (matching card game) vb.net 2010 Pairs (matching card game) vb.net 2010 Pairs (matching card game) vb.net 2010 Pairs (matching card game) vb.net 2010 Pairs (matching card game) vb.net 2010 Pairs (matching card game) vb.net 2010 Pairs (matching card game) vb.net 2010
Pairs (matching card game) vb.net 2010 Pairs (matching card game) vb.net 2010
Pairs (matching card game) vb.net 2010
Go Back  Xtreme Visual Basic Talk > > > Pairs (matching card game) vb.net 2010


Reply
 
Thread Tools Display Modes
  #1  
Old 04-19-2012, 03:35 AM
jackandjones120 jackandjones120 is offline
Newcomer
 
Join Date: Apr 2012
Posts: 1
Default Pairs (matching card game) vb.net 2010


Hello, i need to make a matching card game in VB 2010. i have generated my cards but now need to show the cards for 10 secs then change the cards to (AppPath & "\Cards\red.png"). then when a user clicks on the card the card will flip over.*How would i set a timer to turn all my cards into*(AppPath & "\Cards\red.png") after 10 secsbut still have the values from the array and when i click the cards they flip over (from red card to numbered card)
Code:
  Private Sub Place()
    Dim Counter As Integer = 1
    For Row As Integer = 1 To Int_Grid_Size
      For Column As Integer = 1 To Int_Grid_Size
        n = memory(Row, Column)
        My_PicBox(Row, Column) = New PictureBox()
        My_PicBox(Row, Column).SetBounds(My_Location(Column).X, My_Location(Row).Y, Int_Width, Int_Height)
        My_PicBox(Row, Column).Tag = Counter
        Counter = Counter + 1
        My_PicBox(Row, Column).Visible = True
        ' Creates the link to the Event AddHandler 
        My_PicBox(Row, Column).Click, AddressOf OnPictureBoxClick
        ' Puts the checkbox on the screen at the stated location 
        My_PicBox(Row, Column).SizeMode = PictureBoxSizeMode.StretchImage
        My_PicBox(Row, Column).Image = Image.FromFile(AppPath & "\Cards\" & n & ".png")
        CardPanel.Controls.Add(My_PicBox(Row, Column))
        My_PicBox(Row, Column).Image = Image.FromFile(AppPath & "\Cards\red.png")
      Next
    Next
  End Sub

Last edited by passel; 04-19-2012 at 11:13 AM. Reason: Lost newline indicators in the code window somehow (1 very long line), I reformatted it
Reply With Quote
  #2  
Old 04-19-2012, 11:10 AM
passel's Avatar
passelPairs (matching card game) vb.net 2010 passel is offline
Sinecure Expert

Super Moderator
* Guru *
 
Join Date: Jun 2003
Location: Upstate New York, usa
Posts: 8,028
Default

If you want to make the game interesting, I would assume at some point you will need to randomly place the cards, not just add them in numerical order.

There are so many ways to approach this, it isn't funny.
Most likely, if I were doing this, I would not use all those pictureboxes.
You could load all the images into an array of bitmaps.
For simplicity, rather than create your own control, you could use one picturebox to be your "table" where you display the matrix of cards.
You could set up an array, which you could shuffle the values around to randomize the deck and where things are displayed. The contents of the array would just be the index of where the card image is loaded in the array of bitmaps.
You create a structure to hold the card index and a boolean value indicating whether the card is face up or face down, so that your "rendering" routine would used the image from the bitmap array, or the back image when drawing the card (DrawImage is the method to use, by the way).
You should do the drawing in the Paint Event of the "table".
The code in the Paint Event (or called from the paint event and passed the graphics object), would use the graphics object (e.Graphics) to draw all the cards in their position based on the index and "face down" boolean.

Another option, is to use the index in some manner to serve as the "boolean" as well as the index, then you wouldn't need a structure, if you're not "into" that yet.
Eg. If you set the index to the negative of the index, this could indicate the card is face down, otherwise it is faceup.
When you loop through the cards if the value is less than 0, then draw the back, else use the number to index into the table and draw that image.

As for waiting 10 seconds just usa a timer control. Simply (assuming you've loaded the images and setup up your scrambled array to index into the images), just invalidate your "table" picturebox, whose paint event should redraw the cards in their current faceup state. Set the timer interval to 10000 (10 seconds) and start the timer (start or Enabled = True). Ten seconds later, when the timer fires, in its tick event disable the timer (stop or enabled = false) set all the indexes in your lookup array to the negative of themselves (if you went with that approach), or set all the booleans in your structure to the "face down" state, then invalidate your "table" picture, which should redraw all the cards in their current state (face down).

If you're drawing all the cards, then you would only have the one click event handler, with a click on the "table". You would take the X,Y values and determine which card was clicked on, check to see if the card is face down, and if so, then change it to face up.
You'll need all the logic to keep track if it is the first card, or second card and the logic of when to turn the cards back over if they don't match, etc.... , but that's a given.
__________________
There Is An Island Of Opportunity In The Middle of Every Difficulty.
Miss That, Though, And You're Pretty Much Doomed.
Reply With Quote
  #3  
Old 04-19-2012, 11:56 AM
DrPunk's Avatar
DrPunkPairs (matching card game) vb.net 2010 DrPunk is offline
Senior Contributor

* Expert *
 
Join Date: Apr 2003
Location: Never where I want to be
Posts: 1,403
Default

I think a common mistake that people make is seeing the visual interface of the game and then trying to base the logic on that visual representation.

Instead, there should be logic for the game and then the visual representation just displays the current state of the game (often referred to as model, view, controller).

So you come up with the structures to allow your game to work, you get the logic working (in memory), then you can worry about how you go about displaying it (you'd tend to end up with a routine that just paints whatever structures to a canvas).

passel's post alludes to this, I just thought I'd butt in.
__________________
There are no computers in heaven!
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
Pairs (matching card game) vb.net 2010
Pairs (matching card game) vb.net 2010
Pairs (matching card game) vb.net 2010 Pairs (matching card game) vb.net 2010
Pairs (matching card game) vb.net 2010
Pairs (matching card game) vb.net 2010
Pairs (matching card game) vb.net 2010 Pairs (matching card game) vb.net 2010 Pairs (matching card game) vb.net 2010 Pairs (matching card game) vb.net 2010 Pairs (matching card game) vb.net 2010 Pairs (matching card game) vb.net 2010 Pairs (matching card game) vb.net 2010
Pairs (matching card game) vb.net 2010
Pairs (matching card game) vb.net 2010
 
Pairs (matching card game) vb.net 2010
Pairs (matching card game) vb.net 2010
 
-->