Skip to content

aviyehuda.com

Menu
  • Open Source
  • Android
  • Java
  • Others
  • Contact Me
  • About Me
Menu

Memory Game – Android Application

Posted on 29/07/2010

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:



89 thoughts on “Memory Game – Android Application”

Comments navigation

Newer comments
  1. mitu says:
    02/11/2010 at 21:08

    androidmenifest.xml is missing in source code

    Reply
    1. admin says:
      03/11/2010 at 11:53

      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.

      Reply
      1. Mitu says:
        09/11/2010 at 09:55

        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

        Reply
      2. Jinka says:
        14/11/2011 at 09:03

        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.

        Reply
        1. Avi says:
          17/11/2011 at 07:46

          Hi Jinka,
          What do you mean by “executable” source code?

          Reply
      3. mj says:
        25/02/2014 at 03:50

        I want a congratulation text or picture to appear after you beat the game.
        How do you do that?

        Reply
    2. Cathy says:
      02/01/2014 at 10:37

      I also encounter some error. Error shows in manager.java

      Reply
  2. Sage says:
    24/11/2010 at 07:26

    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!

    Reply
  3. Anonymous says:
    29/12/2010 at 16:09

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

    Reply
  4. shikoo says:
    03/01/2011 at 08:52

    thank you very much!

    Reply
  5. sharu says:
    28/01/2011 at 08:00

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

    Reply
  6. Hasif says:
    09/02/2011 at 03:29

    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 !!!

    Reply
  7. Jose says:
    18/02/2011 at 21:45

    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

    Reply
  8. rizky says:
    23/03/2011 at 20:40

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

    Could you help me please? Thx! 🙂

    Reply
    1. admin says:
      23/03/2011 at 21:48

      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 .

      Reply
      1. rizky says:
        24/03/2011 at 17:10

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

        What should i do?

        Reply
  9. macarius2 says:
    14/04/2011 at 15:08

    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

    Reply
    1. admin says:
      14/04/2011 at 20:48

      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?

      Reply
      1. macarius2 says:
        15/04/2011 at 09:04

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

        Reply
        1. macarius2 says:
          15/04/2011 at 10:08

          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

          Reply
  10. Jason M says:
    16/06/2011 at 20:36

    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.

    Reply
  11. dindin says:
    28/06/2011 at 19:07

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

    Reply
  12. ranjeet says:
    13/07/2011 at 07:10

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

    Reply
    1. admin says:
      13/07/2011 at 07:32

      Hi ranjeet,
      What is the error?

      Reply
  13. lones says:
    17/07/2011 at 12:24

    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

    Reply
    1. admin says:
      17/07/2011 at 15:02

      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?

      Reply
  14. brusk says:
    20/07/2011 at 10:30

    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..

    Reply
    1. admin says:
      21/07/2011 at 07:35

      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?

      Reply
  15. Anonymous says:
    01/08/2011 at 14:27

    thx alot

    very helpful

    Reply
  16. Andal says:
    22/09/2011 at 05:44

    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.

    Reply
  17. Avi says:
    25/09/2011 at 08:29

    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

    Reply
  18. Maciek says:
    27/10/2011 at 14:38

    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?

    Reply
  19. champ says:
    27/10/2011 at 19:48

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

    Reply
  20. Renato says:
    02/12/2011 at 13:30

    Thanks Man !!

    Reply
  21. lilman says:
    11/12/2011 at 10:30

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

    Reply
  22. faisal says:
    10/01/2012 at 23:05

    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

    Reply
  23. mona says:
    16/02/2012 at 04:33

    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?

    Reply
  24. mona says:
    16/02/2012 at 04:38

    i tried to run the app on blackberry..

    Reply
  25. Pooja says:
    07/03/2012 at 14:10

    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.

    Reply
    1. Avi says:
      08/03/2012 at 11:06

      What are the errors you see?

      Reply
      1. Pooja says:
        14/03/2012 at 10:47

        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.

        Reply
    2. abc says:
      29/01/2013 at 11:39

      how do you solve your errors? I am having the same problem as you.

      Reply
  26. jerbz says:
    08/03/2012 at 13:27

    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

    Reply
  27. mich says:
    08/03/2012 at 16:03

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

    Reply
  28. markann says:
    14/03/2012 at 09:07

    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,.

    Reply
    1. Avi says:
      14/03/2012 at 09:28

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

      Reply
      1. Sujay says:
        19/03/2012 at 10:55

        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?

        Reply
  29. yan says:
    21/03/2012 at 09:22

    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

    Reply
  30. melek says:
    17/04/2012 at 21:03

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

    Reply
  31. Faizan says:
    27/04/2012 at 10:05

    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

    Reply
  32. Tuan says:
    10/05/2012 at 10:05

    Thanks you very much, it very helpful

    Reply
  33. murat says:
    29/05/2012 at 16:21

    Can you please send me an e-mail attached with source codes of this game? The one provided by the link is not working :S

    Reply
  34. martin says:
    02/06/2012 at 23:26

    How to judge the game has been successful??

    Reply
  35. Thomas says:
    27/06/2012 at 14:18

    Hi, how can I customize layout? I need more space between pictures. Can you help me. Thanks! 🙂

    Reply
  36. Thomas says:
    07/07/2012 at 11:36

    I have successfully customized design. But now I have problem. I have 24 images and game bord 3×4, I need generate allways different images, but it generate allways same first 6 images. Thanks for help and sorry for bad English

    Reply
  37. catherine says:
    20/07/2012 at 09:12

    hi.!
    i am a beginner in eclipse and i want to create a game with 3 matching tiles of pictures like the game of bejeweled and call of atlantis in a tablet. can you send me some codes that will help me in creating that game..?
    please send it to my e-mail..thank you ..
    🙂

    Reply
  38. JT says:
    20/07/2012 at 16:45

    Love this code thank you! Works perfectly. Although I am trying to change the back image of the card of the image. It automatically is using my icon.png. How do I change the back of the card. I been looking for an hour now. I saw “backImage” in the main.java file. But won’t let me redirect to the drawable folder. Thanks again!

    Reply
  39. farhan shah says:
    05/02/2013 at 12:27

    Thank You Very Very Much Sir.It’s working for me.Thanks Alot..

    Reply
  40. AngelaW says:
    21/02/2013 at 20:28

    firstCard = new Card(buttons,x,y); <—- this code hv error.

    No enclosing instance of type MainActivity is accessible. Must qualify the allocation with an enclosing instance of type MainActivity (e.g. x.new A() where x is an instance of MainActivity).
    this the comment that eclipse give. What shud i do?

    Reply
  41. Andreu says:
    28/02/2013 at 22:55

    Hi! Thanks for the game!

    I just import the project and I find a lot of errors in Manager archive. How can I solve it?

    Thank you!

    Reply
  42. Johny says:
    18/03/2013 at 16:19

    Hi! I need your help. I am looking to build functions to continue the game, you can give me suggestions?

    Reply
  43. Surekha says:
    12/04/2013 at 13:29

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

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

    Reply
  44. Koko says:
    12/04/2013 at 17:38

    Thanks for your source code, im using eclipse and already import it to my workspace but still showing error in manager.java (src folder) please help

    Reply
  45. zeptyan says:
    17/04/2013 at 18:32

    Hi im beginner in android apps… i just downloaded this game, but i wanna a simple configuration, that the object listener in this game is Spinner, but i try some modification with button widget, so there will be :

    Button bu = ((Button)findViewById(R.id.bt1));
    bu.setOnClickListener(new View.OnClickListener() {

    @Override
    public void onClick(View v) {
    NewGame(4,4);
    }
    });
    …..

    but there is an error in runtime… in syntax there is no error… the error show in LogCat:
    1. java.Lang.NullPointerException
    2. android.view.View.
    3. android os handler
    4. android.os looper
    5.android app Activity.thread.main

    what should i do? can you give me a suggestions?

    thanks a lot 🙂

    Reply
  46. yulgun says:
    23/04/2013 at 09:06

    hi u!
    i have downloaded the project and open it on eclipse.
    i tried to compile and there have some errors!
    pls help me to fix these errors,

    errors are like this:
    – The project was not built since its build path is incomplete. Cannot find the class file for java.lang.Object. Fix the build path then try building this project.
    – The type.java.lang.Object cannot be resolved.It is indirectly referenced from required .class files.

    Reply
    1. Avi says:
      23/04/2013 at 09:23

      Hi,
      In the eclipse project properties, go to build properties.
      Fix all the errors in there.
      Make sure you JDK is defined properly in your eclipse.
      Then, clean the project.

      Reply
  47. yulgun says:
    23/04/2013 at 09:35

    thanks a lot.
    but i still have some problems.
    i can not fix those building errors,
    i m a beginer for android, i want to learn more through this game source.
    so please help me!

    pls first tell me to create android project with your open source,
    then the ways to build project and run.
    thanks. Avi !!!

    Reply
  48. Pedro says:
    02/05/2013 at 23:15

    Thank you very much!!!

    Reply
  49. Ancy says:
    10/05/2013 at 07:31

    Thnx a lot, it was a grt help.!

    Reply
  50. lol says:
    25/05/2013 at 19:30

    Hi!
    I want a congratulation text or picture to appear after you beat the game.
    How do you do that?

    Thanks

    Reply
    1. mj says:
      25/02/2014 at 03:49

      me too.. i need the codes for the end of game..

      Reply

