Solved

concentration game

Posted on 1998-11-24
19
420 Views
Last Modified: 2010-05-18
I need to know how to make the game "concentration" using pictures that you flip over instead of cards.  I want to make about 20 green colored rectangles that you click on and a picture appears. I can't figure out how to do this.
please help.  I'm just a vb5.0 beginner. thanks.
0
Comment
Question by:moseyduck
  • 9
  • 7
  • 2
  • +1
19 Comments
 
LVL 5

Expert Comment

by:scrapdog
Comment Utility
Could you be a little more specific?  What have you already figured out, and what have you not?
0
 
LVL 6

Expert Comment

by:VBGuru
Comment Utility
Simplest solution will be to have 20 picture boxes generated dynamically and filinng them with the colour what it should contain when turn aside. In the click event check the index proprty of the control array and assign the picture you want to put. These pictures once again can be placed  in a resource file for faster access and you  don't have to ship it with your application.
If you have anything more to know about let me know?
0
 

Author Comment

by:moseyduck
Comment Utility
In regards to scrapdogs comment, I have not even figured out how to start my form.  I don't know whether to use a text box with a picture underneath or a control box with a picture underneath or maybe not even that at all.  I would like to see what your suggestion is.
0
 

Author Comment

by:moseyduck
Comment Utility
To vbguru, please provide some coding and be more specific about how to assign a picture to the control array.  
0
 
LVL 6

Expert Comment

by:VBGuru
Comment Utility
Then you get info regarding "What is a control  array" from the VBONLINE. for to do that you have to set index property of that control to 0.
Let me know what is your next doubt
0
 
LVL 5

Expert Comment

by:scrapdog
Comment Utility
I would also suggest using picture boxes.  To make a control array, put one picture box on your form.  Then select it and go to copy (in the edit menu?).  Then paste it somewhere.  It will ask you if you want to create a control array.  Keep pasting the boxes until you have 20.  Then line them up the way you want.

In the click event of these, a variable called index is passed.  This will tell you which picture box was clicked.  I would suggest using another array to indicate what is stored in these picture boxes, and use index to check what it is.
0
 

Author Comment

by:moseyduck
Comment Utility
I still don't understand how many arrays are needed if i am going to be able to click on a square for example, and see an image, then click on another square to see another image. Does this have to be done with arrays?  How do i code this so that if the two images are not the same, after 2 or 3 seconds the square comes back and you have to pick two more squares to figure out where the matching images are.  if the images are matching, i want them to stay visible.
0
 

Author Comment

by:moseyduck
Comment Utility
I still don't understand how many arrays are needed if i am going to be able to click on a square for example, and see an image, then click on another square to see another image. Does this have to be done with arrays?  How do i code this so that if the two images are not the same, after 2 or 3 seconds the square comes back and you have to pick two more squares to figure out where the matching images are.  if the images are matching, i want them to stay visible.
0
 
LVL 5

Expert Comment

by:scrapdog
Comment Utility
Have each image be represented by a number in an array.  You could even store this in the tag property of the picture box.  To determine whether or not they are the same, just compare the values in the tag property.

If Picture(a).Tag = Picture(b).Tag Then Match
0
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 

Author Comment

by:moseyduck
Comment Utility
Unfortunately I need more specific instructions.  I can't get the array to work.  Isn't there a way to do this without an array?  I also can't center the icon in the picture box anyway.  I know how to make an array using picture boxes.  I just don't know how to create another one using the tag property.  
0
 
LVL 5

Expert Comment

by:scrapdog
Comment Utility
Don't create another one.  Use the array of picture boxes.  The tag a property of the picture box, which is an element of the array.
0
 
LVL 5

Expert Comment

by:scrapdog
Comment Utility
I mean "The tag *is* a property of the picture box"
0
 
LVL 3

Expert Comment

by:myqlG
Comment Utility
This sounds like an assignment for class.  If you are gunna get
help you should at least make the points worth it so we feel
better about cheating ;)
0
 

Author Comment

by:moseyduck
Comment Utility
Well, this is kind of a project for school, but we're allowed to use whatever means necessary.  We have to make something, anything, and this was all I could think of that sounded kind of fun.  How many points do you want? I only have 156 left and need some for another question.
0
 
LVL 5

Accepted Solution

by:
scrapdog earned 70 total points
Comment Utility
Use a variables that indicates which card was flipped first.  If the variable is 0, then no card was flipped.  In the click event for the picture box, show the picture.  If the variable has a value of 0 then set the variable to the index of the picture box.  If the value is not 0, then a card has already been flipped, so you have to check if the two cards match.

If you call the variables Card1 and Card2, in the click event you would do something like this:

If FirstCard = 0 Then
  FirstCard = Index
  ShowTheCard(Index)
Else
  ShowTheCard(Index)
  If PictureBox(FirstCard).Tag = PictureBox(Index) Then Match
  Else NoMatch
  {....}
  HideTheCard(PictureBox(FirstCard))
  HideTheCard(Index)
  FirstCard = 0
End If
 
Note that this is pseudocode.  ShowTheCard and HideTheCard are functions you would implement (the purpose of these is self-explanatory).



0
 
LVL 5

Expert Comment

by:scrapdog
Comment Utility
oops

"If you call the variables Card1 and Card2" = "If you call the variable FirstCard"

0
 
LVL 5

Expert Comment

by:scrapdog
Comment Utility
Another typo!

If PictureBox(FirstCard).Tag = PictureBox(Index).Tag Then Match
0
 

Author Comment

by:moseyduck
Comment Utility
If I can call you on the phone and work this out, I'll give you extra points.  I think it would be faster for me. If you want to, send your phone number to moseyduck@stic.net and I'll call you or you can call me @ 1-800-749-6488 tomorrow (Texas time). I would really appreciate this.  I'm getting confused with the picture boxes and tags and variables.  If I make 20 green empty picture boxes and make this an array, then how to I give each box a certain picture in the click event?
0
 
LVL 5

Expert Comment

by:scrapdog
Comment Utility
Check the help file on picture boxes.  It will show you how to assign an image to a picture box.  When a card is flipped, assign the image to it.  Otherwise assign a blank image or an image of the back of the card.

You could use a set of filenames to images or whatever in an array to indicate an image, and this array would be indexed by the number found in the picture box's tag property.  In the beginning of the program you would randomly assign these numbers to the picture box's tag property.

In other words, in your ShowCard subroutine, assign the image, and in HideCard, assign the image of the back of the card.

Sorry, I can't help you on the phone, because I don't have Visual Basic, so I wouldn't be able to walk you through it.
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now