{"id":1379,"date":"2024-12-12T10:16:34","date_gmt":"2024-12-12T05:16:34","guid":{"rendered":"https:\/\/obsidianeducation.wordpress.com\/?page_id=1379"},"modified":"2026-05-15T06:43:49","modified_gmt":"2026-05-15T06:43:49","slug":"memory-game-app-inventor","status":"publish","type":"page","link":"https:\/\/obsidiansofteducation.com\/index.php\/memory-game-app-inventor\/","title":{"rendered":"Memory Game App Inventor"},"content":{"rendered":"\n<p class=\"has-medium-font-size wp-block-paragraph\">Hello friends and welcome to Obsidian Soft,<\/p>\n\n\n\n<p class=\"has-medium-font-size wp-block-paragraph\">Today, I will teach you how to make a memory game in MIT App Inventor i.e. a picture-matching game.<\/p>\n\n\n\n<p class=\"has-medium-font-size wp-block-paragraph\">Start a new project in MIT App Inventor. Let\u2019s call it MemoryGame.<\/p>\n\n\n\n<p class=\"has-medium-font-size wp-block-paragraph\">Make the screen orientation portrait and change the title to Memory Game.<\/p>\n\n\n\n<p class=\"has-medium-font-size wp-block-paragraph\">We will be making a 4 by 4 grid type of layout so there will be a total of 16 cards on the screen i.e. 8 pairs so we need 8 images. You can make an animal pictures memory game or fruit pictures\u2026many themes. I will be using these fantasy creatures as I had these images from my reading comprehension worksheets about fantasy creatures.<\/p>\n\n\n\n<p class=\"has-medium-font-size wp-block-paragraph\">You can upload them at the same time by selecting all images and dragging them to the media section until a dotted rectangle appears.<\/p>\n\n\n\n<p class=\"has-medium-font-size wp-block-paragraph\">From the Layout palette, drag and drop a horizontal arrangement. In its properties, make align horizontal and align vertical both center. Make height 20% and width fill parent.<\/p>\n\n\n\n<p class=\"has-medium-font-size wp-block-paragraph\">Drag and drop a button from the User Interface palette inside this horizontal arrangement. Make the background color orange. Make height fill parent and width 25%. Select the button. Right-click and duplicate this button by pressing <strong>Ctrl + C &amp; Ctrl + V on the keyboard for Windows OR Command + C &amp; Command + V on MacOS.<\/strong> Select the new button. And duplicate it.<\/p>\n\n\n\n<p class=\"has-medium-font-size wp-block-paragraph\">Again duplicate the button. There should be a total of 4 identical buttons in the horizontal layout. Now, select the horizontal layout and duplicate it. Duplicate the new layout. Duplicate it again. There should be a total of 4 layouts with 4 buttons each.<\/p>\n\n\n\n<p class=\"has-medium-font-size wp-block-paragraph\">Now, add another horizontal arrangement with align horizontal and align vertical center properties. Make height 15% and width fill parent.<\/p>\n\n\n\n<p class=\"has-contrast-color has-text-color has-medium-font-size wp-block-paragraph\">Add a button inside this horizontal arrangement. Make the background color custom blue. Make font bold, font size 20, width 30%, shape rounded, and the text on it: Reset with color white. From the sensors palette, add a clock. Make timer interval 1000 ms and turn off timer enabled.<\/p>\n\n\n\n<p class=\"has-medium-font-size wp-block-paragraph\">The screen design is done so let\u2019s go to the blocks section.<\/p>\n\n\n\n<p class=\"has-medium-font-size wp-block-paragraph\">First, let\u2019s make our global variables.&nbsp;<\/p>\n\n\n\n<p class=\"has-medium-font-size wp-block-paragraph\">We need two lists:<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/obsidiansofteducation.com\/wp-content\/uploads\/2024\/12\/AD_4nXcyRWOUC4_MPhxuYCBn522xH_VOe-Amif4q2Zy-zq-jiuozsitd-4yMiXOpptMvTpzsWslxJUwRDeQ4Hl6UYHauTmJFzY-B4F2a2ChqJ3m2Z2_idhfjD5W_EiFysaNb8_ESnaRnkeymMteVEhTC2LsD63goFxZvO59.png\" alt=\"\"\/><\/figure>\n\n\n\n<p class=\"has-medium-font-size wp-block-paragraph\">The buttonsList will contain our 16 buttons which will act like our cards and the imageList will contain the images behind those cards. The button index will be for storing the position of the button that has been tapped by the user i.e. its position inside the buttons list.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/obsidiansofteducation.com\/wp-content\/uploads\/2024\/12\/AD_4nXcwgdGpuz5sZGK4Aq9z0e7uoCPT5fo0FdIiynO8s03QndJby4JERvOCxO9iD3Bn3hiAJ6Kn1itf1le1UUDztrRFVBbFHyXtnVrtdL2VxTOxfin2CFDWufh-LPnSoaoKCczvPNl53AkeymMteVEhTC2LsD63goFxZvO59.png\" alt=\"\"\/><\/figure>\n\n\n\n<p class=\"has-medium-font-size wp-block-paragraph\">We also need to maintain a boolean variable for knowing whether the user is tapping on the first picture card or the second card.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/obsidiansofteducation.com\/wp-content\/uploads\/2024\/12\/AD_4nXfgnOi6pAF1UCHe5jVj321aE0vG6kQRVOn048i3EV-eXK_JMKe7WL55aKosL_MTEzdkaw3-_h2udfDSJllVw0ALDCJ8fcsLYeEueQXmNZkkVZ18UfIdTjwFA1yf_73WnLNknFrwswkeymMteVEhTC2LsD63goFxZvO59.png\" alt=\"\"\/><\/figure>\n\n\n\n<p class=\"has-medium-font-size wp-block-paragraph\">We also need a boolean variable to stop clicking too many buttons at the same time.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/obsidiansofteducation.com\/wp-content\/uploads\/2024\/12\/AD_4nXd8BCLG4peImWnv09V8BImLv_fUYH5kt3ixC9ZODBo6BMxUJjOW89nVhT448hp_44-Xh6_KdyyJZdvuDzhxdl_GGEJSc27BN9UGdEwDF2ucej3F3ViYSjpPbtnf84pSh0hV-7snkeymMteVEhTC2LsD63goFxZvO59.png\" alt=\"\"\/><\/figure>\n\n\n\n<p class=\"has-medium-font-size wp-block-paragraph\">We also need to store the image of the first card tapped on by the user.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/obsidiansofteducation.com\/wp-content\/uploads\/2024\/12\/AD_4nXfXvUpRo8vBAioqooDMwmzsTbLCk8YpwDXyTPLur248HHABzhLwOfDbrUT28_O9n4rUTSb4he98sZBM3zcTnuGyEl2uW2b72rbC_PEq97WhD3UiLFF0wne-Tc5S5aEhFbvWm7UykeymMteVEhTC2LsD63goFxZvO59.png\" alt=\"\"\/><\/figure>\n\n\n\n<p class=\"has-medium-font-size wp-block-paragraph\">Last, we need to store the two buttons that have been tapped on by the user.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/obsidiansofteducation.com\/wp-content\/uploads\/2024\/12\/AD_4nXdn-zG6CaODm244OZ4cTXbBr8FuLZBbZFA91Smt3EYq-shBVoimhrbcx1d0EDLlv1IAMZysssXuiPepQ4yRDO2Z95tEWxZHwUUA9Ihu_FNMdHD6TjJ77krr4SHTm6kvG6B_s42yqgkeymMteVEhTC2LsD63goFxZvO59.png\" alt=\"\"\/><\/figure>\n\n\n\n<p class=\"has-medium-font-size wp-block-paragraph\">When the screen is initialized, we need to make a local variable for storing the uploaded 8 images and add them twice to the imagesList to make 16 images in total. We will also use any component -&gt; any button -&gt; everybutton list to add all the buttons except the reset button to our buttonsList. The any component feature in MIT App Inventor is quite awesome as it reduces our code substantially.&nbsp;<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/obsidiansofteducation.com\/wp-content\/uploads\/2024\/12\/AD_4nXds5_0viBojEChEqk_9XrKU8C9vSC0VwFauhO0l5a9lVL9jARPvkG6KmlcvY8-7aLvYKPdMBPUE-4DKLDwYxN1m48ccs1zR8DurfyZbj9h4fx9ikN1TqI8FmsHvonkO4nMa6Gi9-gkeymMteVEhTC2LsD63goFxZvO59.png\" alt=\"\"\/><\/figure>\n\n\n\n<p class=\"has-medium-font-size wp-block-paragraph\">We also need a way of shuffling the cards so that the cards don\u2019t have the same images in the same positions every time. For this, we need to shuffle our imagesList with those 16 images.<\/p>\n\n\n\n<p class=\"has-medium-font-size wp-block-paragraph\">Make a procedure for shuffling. I have used this procedure before too such as in the <a href=\"https:\/\/obsidiansofteducation.com\/index.php\/app_inventor_flashcards_app\/\"><strong>flashcards <\/strong><\/a>app.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/obsidiansofteducation.com\/wp-content\/uploads\/2024\/12\/AD_4nXcu-A3BR6sJU3K0RxLDmuf1hb4KX4B-rRPLcTttw99j7z36cRUJ0vbs7PzpNflT7bJlXqyLT0THvx1SCoP9kwf0d1-JH0Mx5VdJyshNx7V811RSNq9QEmigBXL-xMgoDGlIYXiqYwkeymMteVEhTC2LsD63goFxZvO59.png\" alt=\"\"\/><\/figure>\n\n\n\n<p class=\"has-medium-font-size wp-block-paragraph\">Call this procedure as the last thing in the screen initialize event.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/obsidiansofteducation.com\/wp-content\/uploads\/2024\/12\/AD_4nXc1b0LwIy68y86aBK8bjRvQfQuWmdiwtndDeBADc96al45W6L_UNAPvN1EpbpqRyhXw505vSdjDCN4Urq_0L7TawMVWvdmnJqX-rgOMMz8CkijDQz0tnaCwgPw5GUPqNluXzHjWkeymMteVEhTC2LsD63goFxZvO59.png\" alt=\"\"\/><\/figure>\n\n\n\n<p class=\"has-medium-font-size wp-block-paragraph\">Now, make another custom procedure called reset. It will reset all our cards to a facedown state and will also shuffle the images. For resetting the cards to the facedown state, use a for each item block from control. Go through the buttons list and use the any component-&gt;any button blocks to set background color to orange, image to empty text block and enabled to true. The reset procedure should reset all the global variables to their initial state too.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/obsidiansofteducation.com\/wp-content\/uploads\/2024\/12\/AD_4nXdQg0N7Rz1AdRfF610ZfsmCn99HgjQcMbCk7fydIO5m0FWHtWIT5yiAkw_L0kPFQ8o0X23JzlgXtSrd_nf1rOQM-Id2NHC9PJ4JQCyS_e3TT_uBXvuummBxdHz8_LvV28ldj36jkeymMteVEhTC2LsD63goFxZvO59.png\" alt=\"\"\/><\/figure>\n\n\n\n<p class=\"has-medium-font-size wp-block-paragraph\">Now, we come to our main button click event. Don\u2019t worry, we will not be making a separate button click event for each of our 16 buttons\u2026.phew! That would be troublesome!<\/p>\n\n\n\n<p class=\"has-medium-font-size wp-block-paragraph\">We will use the awesome &#8220;any component&#8221; blocks. Go to the left side and click on any component and choose any button and inside its events, choose when any button.click event. We will first check if our allowButtonClick is true and if it is true, we will use an if\/else block from control to differentiate between reset button and picture buttons. If the button is the resetBtn then call the reset procedure.&nbsp;<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/obsidiansofteducation.com\/wp-content\/uploads\/2024\/12\/AD_4nXeImtMjcG9GXtfuqhAzbZnqI4JzoqO2zOIQA9Jhhm04zmpwqhWzizaZHVrloECD9zFWJ5vJzQnC_ZTQJGeARf34ECA3M1n_DKNHg4DBXrOclWhOg54YM161UImiNeN6-t3CEDY1DAkeymMteVEhTC2LsD63goFxZvO59.png\" alt=\"\"\/><\/figure>\n\n\n\n<p class=\"has-medium-font-size wp-block-paragraph\">In the other condition, this means that this is the picture button, we will first get the button position of the button that was actually clicked by going through our buttons list. We will set this as the button index. When we find the button index, we should also use the Control\u2019s break block to stop running the for loop.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/obsidiansofteducation.com\/wp-content\/uploads\/2024\/12\/AD_4nXcca7cpV_q75xEfBMRuDDFBEqJSYweDKsfOyDwRXP1bgAgh_9n6Flx1q0bg1q7YjNs2GTv0AadpS1ZUnKvceKgM4CTevLmytFhxwdJThK6a3eZEOtat64E5xCCLbq_le1yZZKfESwkeymMteVEhTC2LsD63goFxZvO59.png\" alt=\"\"\/><\/figure>\n\n\n\n<p class=\"has-medium-font-size wp-block-paragraph\">Once we know the button index, we need to know if it is the first card or the second card.<\/p>\n\n\n\n<p class=\"has-medium-font-size wp-block-paragraph\">In the case the not first selected condition is true then this means it is the first card. We should get the image against the button index from our images list and set this as the first selected image. We should also show the image to the user i.e. make the card face up.<\/p>\n\n\n\n<p class=\"has-medium-font-size wp-block-paragraph\">We should also set our first button variable to the clicked button and make isFirstSelected true.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/obsidiansofteducation.com\/wp-content\/uploads\/2024\/12\/AD_4nXdTx4zhIjhPwq-btvroNt9SqT68DEoPUtp3KumyOKaHfIiHCfDRk4WUydclx2OEcuBA4I6WD7Kn4hn9yevIe0-O5ck8eg4z71_yvz2rrY6kt7OOvOuJ2efzPPNzFStlwXdg41ZAYwkeymMteVEhTC2LsD63goFxZvO59.png\" alt=\"\"\/><\/figure>\n\n\n\n<p class=\"has-medium-font-size wp-block-paragraph\">If firstselected is true, we will go inside the else condition. Here, we should first make allowButtonnclicks false, make isFirstSelected false, enable the timer, assign the clicked button to the second button global variable, and also make the card face up. As we have enabled the timer, after 1000 ms i.e. 1 second, our clock\u2019s timer event will be triggered.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/obsidiansofteducation.com\/wp-content\/uploads\/2024\/12\/AD_4nXfk9vFToiHIkyqJrTD6n0IZemUertSjraEaUJGyR7KjsOvPWM6N57KBJONwBmGqcWlljJjBIQaCy_LfMk_rCLwH-A0iQHjKCKDyQiTrKcJqcPO3CehT2dX6V_bxM7DRJVsfc7OYnQkeymMteVEhTC2LsD63goFxZvO59.png\" alt=\"\"\/><\/figure>\n\n\n\n<p class=\"has-medium-font-size wp-block-paragraph\">Here, we will check if the first selected image is the same as the image on the second card. If this happens, we will disable the two paired cards. Otherwise, we will set the two buttons to their facedown state.<\/p>\n\n\n\n<p class=\"has-medium-font-size wp-block-paragraph\">And this is done. This simple memory game with 8 pairs of cards is done. You can customize it. Make the grid bigger or add a timer or more levels. So, have fun making this app.<\/p>\n\n\n\n<p class=\"has-medium-font-size wp-block-paragraph\"><strong>You can get the AIA project file for this game from here:<\/strong><\/p>\n\n\n\n<p class=\"has-medium-font-size wp-block-paragraph\"><a href=\"https:\/\/obsidiansoft.gumroad.com\/l\/widahp\" target=\"_blank\" rel=\"noopener\"><strong>https:\/\/obsidiansoft.gumroad.com\/l\/widahp<\/strong><\/a><\/p>\n\n\n\n<p class=\"has-medium-font-size wp-block-paragraph\"><strong>You can import it into MIT App Inventor and customize it or use it as it is.<\/strong><\/p>\n\n\n\n<p class=\"has-medium-font-size wp-block-paragraph\">You can also watch video tutorials (2 parts) for this amazing memory game here:<\/p>\n\n\n\n<figure class=\"wp-block-embed is-type-video is-provider-youtube wp-block-embed-youtube wp-embed-aspect-16-9 wp-has-aspect-ratio\"><div class=\"wp-block-embed__wrapper\">\n<p class=\"responsive-video-wrap clr\"><iframe loading=\"lazy\" title=\"Memory Game App Inventor (Part 1) | Picture Matching Game |  Memory Game in MIT App Inventor\" width=\"1200\" height=\"675\" src=\"https:\/\/www.youtube.com\/embed\/e-FIMazLRJA?feature=oembed\" frameborder=\"0\" allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share\" referrerpolicy=\"strict-origin-when-cross-origin\" allowfullscreen><\/iframe><\/p>\n<\/div><\/figure>\n\n\n\n<figure class=\"wp-block-embed is-type-video is-provider-youtube wp-block-embed-youtube wp-embed-aspect-16-9 wp-has-aspect-ratio\"><div class=\"wp-block-embed__wrapper\">\n<p class=\"responsive-video-wrap clr\"><iframe loading=\"lazy\" title=\"Memory Game App Inventor (Part 2) | Picture Matching Game |  Memory Game in MIT App Inventor\" width=\"1200\" height=\"675\" src=\"https:\/\/www.youtube.com\/embed\/QtYmt5zV19I?feature=oembed\" frameborder=\"0\" allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share\" referrerpolicy=\"strict-origin-when-cross-origin\" allowfullscreen><\/iframe><\/p>\n<\/div><\/figure>\n\n\n\n<p class=\"has-medium-font-size wp-block-paragraph\">I hope you enjoy making this game as much as I enjoyed designing and creating it for you.<\/p>\n\n\n\n<p class=\"has-medium-font-size wp-block-paragraph\">Please remember to subscribe if you haven\u2019t done so yet so that you don\u2019t miss any of the great tutorials that I have planned for you.<\/p>\n\n\n\n<p class=\"has-medium-font-size wp-block-paragraph\">Please like my videos and share them with your friends and family. Also, subscribe to my channel and press the bell icon so you don&#8217;t miss any of the great projects I have planned for you.<\/p>\n\n\n\n<p class=\"has-medium-font-size wp-block-paragraph\"><a href=\"https:\/\/www.blogger.com\/blog\/page\/edit\/4947000819484484884\/7140650632339107612#\" target=\"_blank\" rel=\"noopener\">https:\/\/www.youtube.com\/c\/obsidiansofteducation<\/a><\/p>\n\n\n\n<p class=\"has-medium-font-size wp-block-paragraph\">Please like my social media pages for more educational resources and tips.<\/p>\n\n\n\n<p class=\"has-medium-font-size wp-block-paragraph\">Facebook:<a href=\"https:\/\/www.blogger.com\/blog\/page\/edit\/4947000819484484884\/7140650632339107612#\" target=\"_blank\" rel=\"noopener\">&nbsp;https:\/\/www.facebook.com\/ObsidianSoft\/<\/a><\/p>\n\n\n\n<p class=\"has-medium-font-size wp-block-paragraph\">Instagram:<a href=\"https:\/\/www.blogger.com\/blog\/page\/edit\/4947000819484484884\/7140650632339107612#\" target=\"_blank\" rel=\"noopener\">&nbsp;https:\/\/www.instagram.com\/obsidiansoftapps\/<\/a><\/p>\n\n\n\n<p class=\"has-medium-font-size wp-block-paragraph\">Pinterest:<\/p>\n\n\n\n<figure class=\"wp-block-embed is-type-rich is-provider-pinterest wp-block-embed-pinterest\"><div class=\"wp-block-embed__wrapper\">\n<div class=\"oceanwp-oembed-wrap clr\"><iframe loading=\"lazy\" title=\"Obsidian Soft\" src=\"https:\/\/assets.pinterest.com\/ext\/embed.html?grid=obsidiansoft&#038;src=oembed\" height=\"900\" width=\"450\" frameborder=\"0\" scrolling=\"no\" ><\/iframe><\/div>\n<\/div><\/figure>\n\n\n\n<p class=\"has-medium-font-size wp-block-paragraph\">For links to free educational apps, have a look at the<a href=\"https:\/\/obsidiansofteducation.com\/index.php\/mobile-apps\/\">\u00a0educational apps page<\/a><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Hello friends and welcome to Obsidian Soft, Today, I will teach you how to make a memory game in MIT App Inventor i.e. a picture-matching game. Start a new project in MIT App Inventor. Let\u2019s call it MemoryGame. Make the screen orientation portrait and change the title to Memory Game. We will be making a [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":1381,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-1379","page","type-page","status-publish","has-post-thumbnail","hentry","entry","has-media"],"_links":{"self":[{"href":"https:\/\/obsidiansofteducation.com\/index.php\/wp-json\/wp\/v2\/pages\/1379","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/obsidiansofteducation.com\/index.php\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/obsidiansofteducation.com\/index.php\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/obsidiansofteducation.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/obsidiansofteducation.com\/index.php\/wp-json\/wp\/v2\/comments?post=1379"}],"version-history":[{"count":1,"href":"https:\/\/obsidiansofteducation.com\/index.php\/wp-json\/wp\/v2\/pages\/1379\/revisions"}],"predecessor-version":[{"id":6237,"href":"https:\/\/obsidiansofteducation.com\/index.php\/wp-json\/wp\/v2\/pages\/1379\/revisions\/6237"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/obsidiansofteducation.com\/index.php\/wp-json\/wp\/v2\/media\/1381"}],"wp:attachment":[{"href":"https:\/\/obsidiansofteducation.com\/index.php\/wp-json\/wp\/v2\/media?parent=1379"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}