memory game randomizing card faces

0 favourites
From the Asset Store
Template for trading card game, fully documented in comments and video
  • Hello all! First, let me say that I love this website. This has got to be one of the most helpful/friendly sources of information on the internet. You people are geniuses.

    So I recently went through and did kittiewan's memory matching tutorial.memory match tutorial

    This thing helped me understand so much more about Construct. I'm no programmer but i loove video games so i apologize for the lack of programming etiquette here, but ill try to explain my problem as best as i can.

    The way that game is set up, it has 2 frames for each cardface that is put onto the field. So when you have 6 cards to match in the game, the first 6 frames of the card object are used. This ensures that there will always be 2 of every face.

    My problem is that if i make my card deck have more cards (frames) than will ever appear on the field, the cards that use the later frames in the animation will never see the light of day. Those first 6 cards will always be the first 6 frames. I'm having trouble wrapping my head around how to get the game to randomly choose card faces from the entire animation AND THEN make sure that each randomly selected frame has its partner frame (either the frame before it or after it) put onto the field as well.

    For example, if i was using the entire alphabet as a matching game and i wanted to only have a 6 card game. how could i ensure that Q, W, Z, etc. have a chance to be used and not just have A, B, and C every time.

    I hope that was easy to understand... Thanks in advance!

  • thanks R0J0! now ill see if i can figure out how to implement that in her tutorial

  • ok so ive gotten it... kind of working lol

    using kittiewan's tutorial still, ive gotten the cards to be randomly selected from all of the available frames

    i have 2 problems i cant seem to figure out

    1. if i have only 6 cards appear on the field, the pairs aren't really shuffled, each card's partner is underneat/above it. kittiewan had a shuffle function but once i added all this jazz it makes all the cards the same if enabled, at the moment ive disabled that function so if anyone can figure out why they cant be shuffled that way, i would love it

    2. every once in a while it will give me 2 of the same pairs, so 4 frames that are the same, like 4 fires or 4 stick men

    heres the capx if anyone can figure it out. thanks again!

    https://dl.dropbox.com/s/25qhvc6ny5thgev/MemMatchTutComplete_random.capx?dl=1

  • ok i think i fixed my first problem, the cards arent always positioned above and below each other.

    i still kind of have the 2nd problem, but slightly different/worse.

    every couple games it will give me 2 pairs and then 2 different cards that cant be matched together, like ill get 2 stick men 3 hands and a fire, or 2 fire, 2 leaves, 1 rabbit and 1 stick man.

    been working at this for hours and i cant figure it out <img src="smileys/smiley19.gif" border="0" align="middle">

    heres another capx https://dl.dropbox.com/s/25qhvc6ny5thgev/MemMatchTutComplete_random.capx?dl=1

    thanks!

  • Make event 8 so that it is not a sub-event of event 5 and that should fix most of it. You can still get two pairs of the same card so just delete the duplicate frames.

  • unfortunatly taking event 8 out of event 5 and just making it a sub event of on start of layout, and even a stand alone event did not fix the problem of getting unmatchable pairs, although it didnt seem to make anything worse either haha

    and when you say delete the duplicate frames, do you mean the duplicated frames inside the card sprite itself? cause i tried that and it didnt work

  • Add a card:destroy action to start of layout. The off screen card is what is giving the unmatchable cards.

  • poop that didn't work either

    the card is definitely being destroyed but i still sometimes get 2 cards i cant match or double of 1 pair. i've somehow even gotten 2 cards that weren't the same to "match". ive probably destroyed the hell out of this tutorial with all of my changes lol

    here's the newest capx with all suggested changes if anyone still wants to give it a shot https://dl.dropbox.com/s/25qhvc6ny5thgev/MemMatchTutComplete_random.capx?dl=1

    R0J0, thanks for wasting your time with me haha... im sure you have nothing better to do <img src="smileys/smiley17.gif" border="0" align="middle">

  • Ok, add a new event:

    System:compare tickcount=1

    And move event 9 (the for each ordered) to be a sub event of that new event.

    What was happening was destroyed objects still exist until the end of the frame. So there was still an odd number of cards when the for each was run.

    As for being able to match different cards I suspect your condition that checks for a win may be the cause.

    Try changing the expressions to just gFirstCardFrame=gSecondCardFrame

  • thank you so much, youre a freakin genious <img src="smileys/smiley32.gif" border="0" align="middle" />

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Hi R0J0hound ,

    sorry for asking this on this old post but i found your deal_pairs.capx much better to understand using arrays as i can actually 'see' how

    the cards are laid out, which is what i want. Unfortunately kittiewan hasn't been on for a year (to ask) so i used some of her code from the tutorial

    so i am able to remove and destroy the pairs of cards i click on.

    Where i'm stuck is how, using the array, to just so ALL "facedown" cards to begin with. At the moment they're all faceup and your capx is definitely a quicker

    way to do it also. Do i need to create another array using a different card object, animation frame 0, and use there IIDs to select those and remove

    them from the TOP of the array by Ids?

    Any help on that would be appreciate. Read the manual, and Kits tut, but cant workout whether i need a separate array of "facedown" cards to appear

    ontop. Thanks,

    Rob

  • Instead of setting the animation frame, you can set an instance variable of each card. Then you can make a boolean variable for each card and call it "face up". If the boolean is true you set the animation frame, and if it's false change the animation to a face down animation frame.

  • Thanks for quick reply R0j0.

    <- i set the card object with those variables. I just mean, as in your example, where would i put the check so that

    all cards initially are face-down? I'm using Card.AnimationFrame and a few text objects so i can "see" the FrameNumber as i click on it so i can see the feedback. OK...so

    i will have a think a bit more about this. If i get stuck ill annoy you again nicely,

    Thanks again.

    Instead of setting the animation frame, you can set an instance variable of each card. Then you can make a boolean variable for each card and call it "face up". If the boolean is true you set the animation frame, and if it's false change the animation to a face down animation frame.

  • Vaidd

    I made this for another thread, mixing up letters of a word and mixing in "fake" ones. Check it out, it might help you too...

    The randomizing principle can be exactly the same in your case.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)