{"id":24840,"date":"2016-09-10T03:01:44","date_gmt":"2016-09-09T17:01:44","guid":{"rendered":"http:\/\/www.rjmprogramming.com.au\/ITblog\/?p=24840"},"modified":"2016-11-10T13:19:22","modified_gmt":"2016-11-10T03:19:22","slug":"image-in-nine-game-hide-and-seek-tutorial","status":"publish","type":"post","link":"https:\/\/www.rjmprogramming.com.au\/ITblog\/image-in-nine-game-hide-and-seek-tutorial\/","title":{"rendered":"Image in Nine Game Hide and Seek Tutorial"},"content":{"rendered":"<div style=\"width: 230px\" class=\"wp-caption alignnone\"><a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/HTMLCSS\/scroll_touch.htm\"><img decoding=\"async\" style=\"border: 15px solid pink;\" alt=\"Image in Nine Game Hide and Seek  Tutorial\" src=\"http:\/\/www.rjmprogramming.com.au\/HTMLCSS\/hide_and_seek_mode.jpg\"  \/><\/a><p class=\"wp-caption-text\">Image in Nine Game Hide and Seek Tutorial<\/p><\/div>\n<p>Our &#8220;Image in Nine Game&#8221; from yesterday&#8217;s <a title='Image in Nine Game Primer Tutorial' href='#iingpt'>Image in Nine Game Primer Tutorial<\/a> as shown below, was a bit lacking as a &#8220;game&#8221; in real world terms.  But what if we added a &#8220;Hide and Seek&#8221; element to it?  Lots of people in the world know the idea of &#8220;Hide and Seek&#8221; as a game.  But doesn&#8217;t &#8220;Hide and Seek&#8221; involve at least two players?  Yes, that is so, and we don&#8217;t go inventing some new game console functionality here to add this new &#8220;Hide and Seek&#8221; functionality to our game today.  Instead, we rely on user goodwill and sense, as we so often do at this blog.  We have a &#8220;Hiding Player&#8221; and a &#8220;Finding Player&#8221; and just ask that the &#8220;Finding Player&#8221; turns away when the &#8220;Hiding Player&#8221; is selecting something to hide and using two <i>document.body<\/i> <a target=_blank title='Javascript event onload information from w3schools' href='http:\/\/www.w3schools.com\/tags\/ev_onclick.asp'><i>onclick<\/i><\/a> events to define top left and bottom right co-ordinates respectively, in time for the overlayed images to &#8220;cloud&#8221; the issue for the &#8220;Finding Player&#8221;, who will have to use scrolling techniques and clues from the name left by the &#8220;Hiding Player&#8221; as to what was hidden to &#8230;<\/p>\n<ol>\n<li>pick the correct square of nine (parts to the background image of game)<\/li>\n<li>make the hidden thing go up to the top left of that square via scrolling techniques<\/li>\n<\/ol>\n<p> &#8230; to succeed with their game quest.  Again, we show a time taken aspect to how the &#8220;Finding Player&#8221; does.  After any one finding, the game is totally reworked, and presumably, this could be the chance for the players to swap roles, perhaps &#8230; but that is up to them?!<\/p>\n<p>Along the way here you&#8217;ll have seen that a new component to our web application, which still can do all yesterday&#8217;s ideas as well, is that <i>document.body<\/i> <i>onclick<\/i> event, used exclusively in the game by the &#8220;Hiding Player&#8221;, which is made to work via a <i>document.body<\/i> <i>onload<\/i> scenario as per <b>bold<\/b> bits of HTML and Javascript code below &#8230;<\/p>\n<p><code><br \/>\n&lt;head&gt;<br \/>\n\/\/ Lots of CSS styling code and title<br \/>\n\/\/ ...<br \/>\n\/\/ End of CSS styling code and title<br \/>\n&lt;script type='text\/javascript'&gt;<br \/>\nvar i, j, imgw=0, imgh=0, factor=1.0<b>, x=0, y=0, tlx=0, tly=0, brx=0, bry=0, squarethingison=-1, rtlx=0, rtly=0, rbrx=0, rbry=0<\/b>;<br \/>\n\/\/ Lots of other Javascript code<br \/>\n\/\/ ...<br \/>\n\/\/ End of lots of other Javascript code<br \/>\n<b>function oc(event) {<br \/>\n       if (event.clientX || event.clientY) {<br \/>\n       x = event.clientX;<br \/>\n       y = event.clientY;<br \/>\n       } else {<br \/>\n       x = event.pageX;<br \/>\n       y = event.pageY;<br \/>\n       }<br \/>\n       if (!tl_click && thing != '') {<br \/>\n       tl_click=true;<br \/>\n       tlx=x;<br \/>\n       tly=y;<br \/>\n       document.title=\"Got that, 'Hiding Player', thanks.  Now the bottom right?  After that, call in 'Finding Player', quickly to see a message and to find your hidden \" + thing + \".\";<br \/>\n       document.getElementById('custom-alert-1').innerHTML=\"Got that, 'Hiding Player', thanks.  Now the bottom right?  After that, call in 'Finding Player', quickly to see a message and to find your hidden \" + thing + \".\";<br \/>\n       document.getElementById('custom-alert-1').style.visibility='visible';<br \/>\n       setTimeout(andt, hiding_fourfivehundred);<br \/>\n       } else if (!br_click && thing != '') {<br \/>\n       br_click=true;<br \/>\n       brx=x;<br \/>\n       bry=y;<br \/>\n       squarethingison=whichsquare();<br \/>\n       var imgs=document.getElementsByTagName('img');<br \/>\n       for (var m=0; m&lt;imgs.length; m++) {<br \/>\n        if (imgs[m].id != 'myimg' && thing != '') imgs[m].style.display=dmode;<br \/>\n       }<br \/>\n       document.title=\"Okay 'Finding Player', over to you to find the \" + thing + \" that 'Hiding Player' has hidden, by scrolling \" + thing + \" into the top left of relevant of Nine Parts of Image square.  The correct square must be the one scrolled in to succeed.\";<br \/>\n       document.getElementById('custom-alert-1').innerHTML=\"Okay 'Finding Player', over to you to find the \" + thing + \" that 'Hiding Player' has hidden, by scrolling \" + thing + \" into the top left of relevant of Nine Parts of Image square.  The correct square must be the one scrolled in to succeed.\";<br \/>\n       document.getElementById('custom-alert-1').style.visibility='visible';<br \/>\n       setTimeout(andt, finding_eightfivehundred);<br \/>\n       setTimeout(secondstaken, 1000);<br \/>\n       }<br \/>\n}<\/b><br \/>\n&lt;\/script&gt;<br \/>\n&lt;\/head&gt;<br \/>\n&lt;body onload='pregetwh();'<b> onclick=' oc(event);  ' ontouchstart=' oc(event);  '<\/b>&gt;<br \/>\n<\/code><\/p>\n<p>We channelled our temporary dialog (like Android &#8220;toast&#8221;) functionality we talked about at <a target=_blank href='https:\/\/www.rjmprogramming.com.au\/ITblog\/web-slideshow-like-powerpoint-hashtag-navigation-tutorial\/' title='Web Slideshow Like PowerPoint Hashtag Navigation Tutorial'>Web Slideshow Like PowerPoint Hashtag Navigation Tutorial<\/a> to place some temporary &#8220;overlayed&#8221; advice for the Hide and Seek players as the game progresses.<\/p>\n<p>So what&#8217;s the opening &#8220;blurb&#8221; of the web application game now &#8230;<\/p>\n<blockquote><p>\nWelcome to our Image in Nine Games &#8230; firstly, one player mode game is a bit like a jigsaw game, with the top left of nine filled in (they have a yellow border when fitting nicely &#8230; though there is a tolerance) &#8230; and help for others via faint underneath image and getting numbers up in the title close to zero &#8230; once you move the other eight pieces around via one finger swipe gesture for mobile or scrolling for non-mobile.  This starting image is <a target=_blank title='http:\/\/www.rjmprogramming.com.au\/HTMLCSS\/your_acronyms.jpg' href='http:\/\/www.rjmprogramming.com.au\/HTMLCSS\/your_acronyms.jpg'>http:\/\/www.rjmprogramming.com.au\/HTMLCSS\/your_acronyms.jpg<\/a> and you can practice or give up by using <a target=_blank title='http:\/\/www.rjmprogramming.com.au\/HTMLCSS\/scroll_touch.htm?goes=1' href='http:\/\/www.rjmprogramming.com.au\/HTMLCSS\/scroll_touch.htm?goes=1'>http:\/\/www.rjmprogramming.com.au\/HTMLCSS\/scroll_touch.htm?goes=1<\/a> URL in order to specify your own URL image as required, or enter your own image URL below, or as a collaborative game for two (Hiding Player and Finding Player), enter name of Thing You Want Other Player to Find or [image URL]&#038;thing=[Thing You Want Other Player to Find]\n<\/p><\/blockquote>\n<p>And here is the new <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/HTMLCSS\/scroll_touch.htm\">live run<\/a> link to the &#8220;Image in Nine Game&#8221; including a &#8220;Hide and Seek&#8221; component, that has this HTML and Javascript and CSS programming source code you could call <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/HTMLCSS\/scroll_touch.html-GETME\">scroll_touch.htm<\/a> that changed from yesterday in <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/PHP\/Geographicals\/diff.php?one=http:\/\/www.rjmprogramming.com.au\/HTMLCSS\/scroll_touch.html-GETME\">this way<\/a>.<\/p>\n<p>We&#8217;ll leave you with a fairly obvious theme of usage of this game with a <a target=_blank title='?' href='http:\/\/www.rjmprogramming.com.au\/HTMLCSS\/scroll_touch.htm?image=http:\/\/i.imgur.com\/Bl9ZQQG.jpg&#038;score=1&#038;thing=Wally&#038;goes=0&#038;seconds=0'>Where&#8217;s Wally<\/a> scenario, the image for which we&#8217;d like to thank the <a target=_blank title='http:\/\/i.imgur.com\/' href='http:\/\/i.imgur.com\/'>imgur<\/a> website.<\/p>\n<p><b><i>Did you know?<\/i><\/b><\/p>\n<p>Sometimes, as with today&#8217;s game, but not always, with web applications, if you&#8217;ve forgotten to &#8220;test mobile&#8221; &#8230; how sinful &#8230; you&#8217;ll find that wherever you have some <i>onclick<\/i> event code you can just double up the same logic for an <a target=_blank title='Ontouchstart event information' href='https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/API\/GlobalEventHandlers\/ontouchstart'><i>ontouchstart<\/i><\/a> event, and have your web application burst to life in the mobile wooooooorrrrrrlllld.<\/p>\n<hr>\n<p id='iingpt'>Previous relevant <a target=_blank title='Image in Nine Game Primer Tutorial' href='https:\/\/www.rjmprogramming.com.au\/ITblog\/image-in-nine-game-primer-tutorial\/'>Image in Nine Game Primer Tutorial<\/a> is shown below.<\/p>\n<div style=\"width: 230px\" class=\"wp-caption alignnone\"><a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/HTMLCSS\/scroll_touch.html\"><img decoding=\"async\" style=\"border: 15px solid pink;\" alt=\"Image in Nine Game Primer Tutorial\" src=\"http:\/\/www.rjmprogramming.com.au\/HTMLCSS\/scroll_touch.jpg\"  \/><\/a><p class=\"wp-caption-text\">Image in Nine Game Primer Tutorial<\/p><\/div>\n<p>Today we&#8217;ve written a web application game that really benefits, in its mobile device incarnations, by &#8220;touch scrolling&#8221; or <a target=_blank title='Momentum-based scrolling information' href='https:\/\/css-tricks.com\/snippets\/css\/momentum-scrolling-on-ios-overflow-elements\/'>momentum-based scrolling<\/a> techniques.<\/p>\n<p>We found lots of great advice for today&#8217;s game from the Open Source community on the net, and give thanks to &#8230;<\/p>\n<ul>\n<li>CSS <a target=_blank title='Useful link' href='https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/CSS\/-webkit-overflow-scrolling'>momentum-based scrolling<\/a> setting for touch devices advice<\/li>\n<li>great CSS <a target=_blank title='Useful link' href='http:\/\/www.css3.info\/preview\/multiple-backgrounds\/'>multiple background image<\/a> advice<\/li>\n<li>use of CSS <a target=_blank title=\"CSS overflow:hidden idea information from w3schools ... thanks\" href=\"http:\/\/www.w3schools.com\/cssref\/pr_pos_overflow.asp\"><i>overflow: scroll<\/i> property<\/a> in a &#8220;reveal&#8221; themed approach<\/li>\n<li>good general use of <a target=_blank title='Useful link' href='https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/API\/Canvas_API\/Tutorial\/Using_images'>images<\/a> webpage<\/li>\n<li>Javascript <a target=_blank title='Useful link' href='http:\/\/stackoverflow.com\/questions\/2950382\/onscroll-for-div'>scrolling<\/a> event advice<\/li>\n<li>helped with <a target=_blank title='Useful link' href='http:\/\/stackoverflow.com\/questions\/442404\/retrieve-the-position-x-y-of-an-html-element'>scrolling event co-ordinate definition<\/a> via the Javascript <a target=_blank title='Useful link' href='https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/API\/Element\/getBoundingClientRect'>element.getBoundingClientRect<\/a>() function<\/li>\n<li>set us right to <a target=_blank title='Useful link' href='http:\/\/stackoverflow.com\/questions\/18564561\/how-to-specify-how-many-pixels-scroll-moves-on-each-step'>stop thinking that it would be a good idea to try to control the smallest scrolling resolution unit<\/a><\/li>\n<li>the CSS &#8220;overlay&#8221; usual suspects coming into play were <a target=_blank title='CSS position:absolute information from w3schools' href='http:\/\/www.w3schools.com\/cssref\/pr_class_position.asp'>position:absolute<\/a> property and <a target=_blank title='CSS z-index information from w3schools' href='http:\/\/www.w3schools.com\/cssref\/pr_pos_z-index.asp'>z-index<\/a> and <a target=_blank title='CSS opacity information from w3schools' href='http:\/\/www.w3schools.com\/css\/css_image_transparency.asp'>opacity<\/a><\/li>\n<\/ul>\n<p>So what is our game?  Here&#8217;s the opening &#8220;blurb&#8221; for it &#8230;<\/p>\n<blockquote><p>\nWelcome to our Image in Nine Game &#8230; bit like a jigsaw game with top left of nine filled in (they have a yellow border when fitting nicely &#8230; though there is a tolerance) &#8230; and help for others via faint underneath image and getting numbers up in the title close to zero &#8230; once you move the other eight pieces around via one finger swipe gesture for mobile or scrolling for non-mobile.  This starting image is <a target=_blank title='http:\/\/www.rjmprogramming.com.au\/HTMLCSS\/your_acronyms.jpg' href='http:\/\/www.rjmprogramming.com.au\/HTMLCSS\/your_acronyms.jpg'>http:\/\/www.rjmprogramming.com.au\/HTMLCSS\/your_acronyms.jpg<\/a> and you can practice or give up by using <a target=_blank title='http:\/\/www.rjmprogramming.com.au\/HTMLCSS\/scroll_touch.html?goes=1' href='http:\/\/www.rjmprogramming.com.au\/HTMLCSS\/scroll_touch.html?goes=1'>http:\/\/www.rjmprogramming.com.au\/HTMLCSS\/scroll_touch.html?goes=1<\/a> URL in order to specify your own URL image as required, or enter your own image URL below.\n<\/p><\/blockquote>\n<p>It&#8217;s a simple premise.  An image gets cut evenly up into nine equal area pieces, a bit like a jigsaw.  We add this to a table of HTML div elements including the <i>game&#8217;s image<\/i> as a background image with a defined <a target=_blank title='CSS background-position property information from w3schools' href='http:\/\/www.w3schools.com\/cssref\/pr_background-position.asp'>background-position<\/a> property, within HTML table td cells.  Those HTML div elements &#8220;reveal&#8221; the <i>game image<\/i> again overlayed on top, but with no offsets in positioning, so you end up with the top left cell&#8217;s HTML div element being totally fine, and so showing a yellow border to indicate this.  But the mobile user will need to use <i>momentum-based scrolling<\/i> and the non-mobile user can use normal scrolling techniques to pull the &#8220;overlayed&#8221; image back into the correct &#8220;jigsaw&#8221; position, and get a yellow border, to succeed at the game.  There is a numerical reporting helper in <i>document.title<\/i> that when creeping towards zero helps the user out with their positioning.  We time the user doing this, should they want to try the game again to try to improve, perhaps with their own image URL in mind.<\/p>\n<p>Here is the <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/HTMLCSS\/scroll_touch.html\">live run<\/a> link to the &#8220;Image in Nine Game&#8221; that has this HTML and Javascript and CSS programming source code you could call <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/HTMLCSS\/scroll_touch.html_GETME\">scroll_touch.html<\/a> and here for your perusal. And here is a <a target=_blank title='Live run for an Australian Lighthouses' href='http:\/\/www.rjmprogramming.com.au\/HTMLCSS\/scroll_touch.html?image=http%3A%2F%2Fwww.rjmprogramming.com.au%2FPHP%2Faustralian_lighthouses.jpg'>live run for an Australian Lighthouses<\/a> image.<\/p>\n<p>If this was interesting you may be interested in <a title='Click here to see topics in which you might be interested' href='#d24823' onclick='var dv=document.getElementById(\"d24823\"); dv.innerHTML = \"&lt;iframe width=670 height=600 src=\" + \"https:\/\/www.rjmprogramming.com.au\/ITblog\/tag\/scrolling\" + \"&gt;&lt;\/iframe&gt;\"; dv.style.display = \"block\";'>this<\/a> too.<\/p>\n<div id='d24823' style='display: none; border-left: 2px solid green; border-top: 2px solid green;'><\/div>\n<hr>\n<p>If this was interesting you may be interested in <a title='Click here to see topics in which you might be interested' href='#d24840' onclick='var dv=document.getElementById(\"d24840\"); dv.innerHTML = \"&lt;iframe width=670 height=600 src=\" + \"https:\/\/www.rjmprogramming.com.au\/ITblog\/tag\/onclick\" + \"&gt;&lt;\/iframe&gt;\"; dv.style.display = \"block\";'>this<\/a> too.<\/p>\n<div id='d24840' style='display: none; border-left: 2px solid green; border-top: 2px solid green;'><\/div>\n","protected":false},"excerpt":{"rendered":"<p>Our &#8220;Image in Nine Game&#8221; from yesterday&#8217;s Image in Nine Game Primer Tutorial as shown below, was a bit lacking as a &#8220;game&#8221; in real world terms. But what if we added a &#8220;Hide and Seek&#8221; element to it? Lots &hellip; <a href=\"https:\/\/www.rjmprogramming.com.au\/ITblog\/image-in-nine-game-hide-and-seek-tutorial\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[12,15,37],"tags":[281,327,342,476,477,576,590,652,1610,2006,861,873,894,997,1063,1917,1107,1238,1288,1319],"class_list":["post-24840","post","type-post","status-publish","format-standard","hentry","category-elearning","category-games","category-tutorials","tag-css","tag-did-you-know","tag-div","tag-game","tag-games-2","tag-html","tag-image","tag-javascript","tag-lighthouse","tag-momentum-based-scrolling","tag-onclick","tag-ontouchstart","tag-overlay","tag-programming","tag-reveal","tag-scroll","tag-scrolling","tag-table","tag-toast","tag-tutorial"],"_links":{"self":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts\/24840"}],"collection":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/comments?post=24840"}],"version-history":[{"count":19,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts\/24840\/revisions"}],"predecessor-version":[{"id":26302,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts\/24840\/revisions\/26302"}],"wp:attachment":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/media?parent=24840"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/categories?post=24840"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/tags?post=24840"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}