Solved

concentration game

Posted on 1998-11-24
19
426 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
ID: 1446666
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
ID: 1446667
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
ID: 1446668
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
ScreenConnect 6.0 Free Trial

Discover new time-saving features in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI, app configurations and chat acknowledgement to improve customer engagement!

 

Author Comment

by:moseyduck
ID: 1446669
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
ID: 1446670
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
ID: 1446671
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
ID: 1446672
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
ID: 1446673
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
ID: 1446674
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
 

Author Comment

by:moseyduck
ID: 1446675
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
ID: 1446676
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
ID: 1446677
I mean "The tag *is* a property of the picture box"
0
 
LVL 3

Expert Comment

by:myqlG
ID: 1446678
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
ID: 1446679
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
ID: 1446680
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
ID: 1446681
oops

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

0
 
LVL 5

Expert Comment

by:scrapdog
ID: 1446682
Another typo!

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

Author Comment

by:moseyduck
ID: 1446683
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
ID: 1446684
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

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
DIR issue 7 54
VBA open file from excel cell 4 42
passing a value with stream reader AFTER a ";" 3 66
VB6 - Scroll Mouse wheel on Picturebox 13 44
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…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
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…

770 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