Newbie Question (If Statements)

nyr1man

New member
Joined
Nov 12, 2004
Messages
2
Programming Experience
Beginner
Have to write a concentration (memory) game for my beginners VB class at college. Having a little trouble with some of my syntax. What I am trying to do is use IF statements to compare each individual picturebox in order that I define them to the other pictureboxes I have defined before them. I am doing this to ensure that I end up with the exactly the right number of matches with no extra cards without matches. For example I have 28 cards in the game. Cards 1-14 are all different pictures. Cards 15-28 are the matches for the first 14 cards. What I want to do is randomely place these 28 cards on the board without duplicating any one of them twice so that the game ends with exacty 14 matches everytime. once I use the random statement to choose the first card I will use the random statement to choose the second card. I then want to use the if statement to say If card2 = card1 then choose another card until they don't match. Once card2 is a card not matching card1 I will then use the random statement to choose card three. Then I want to use the If statement to say if card3 = card2 or card1 choose another card until they don't match.

***Long story short is how do you use the if statement correctly to compare more than two items? (Ex: if card5 = card1 or card2 or card3 or card4 then) Any help would be greatly appreciated and if I have confused any on then I can try to make it clearer if necessary.***
 
To do the randomizing as you suggest, you could create an arraylist and add an object representing the picture to the arraylist each time one is selected (an integer from 1 to 28 for example). Before adding it, check to see if it already contains that object using the ArrayList.Contains function. If your random statement chooses a number from 1 to 28 each time, by the time you reach the 28 card, your chances of choosing the last available picture would be very low and it could take quite a bit of time to find.

I would suggest creating an arrayList containing integer values from 1 to 28 then randomize the list (there are many examples of how to randomize a list on the net). Then assign the picture to the card based on the new order of the list.
 
Thank you both for your suggestions I was close actually in regards to the If statement. Was writing the syntax as If card5= card1 or card2 or card3 then.... not If card5-card1 or card5=card2 or if card5=card3 then.....

VB was not flagging it as incorrect code in the program but as soon as I ran it the program would end with a handler error.

As for the array suggestion - have never used arrays before, but might try it as I understand what you are saying in regards to the time it will take using the Random statement. Seeing as it has 28 cards to choose from it may take a while to finally come up with a card that has not been used by the time you get to the high 20's.
 

Latest posts

Back
Top