Memory Game – Android Application

This is a very simple card memory game I wrote for Android platform.
I’ve attached it complete with source code and resources.
Enjoy.


zip  Download Game

zip  Download Source code



Screen shots:







48 Comments to “Memory Game – Android Application”

  1. mitu says:

    androidmenifest.xml is missing in source code

    • admin says:

      Are you sure?
      I have just download the source code and saw it.
      Please check again.
      If there is still a problem, leave me your email and I will send it to you.

      • Mitu says:

        Hi,

        I tried to download a source code and build the game but it gives
        the same error. Can you please email me zipped folder ?

        Thanks,

        Mitu

      • Jinka says:

        Hi, i downloaded this source code but it is showing some errors in Manager.java file,
        I am a fresher to android gaming apps.

        please send me the executable source code of this application, It will help me a lot.

  2. Sage says:

    Hi, Thanks for posting this game code. This was really helpful. I was trying to add some more functionality to this code like show all cards by clicking a button, so I was wondering if you could help me with that.

    I am very new to programming so your help will be highly appreciated.

    Thanks in advance!

  3. Anonymous says:

    thank you very much! it is really helpful in doing my game development home work

  4. shikoo says:

    thank you very much!

  5. sharu says:

    thank you very much! it is really helpful in doing my game development.

  6. Hasif says:

    Hi…I’m new to JAVA for Android…
    For my sch project, i decided to do a memory game.
    i have decided to use ur source code..however, there is no error but when i run it in sdk-android, the game force close..
    plz help !!!

  7. Jose says:

    hi i was looking at this code, pretty good , really really good, ive been peeking and poking it , and was wondering how would one make the pictures have certain space on the phone, what i mean is , having them cover all the screen of the phone in land and port mode, having them separated by certain amount of space

  8. rizky says:

    There was an error on ArrayAdapter statement and import java.util.regex.Pattern;

    Could you help me please? Thx! :)

    • admin says:

      Hi rizky,
      java.util.regex.Pattern is a standard import, there shouldn’t be a problem with it- try cleaning your project.

      Send me the error message of the ArrayAdapter .

      • rizky says:

        The error message: ArrayAdapter is a raw type. References to generic type ArrayAdapter should be parameterized

        What should i do?

  9. macarius2 says:

    Thank you !! it’s very usefull !!

    However i have one question about your “Manager.java” :
    In which part of the code, do you duplicate the different image ??

    thx again

    • admin says:

      I am not sure I understood the question but i’ll try to help.

      in loadCards() I create a list of sorted numbers according to the number of the cards.
      Than I pull them one by one in random order and order them in a matrix according to the cards on the table
      but first I divide the number by 2 so that each 2 cards on the table will hold the number.

      Now look at the function turnCard() – when a user click on a card I take the image
      according to the number it holds. This is how 2 cards on the table hold the same image.

      Does that answer your question?

      • macarius2 says:

        Yes it’s perfect !!!
        Thx you very much

        • macarius2 says:

          I have an other question, :)
          If i want to change this line : if(cards[seconedCard.x][seconedCard.y] == cards[firstCard.x][firstCard.y]){ …
          by on other which chek if, for example, an apple and a banana are found on the same turn, and then those cards become invisible … How should i do ?
          Maybe : if(cards[seconedCard.x][seconedCard.y] == R.drawable.card1 && cards[firstCard.x][firstCard.y] == R.drawable.card2) { …
          or something like that ??

          I hope that it’s rather understandable !

          Thx

  10. Jason M says:

    Great sample! I am modifying this to have some pics my son likes, but I noticed an issue with large resolution screens. In Droid phones it works great, but on my 2.2 pad if you empty a row of cards via matching, the layout shrinks and new cards you turn over are resized…basically, smashed. I can rework the code to use fixed sized containers for each card/cell, but I’d rather not if you already saw it and resolved it. Again, thanks for this code, it is a great way to start customizing my own similar game.

  11. dindin says:

    wow.. you are very good.. thank you.
    It really helped me in learning :)

  12. ranjeet says:

    Sir,
    The code have some error please tell me what can i do?

  13. lones says:

    There are some errors:
    1. The method onClick(View) of type Manager.ButtonListener must override a superclass method
    2. The method onItemSelected(AdapterView, View, int, long) of type new AdapterView.OnItemSelectedListener(){} must override a superclass method
    3. The method onNothingSelected(AdapterView) of type new AdapterView.OnItemSelectedListener(){} must override a superclass method

    • admin says:

      Hi lones,
      I have just downloaded the project and imported it into my eclipse.
      It compiles and run as it should.
      Here’s a suggestion, try cleaning your project in eclipse, see if that’s help.
      Also, make sure you havent got any environment related problems.
      Do you have problems with some of the imports?

  14. brusk says:

    Hi

    Thanks for your source code, but I have a problem when I next started eclipse..

    I have a problem with arrayAdapter, eclipse give me two option
    1. Create field “array” in R tipe
    2. Create constant “array” in R tipe

    What I have todo…?

    Thanks again..

    • admin says:

      Ignore the suggestions from eclipse, they are not good.

      Make sure you have added all the files from my project (including all the files under the ‘res’ folder).
      Try cleaning the project in eclipse.
      Is that helps?

  15. Anonymous says:

    thx alot

    very helpful

  16. Andal says:

    Hey. Thanks for the code! :) It works perfectly fine. But can you explain me why do you use “log” in your program? I don’t understand what it is used for. Also suggest me links where I can find material to read about it.

  17. Avi says:

    Log is a tool for developers to print messages and parameters values while the program is running.
    Let’s say for example you would like to see the value of parameter X in diffrent times of the program, than you can use the Log to print it’s value in diffrent times.
    The log is also used to print errors.
    All the messages are displayed in the log cat console.

    http://developer.android.com/guide/developing/debugging/debugging-log.html
    http://developer.android.com/reference/android/util/Log.html

  18. Maciek says:

    Don’t know why I can’t compile it back to the apk file. At first blush exerything seems to be ok but is not. File has been compiled but is not working on my HTC… Could you please help me?

  19. champ says:

    thaxx a lot…now i will be copying it for my collg project…mmuuaahhh

  20. Renato says:

    Thanks Man !!

  21. lilman says:

    hey
    i got the same problem with arrayAdapter.. how can i fix it? any suggestions?

  22. faisal says:

    Hi,
    You have done excellent job. Very nice. Though I tried to build it but it did not build.
    Could you please give the working source code

  23. mona says:

    I tried this app..tis app is really cool….but when i run the game ,the spinner option is appearing even i selected the 4×4.i ignored it i selected the first set of cards the i selected second set of cards,the first set of cards and the spinner option is displaying again..wht do i need to do…could u plz help me out?

  24. mona says:

    i tried to run the app on blackberry..

  25. Pooja says:

    I just downloaded this code and tried to run in eclipse. But the manager.java file has many errors which state that “cannot be resolved to the type” could you please suggest how to debug this error.

    • Avi says:

      What are the errors you see?

      • Pooja says:

        i have managed to debug the errors but the table rows and columns are not fitting in the emulator screen. how do i change the size could you please explain. i have changed the image sizes to 50dip but still the rows and columns are not shrinking.

  26. jerbz says:

    hmm can i ask?
    what if i when the game is finish a dialog message will appear showing the game is finish and it will also show the tries/turn he commit where do u think in the code can i insert it

  27. mich says:

    thank you for the codes..but there are errors appeared. please help me solve the errors

  28. markann says:

    i have just downloaded the source code..i’ll just ask if there were any graphical layout in main.xml for the 3rd screen shot above? or it will appear automatically once the game is set,.

    • Avi says:

      Hi,
      No, the 3rd screen has no XML layout.
      It is generated in the code.

      • Sujay says:

        I have downloaded the source code .Its nice game.You have given a spinner that shows a dropdown and on selecting the item in the dropdown view it shows the game.But I want to the game to be shown when I click on a button such as play button.I dont want the spinner and dropdown box.What should be done?

  29. yan says:

    hello sir. sorry to interrupt you. can you make some explanation from the source code and the flowchart for this game? i really really need it for my homework. please send me the explanation and flowchart to my email.

    i appreciate your kindness for sharing your great work. thank you very much

  30. melek says:

    bana bunu kodlarını rarlayıp yollarmısın dogru bir şekilde proje ödevim için lazım da

  31. Faizan says:

    Hi,
    I really like your game it helps me understand the code within android. Just wanted to know if there is a way of making a high score table at the end of each game with information about previous top 5 high scores and if you are in the top 5 you can add your name in

  32. Tuan says:

    Thanks you very much, it very helpful

Leave a Reply

Your email address will not be published.

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

This entry was posted on 29/07/2010 and is filed under Android, Open Source. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.