Comments navigation

Newer comments

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *


About Me

REFCARD – Code Gems for Android Developers

Categories

  • Android
  • AWS
  • AWS EMR
  • bluetooth
  • Chrome extension
  • ClientSide
  • Clover
  • Coding Coventions
  • Data Lake
  • General
  • GreaseMonkey
  • Hacks
  • hibernate
  • hibernate validator
  • HTML5
  • HtmlUnit
  • Image Manipulation
  • Java
  • Java Technologies
  • JavaScript
  • Java_Mail
  • JEE/Network
  • Job searching
  • Open Source
  • Pivot
  • projects
  • Pure Java
  • software
  • Spark
  • Trivia
  • Web development

Archives

  • March 2022 (1)
  • January 2022 (1)
  • January 2021 (1)
  • December 2018 (1)
  • August 2018 (1)
  • October 2013 (1)
  • March 2013 (1)
  • January 2013 (2)
  • July 2012 (1)
  • April 2012 (1)
  • March 2012 (1)
  • December 2011 (1)
  • July 2011 (1)
  • June 2011 (1)
  • May 2011 (2)
  • January 2011 (1)
  • December 2010 (1)
  • November 2010 (3)
  • October 2010 (4)
  • July 2010 (1)
  • April 2010 (2)
  • March 2010 (1)
  • February 2010 (2)
  • January 2010 (5)
  • December 2009 (10)
  • September 2009 (1)
 RSS Feed
6dc4b508c301309b9e838ba10393207a-332
©2023 aviyehuda.com | Design: Newspaperly WordPress Theme