Memory game using images

edited October 2016 in How To...

Hello im creating a memory game for an assignment. I have too draw matching cards (imported from an image) too a random location . I thought about making an array with images and a Two-dimensional Array with the locations. And then pick random locations out of the array and draw cards on those places.

Can anyone tell me if this is a good idea. If yes please give me some pointers, if not could you point me towards an easier solution.

Thanks!

Answers

  • Answer ✓

    First, yes, you are going to want an array of PImages to store your images in. Once you have them loading properly (in setup), see if you can display each of them, showing the next one each time you click the mouse.

    Then you will probably want to write a Card class. This will keep track of all the variables needed for one Card. This will involve the Card's position (x and y), if it is flipped over, if it is visible at all, and what image it should display when flipped over. You could also write a function to determine if the mouse is over the card.

    Then you will only need an Array of Cards. When the mouse is clicked, see, for each Card, if the mouse is over that Card. If it is, flip it (and remember that a card is flipped now), or (if a card is already flipped), cope with the match or the not-a-match - either mark both cards as not visible, or flip them back over.

Sign In or Register to comment.