{"id":43777,"date":"2019-02-23T03:01:40","date_gmt":"2019-02-22T17:01:40","guid":{"rendered":"http:\/\/www.rjmprogramming.com.au\/ITblog\/?p=43777"},"modified":"2019-02-24T19:12:41","modified_gmt":"2019-02-24T09:12:41","slug":"simon-says-game-primer-tutorial","status":"publish","type":"post","link":"https:\/\/www.rjmprogramming.com.au\/ITblog\/simon-says-game-primer-tutorial\/","title":{"rendered":"Simon Says Game Primer Tutorial"},"content":{"rendered":"<div style=\"width: 230px\" class=\"wp-caption alignnone\"><a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/HTMLCSS\/doc_qs.html\"><img decoding=\"async\" style=\"border: 15px solid pink;\" alt=\"Simon Says Game Primer Tutorial\" src=\"http:\/\/www.rjmprogramming.com.au\/HTMLCSS\/simon_says.jpg\" title=\"Simon Says Game Primer Tutorial\"  style=\"float:left;\"   \/><\/a><p class=\"wp-caption-text\">Simon Says Game Primer Tutorial<\/p><\/div>\n<p>One of the great things about the &#8220;net&#8221; is learning things off other people.  Here at this blog we&#8217;ve mentioned the stupendous <a target=_blank title='Great link' href='http:\/\/www.html5rocks.com\/en\/tutorials\/file\/dndfiles\/'>HTML5 File API<\/a> link we&#8217;ve used a lot for &#8220;shape to upload&#8221; local disk file browsing purposes in so many web applications we&#8217;ve talked about.  So, thanks for that, but that File API brilliance is not all we learnt by putting that logic into play.  We&#8217;ve not up until now, formalized it into a &#8220;proof of concept&#8221; web application, but we&#8217;ve now adapted its &#8230;<\/p>\n<table>\n<tr>\n<th>At <a target=_blank title='Great link' href='http:\/\/www.html5rocks.com\/en\/tutorials\/file\/dndfiles\/'>HTML5 File API<\/a> &#8230;<\/th>\n<\/tr>\n<tr>\n<td>\n<blockquote cite='http:\/\/www.html5rocks.com\/en\/tutorials\/file\/dndfiles\/'><p>\ndocument.querySelector(&#8216;.readBytesButtons&#8217;).addEventListener(&#8216;click&#8217;, function(evt) {<br \/>\n    if (evt.target.tagName.toLowerCase() == &#8216;button&#8217;) {<br \/>\n      var startByte = evt.target.getAttribute(&#8216;data-startbyte&#8217;);<br \/>\n      var endByte = evt.target.getAttribute(&#8216;data-endbyte&#8217;);<br \/>\n      readBlob(startByte, endByte);<br \/>\n    }<br \/>\n  }, false);\n<\/p><\/blockquote>\n<\/td>\n<\/tr>\n<tr>\n<th>Adapted for a <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/HTMLCSS\/doc_qs.html\" title=\"Click picture\">Simon Says<\/a> Game<\/th>\n<\/tr>\n<tr>\n<td>\ndocument.querySelector(&#8216;.classy&#8217;).addEventListener(&#8216;click&#8217;, function(evt) {<br \/>\n    if (evt.target.tagName.toLowerCase() == &#8216;button&#8217;) {<br \/>\n      eval(evt.target.title);<br \/>\n    }<br \/>\n}, false);\n<\/td>\n<\/tr>\n<\/table>\n<p>Let&#8217;s learn a bit more about the crucial <a target=_blank title='Javascript DOM document.querySelector information from w3schools' href='https:\/\/www.w3schools.com\/jsref\/met_document_queryselector.asp'>document.querySelector<\/a> method &#8230;<\/p>\n<blockquote cite='https:\/\/www.w3schools.com\/jsref\/met_document_queryselector.asp'><p>\nThe querySelector() method returns the first element that matches a specified CSS selector(s) in the document.\n<\/p><\/blockquote>\n<p>For me, and I grant you it might just be me, but it breaks the nexus in my mind that I should always be thinking &#8230;<\/p>\n<ul>\n<li>HTML element <a target=_blank title='HTML ID attribute information from w3schools' href='https:\/\/www.w3schools.com\/html\/html_id.asp'>ID<\/a> attribute is associated with Javascript DOM (action) work &#8230; eg. clicking a button and looking after other event logics<\/li>\n<li>HTML element <a target=_blank title='HTML class attribute information from w3schools' href='https:\/\/www.w3schools.com\/tags\/att_class.asp'>class<\/a> attribute is associated with CSS (styling) work<\/li>\n<\/ul>\n<p> &#8230; and not quite &#8220;never the twain shall meet&#8221; because ID CSS is commonly used by us, but generally the above principles hold for us.<\/p>\n<p>The use of the <a target=_blank title='Javascript DOM document.querySelector information from w3schools' href='https:\/\/www.w3schools.com\/jsref\/met_document_queryselector.asp'>document.querySelector<\/a> method above turns this on its head though, to the extent that with the underlying Simon Says game HTML and Javascript and CSS <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/HTMLCSS\/doc_qs.html_GETME\" title=\"doc_qs.html\">doc_qs.html<\/a> code &#8230;<\/p>\n<ul>\n<li>no HTML elements needed any ID attributes &#8230; and yet &#8230;<\/li>\n<li>HTML button elements with a class are controlled by onclick logic instigated by that right hand Javascript code above &#8230; but it had to be (a little awkwardly, we grant you) arranged that &#8230;<\/li>\n<li>only one HTML button class=&#8217;classy&#8217; exists at any given time to allow that <a target=_blank title='Javascript DOM document.querySelector information from w3schools' href='https:\/\/www.w3schools.com\/jsref\/met_document_queryselector.asp'>document.querySelector<\/a> methodology to serve its purpose in the Simon Says game (which is just a bit of fun trying to succeed with what Simon Says to turn its underlying table all green)<\/li>\n<\/ul>\n<p>We hope this is of interest to you too, and thanks to <a target=_blank title='Useful link, thanks' href='https:\/\/stackoverflow.com\/questions\/11373841\/make-a-3d-button-with-rounded-edge'>this useful link<\/a> for some CSS ideas for button styling, and <a target=_blank title='30 Funniest Simon Says Ideas' href='https:\/\/playtivities.com\/30-funniest-simon-says-ideas\/'>30 Funniest Simon Says Ideas<\/a> for Simon Says ideas.<\/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='#d43777' onclick='var dv=document.getElementById(\"d43777\"); dv.innerHTML = \"&lt;iframe width=670 height=600 src=\" + \"https:\/\/www.rjmprogramming.com.au\/ITblog\/tag\/class\" + \"&gt;&lt;\/iframe&gt;\"; dv.style.display = \"block\";'>this<\/a> too.<\/p>\n<div id='d43777' style='display: none; border-left: 2px solid green; border-top: 2px solid green;'><\/div>\n","protected":false},"excerpt":{"rendered":"<p>One of the great things about the &#8220;net&#8221; is learning things off other people. Here at this blog we&#8217;ve mentioned the stupendous HTML5 File API link we&#8217;ve used a lot for &#8220;shape to upload&#8221; local disk file browsing purposes in &hellip; <a href=\"https:\/\/www.rjmprogramming.com.au\/ITblog\/simon-says-game-primer-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,14,37],"tags":[112,210,281,349,354,400,476,477,576,2846,652,861,997,2835,1319],"class_list":["post-43777","post","type-post","status-publish","format-standard","hentry","category-elearning","category-event-driven-programming","category-tutorials","tag-attribute","tag-class","tag-css","tag-document","tag-dom","tag-event","tag-game","tag-games-2","tag-html","tag-id","tag-javascript","tag-onclick","tag-programming","tag-queryselector","tag-tutorial"],"_links":{"self":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts\/43777"}],"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=43777"}],"version-history":[{"count":5,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts\/43777\/revisions"}],"predecessor-version":[{"id":43782,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts\/43777\/revisions\/43782"}],"wp:attachment":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/media?parent=43777"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/categories?post=43777"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/tags?post=43777"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}