GameSalad

Memory Card Game

darren.gregorio%40gmail.comdarren.gregorio@gmail.com Posts: 19Member
edited March 9 in Working with GS (Mac)

I am trying to make a memory card game, however I am very confused on how to do this. I searched online but there is no tutorial on how to make it, instead there were templates but I had to pay for them.

Can anyone make a simple tutorial or just explain to me on how to make this memory card game, at least just 2 type of cards. I want to know how to make two actors to destroy themselves if they match.

Comments

  • imjustmikeimjustmike Posts: 450Member
    edited March 8

    A super simple way to do it is as follows (you can probably combine these rules to make the logic tighter, but I think this should do the job and explains why it does the job).

    In your cards have a self attribute called self.card. Use a text attribute. In each of the cards on your scene you'll need to type the type of the card into this attribute, making sure to use the EXACT same text on cards that match.

    Create a global text attribute called global.card.

    Create a second global attribute, an integer one called global.count

    Then create a combination of rules that tell the game if it's been pressed, how many cards have been pressed and do they match the card that was already selected.

    Give that a bash and see if it works for you

  • imjustmikeimjustmike Posts: 450Member
    edited March 8

    Thinking about it, you'll probably need to use some timers to make sure that the rules trigger correctly.

    And it might just be simpler to have two global attributes. game.first_card and game.second_card.

    When two cards have been pressed, if game.first_card = game.second_card destroy cards and reset count, else reset count

  • darren.gregorio%40gmail.comdarren.gregorio@gmail.com Posts: 19Member
    edited March 8

    How do I do this? This is what I am actually confused about
    "Then create a combination of rules that tell the game if it's been pressed, how many cards have been pressed and do they match the card that was already selected."

  • tatiangtatiang Posts: 11,034Member, Sous Chef, PRO, Senior Sous-Chef
    edited March 8

    There's no need to make a new thread for each additional piece of information... just post in the original thread (this one) or edit your post using the gear button at the top-right of each post. Here's your question from your other thread:

    I am making a memory card game,
    so far what i did was
    For card A:
    Rule when actor is touched, attribute game.Match +1
    Rule when attribute game.Match=2, destroy card

    For Card B:
    Rule when actor is touched, attribute game.Match2 +1
    Rule when attribute game.Match2 =2, destroy card

    Now, how do I make so that when press the same card twice, they wont be destroyed?
    How do I reset when two cards have been pressed if it doesnt match?

    New to GameSalad? (FAQs)   |   Tutorials   |   Templates   |   Greenleaf Games   |   Educator & Certified GameSalad User

  • tatiangtatiang Posts: 11,034Member, Sous Chef, PRO, Senior Sous-Chef

    No need for a new attribute... just compare self.Image assuming your actors are using unique image names (e.g. orange.jpg, apple.jpg, lemon.jpg). But you'll need to store the two values somewhere:

    When Touch is Pressed
         When game.turnNumber=1
              Change attribute game.firstCard to self.Image
              Change attribute game.turnNumber to 2
         Otherwise
              Change attribute game.secondCard to self.Image
              When attribute game.firstCard=game.secondCard
                   [match]
              Otherwise
                   [no match]
              Change attribute game.turnNumber to 1

    New to GameSalad? (FAQs)   |   Tutorials   |   Templates   |   Greenleaf Games   |   Educator & Certified GameSalad User

  • I might have a solution, but I made a new problem

    This is what I have on one card:

    When touch is pressed
    Change Attribute game.turnNumber to game.turnNumber + 1
    Change Attribute game.SelectedCard to game.SelectedCard + 1

    When Attribute game.turnNumber = 2
    When game.SelectedCard = 2
    Destroy this actor

    On the other side, I have another actor which acts like a resetter
    so
    When Attribute game.Select = 2
    ChangeAttribute game.turnNumber = 0
    ChangeAttribute game.SelectedCard = 0

    This works pretty well until I previewed it

    I placed the card beside each other like this

    (A) (A)

    These are the problems:

    • If i pressed on two of the same card both card dissapears
    • If I pressed the left card first, then the right card, only the right card disappears (If I did the right card first then the left one, both disappears which is ok)
    • If I had more than 2 same type card, and pressed only on two cards, either only one disappears (when I pressed on the card on the right side first), or otherwise all of them disappear.
  • pHghostpHghost London, UKPosts: 2,059Member
    edited March 9

    @darren.gregorio@gmail.com said:
    I might have a solution, but I made a new problem

    @imjustmike gave an elegant solution, which would cause no problems like this, why not try that?

    Two game attributes for cards:

    game.card_01
    game.card_02

    Also, a counter for how many cards are turned round.

    game.turned_cards

    Now, inside the card actor, make a self attribute:

    self.card_ID

    That is the type of card it is, what picture. There will be two of each ID, of course.

    When you tap a card, do the following:

    if: game.turned_cards < 1, change attribute: game.card_01 to: self.card_ID, AND change attribute: game.turned_cards to: game.turned_cards +1, OTHERWISE if: game.turned_cards < 2, change attribute: game.card_02 to: self.card_ID, AND change attribute: game.turned_cards to: game.turned_cards +1

    Then a timer in a rule:

    if: game.turned_cards = 2, after: 2 seconds, change attribute: game.card_01 to: 0, change attribute: game.card_02 to: 0, change attribute: game.turned_cards to: 0

    Name your card images systematically: card_00.png for the back then card_01.png, card_02.png ... card_0X.png -- or card_000.png, card_001 etc., if you have more than 99 uniques card pictures.

    Then, do a change image rule:

    if: game.card_01 = self.card_ID or: game.card_02 = self.card_ID, change: self.image to: "card_"..padInt(self.card_ID,2)..".png", OTHERWISE: change: self.image to: "card_00.png"

    Here, in the padInt, you put a 2 or a 3, depending on how many digits your image names have, as described earlier.

Sign In or Register to comment.