{"id":884,"date":"2014-09-03T19:18:13","date_gmt":"2014-09-03T07:18:13","guid":{"rendered":"http:\/\/www.davidbrebner.com\/?p=884"},"modified":"2014-09-03T22:38:20","modified_gmt":"2014-09-03T10:38:20","slug":"mad-memory-advanced-scripts-for-umajin","status":"publish","type":"post","link":"https:\/\/davidbrebner.com\/?p=884","title":{"rendered":"Mad Memory &#8211; Advanced scripts for Umajin"},"content":{"rendered":"<p><img decoding=\"async\" src=\"http:\/\/www.davidbrebner.com\/wp-content\/uploads\/2014\/09\/memory_header.jpg\" alt=\"memory_header\" width=\"900\" height=\"300\" class=\"alignnone size-full wp-image-885\" srcset=\"https:\/\/davidbrebner.com\/wp-content\/uploads\/2014\/09\/memory_header.jpg 900w, https:\/\/davidbrebner.com\/wp-content\/uploads\/2014\/09\/memory_header-150x50.jpg 150w, https:\/\/davidbrebner.com\/wp-content\/uploads\/2014\/09\/memory_header-300x100.jpg 300w\" sizes=\"(max-width: 900px) 100vw, 900px\" \/><\/p>\n<p>This example shows a more complex custom script which is used to make a memory game .<\/p>\n<p><img decoding=\"async\" src=\"http:\/\/www.davidbrebner.com\/wp-content\/uploads\/2014\/09\/memory_code1.png\" alt=\"memory_code1\" width=\"534\" height=\"464\" class=\"alignnone size-full wp-image-886\" srcset=\"https:\/\/davidbrebner.com\/wp-content\/uploads\/2014\/09\/memory_code1.png 534w, https:\/\/davidbrebner.com\/wp-content\/uploads\/2014\/09\/memory_code1-150x130.png 150w, https:\/\/davidbrebner.com\/wp-content\/uploads\/2014\/09\/memory_code1-300x260.png 300w\" sizes=\"(max-width: 534px) 100vw, 534px\" \/><\/p>\n<p>The first piece of the script registers the memorygame function setting it to take a row and a column (between 1 and 4).<\/p>\n<p>Then global tables\/arrays are created to hold the memory items, state and current card.  The cards are allocated in pairs, and then ten sets of pairs are swapped to shuffle the deck.<\/p>\n<p><img decoding=\"async\" src=\"http:\/\/www.davidbrebner.com\/wp-content\/uploads\/2014\/09\/memory_code2.png\" alt=\"memory_code2\" width=\"691\" height=\"465\" class=\"alignnone size-full wp-image-887\" srcset=\"https:\/\/davidbrebner.com\/wp-content\/uploads\/2014\/09\/memory_code2.png 691w, https:\/\/davidbrebner.com\/wp-content\/uploads\/2014\/09\/memory_code2-150x100.png 150w, https:\/\/davidbrebner.com\/wp-content\/uploads\/2014\/09\/memory_code2-300x201.png 300w, https:\/\/davidbrebner.com\/wp-content\/uploads\/2014\/09\/memory_code2-120x80.png 120w\" sizes=\"(max-width: 691px) 100vw, 691px\" \/><\/p>\n<p>This script block is the main function. It remembers the component the user clicked on (self) by storing it in the memory_item table\/array.  If it&#8217;s the first card clicked on (and it&#8217;s not already flipped) the card is turned over with an animation.  If it&#8217;s the second card then it&#8217;s compared to the first card.  If its a match we bounce the cards and leave them face up.  If it&#8217;s not a match then the cards are turned back over.<\/p>\n<p><img decoding=\"async\" src=\"http:\/\/www.davidbrebner.com\/wp-content\/uploads\/2014\/09\/memory_code3.png\" alt=\"memory_code3\" width=\"476\" height=\"323\" class=\"alignnone size-full wp-image-888\" srcset=\"https:\/\/davidbrebner.com\/wp-content\/uploads\/2014\/09\/memory_code3.png 476w, https:\/\/davidbrebner.com\/wp-content\/uploads\/2014\/09\/memory_code3-150x101.png 150w, https:\/\/davidbrebner.com\/wp-content\/uploads\/2014\/09\/memory_code3-300x203.png 300w, https:\/\/davidbrebner.com\/wp-content\/uploads\/2014\/09\/memory_code3-120x80.png 120w\" sizes=\"(max-width: 476px) 100vw, 476px\" \/><\/p>\n<p>This final code is some helper functions which use the handy set_prop_in function to set properties in a specified time in miliseconds.  This creates the animation you see as the values change.<\/p>\n<p>Finally here is a video of the game in action.<\/p>\n<p><iframe width=\"853\" height=\"480\" src=\"\/\/www.youtube.com\/embed\/7u5M4GBrck0\" frameborder=\"0\" allowfullscreen><\/iframe><\/p>\n","protected":false},"excerpt":{"rendered":"<p>This example shows a more complex custom script which is used to make a memory game . The first piece [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":885,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"image","meta":{"footnotes":""},"categories":[40],"tags":[],"class_list":["post-884","post","type-post","status-publish","format-image","has-post-thumbnail","hentry","category-umaijn","post_format-post-format-image"],"_links":{"self":[{"href":"https:\/\/davidbrebner.com\/index.php?rest_route=\/wp\/v2\/posts\/884","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/davidbrebner.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/davidbrebner.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/davidbrebner.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/davidbrebner.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=884"}],"version-history":[{"count":3,"href":"https:\/\/davidbrebner.com\/index.php?rest_route=\/wp\/v2\/posts\/884\/revisions"}],"predecessor-version":[{"id":891,"href":"https:\/\/davidbrebner.com\/index.php?rest_route=\/wp\/v2\/posts\/884\/revisions\/891"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/davidbrebner.com\/index.php?rest_route=\/wp\/v2\/media\/885"}],"wp:attachment":[{"href":"https:\/\/davidbrebner.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=884"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/davidbrebner.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=884"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/davidbrebner.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=884"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}