Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Concentration Game Help
Index -> Programming, Visual Basic and Other Basics -> Visual Basic Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
NightWing




PostPosted: Wed Jun 14, 2006 1:37 pm   Post subject: Concentration Game Help

I am wanting to create a big concentration game.. As I have it at the moment, I have two arrays with both the same pictures all in.. I have also made all the buttons.. What I need to know is:

a) How to make it so that the pictures will be listed randomly into the buttons.
b)After this, make the same buttons interlocked so when you push both of them, they will stay upside, and unpushable again.
c)Find if there are still cards left, if not, then Ask to play again. Yes = restard, No = Quit

I appreciate anyone who is willing to give some feedback on this, have been stuck for awhile now on it:).
Sponsor
Sponsor
Sponsor
sponsor
cool dude




PostPosted: Wed Jun 14, 2006 4:53 pm   Post subject: (No subject)

i don't really remember the game concentration but i can help with your questions.

a) to randomize the card order u can do something like so

code:

Randomize
num = int(5 * Rnd) +1

if num = 1 then
   'display picture 1
elseif num = 2 then
   'display picture 2
etc...


this will randomize a number between 1 and 5 and then u can make if statements saying if the number is 1 display picture 1 and so on.

b)to make the buttons unpushable again u can say
code:

buttonname.enabled = false


c)to find out if there are still cards left u can have a variable count and u increase count everytime a card is played i.e.
code:

count = count + 1


then i don't know how u want to ask if they want to play again, but if u want u can make a button that says newgame and just restart the whole game by doing this
code:

 Unload Me
 Formname.Show
GlobeTrotter




PostPosted: Wed Jun 14, 2006 7:15 pm   Post subject: (No subject)

The way I would structure the program is like this:

code:

Public Type ConcentrationCard
   TurnedUp as Boolean
   Picture as StdPictureFile 'This may give an error, I forget the actual name of the image type
End Type


Have two arrays of this, similar to what you have.

You will also need a control array of buttons, look into them if you are unfamiliar.

To randomize the buttons with cards, it's just a matter of randomly choosing a number out of continually descending choices of buttons: a for loop should suffice.

When the user clicks on the button, set it's turnedup to true. Then check if the .TurnedUp in the other array with the same element number is true. If it isn't, loop through and reset the other cards' value. If it is, then have its value set to true.

I apologize if I'm being a bit too specific and/or vague. Ask questions.

Try to avoid some of the things reccomended by cooldude, such as:

-The way he told you to randomize is poor coding. Use of loops is preferable.

-Remember to use a control array, it will make things much easier.

-The way he has you restart, I don't reccomend. It's best you actually loop through and reset all things to their original values rather then reloading the form.

good luck.
cool dude




PostPosted: Wed Jun 14, 2006 7:42 pm   Post subject: (No subject)

GlobeTrotter wat is wrong with randomizing a number my way? it is easier for beginners! Wink as well yes u can reset all your variables and everything else everytime u want a new game, but the reason i didn't suggest it was because beginners usually forget to reset a variable or reset something else, so to make sure everything is reset totally u should use my way, which may i add is less code, and there is absolutely nothing wrong with doing it that way.
GlobeTrotter




PostPosted: Wed Jun 14, 2006 8:02 pm   Post subject: (No subject)

I never said your way wouldn't work. It is a poor way to go about solving the problem, however. It's always best to compartmentalize code and avoid repetition wherever possible. Using arrays (control arrays as well) minimizes repetition, thus it is preferable.
cool dude




PostPosted: Wed Jun 14, 2006 10:15 pm   Post subject: (No subject)

GlobeTrotter wrote:
I never said your way wouldn't work. It is a poor way to go about solving the problem, however. It's always best to compartmentalize code and avoid repetition wherever possible. Using arrays (control arrays as well) minimizes repetition, thus it is preferable.


i never said to not use control arrays in fact i strongly suggest to use them. now u still hadn't shown me proof that the way i'm randomizing a number is poor coding. oh and how am i doing repetition? i believe that both our ways are efficient and they're just 2 different ways to approaching the problem.
GlobeTrotter




PostPosted: Wed Jun 14, 2006 10:39 pm   Post subject: (No subject)

cool dude wrote:

code:

Randomize
num = int(5 * Rnd) +1

if num = 1 then
   'display picture 1
elseif num = 2 then
   'display picture 2
etc...

[/code]


Let's assume he does have 6 cards. That is 6 elseif statements + 5 more for the next card + 4 more... etc. That's 6! elseif statements. That's a lot. What if instead of 6 cards he had 20. 20! = 2432902008176640000. That's ridiculous.

My point is, loops are a good thing. Not using them would mean repetition. If you are using control arrays, then you should also use loops. That is all I am saying.
cool dude




PostPosted: Thu Jun 15, 2006 4:27 pm   Post subject: (No subject)

i do get your point but if he does have so many cards which i doubt then he can simiply use the randomize function and then instead of all those if statements he could have a counted loop
i.e.


code:

for i = 1 to 100
if num = i then
'display picture i
end if
next i


as i said there is always more than one solution when it comes to programming so u shouldn't say one is wrong or not. so lets agree on both and settle there
Sponsor
Sponsor
Sponsor
sponsor
GlobeTrotter




PostPosted: Thu Jun 15, 2006 10:20 pm   Post subject: (No subject)

Yes
NightWing




PostPosted: Fri Jun 16, 2006 2:09 pm   Post subject: (No subject)

Thanks for the help guys, really helped me through it..Sorry to start the fight too.. Lol.. Oh, and if you're wondering, I have over 150 cards:), so I guess it would have been alot of code..

Oh, and sorry for not really putting it into a question form, Lol.. Kinda stupid of me.

Again, thanks for the help:)
Display posts from previous:   
   Index -> Programming, Visual Basic and Other Basics -> Visual Basic Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 10 Posts ]
Jump to:   


Style:  
Search: