{"id":62094,"date":"2023-12-28T03:01:56","date_gmt":"2023-12-27T17:01:56","guid":{"rendered":"http:\/\/www.rjmprogramming.com.au\/ITblog\/?p=62094"},"modified":"2023-12-28T06:29:55","modified_gmt":"2023-12-27T20:29:55","slug":"phpjavascript-decoding-scrambled-words-game-css-tutorial","status":"publish","type":"post","link":"https:\/\/www.rjmprogramming.com.au\/ITblog\/phpjavascript-decoding-scrambled-words-game-css-tutorial\/","title":{"rendered":"PHP\/Javascript Decoding Scrambled Words Game CSS Tutorial"},"content":{"rendered":"<div style=\"width: 230px\" class=\"wp-caption alignnone\"><a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/PHP\/DecodingScrambledWords\/\"><img decoding=\"async\" style=\"float:left;border: 15px solid pink;\" alt=\"PHP Decoding Scrambled Words Game CSS Tutorial\" src=\"http:\/\/www.rjmprogramming.com.au\/PHP\/DecodingScrambledWords\/decodewords_css_makeover.jpg\" title=\"PHP\/Javascript Decoding Scrambled Words Game CSS Tutorial\"  \/><\/a><p class=\"wp-caption-text\">PHP\/Javascript Decoding Scrambled Words Game CSS Tutorial<\/p><\/div>\n<p>It can be hard for a Javascript DOM aficionado to be restricted to &#8220;just CSS styling&#8221; means by which to give a web application &#8220;a bit of a&#8221; makeover.  Yes, &#8220;a bit of a&#8221; is apt.   We&#8217;re not going overboard, and besides, CSS styling is an art form a lot of people are better at than moi.  And we tend towards &#8220;mild masochism&#8221;, so there you go.  Never mind, it is CSS selector possibilities we want to impart today, and today, with our new PHP writes CSS code &#8230;<\/p>\n<p>&lt;?php<br \/>\n<code><br \/>\necho \"\\n\" , '&lt;style&gt;' . \"\\n\";<br \/>\necho \"\\n\" , ' h1 { text-shadow: -2px 2px 2px #2dff95;  } ' . \"\\n\";<br \/>\necho \"\\n\" , ' select { text-shadow:  -1px 1px 1px #ff2d95;  } ' . \"\\n\";<br \/>\necho \"\\n\" , ' span b i { text-shadow: -1px 1px 1px #95ff2d; min-width:60px;  } ' . \"\\n\";<br \/>\necho \"\\n\" , ' h2 { text-shadow: -1px 1px 1px #952dff;   } ' . \"\\n\";<br \/>\necho \"\\n\" , ' .guess* { width: 60px; } ' . \"\\n\"; \/\/ thanks to https:\/\/stackoverflow.com\/questions\/13352080\/match-all-elements-having-class-name-starting-with-a-specific-string<br \/>\necho \"\\n\" , \" select[name^='guess'] { width: 60px; } \" . \"\\n\"; \/\/ https:\/\/stackoverflow.com\/questions\/41832255\/css-class-name-selector-name-starts-with<br \/>\necho \"\\n\" , ' input { margin-top: 25px; border-radius: 20px;  } ' . \"\\n\";<br \/>\necho \"\\n\" , \" input[type='button'] { background-color: magenta; padding: 5 5 5 5;  } \" . \"\\n\";<br \/>\necho \"\\n\" , \" input[value^='Please'] { background-color: lightgreen;  } \" . \"\\n\";<br \/>\necho \"\\n\" , \" #selease { background-color: orange;  border-radius: 20px; padding: 5 5 5 5;  } \" . \"\\n\";<br \/>\necho \"\\n\" , '&lt;\/style&gt;' . \"\\n\";<br \/>\n<\/code><br \/>\n?&gt;<\/p>\n<p> &#8230; it wasn&#8217;t used <font size=1>in anger<\/font> today, because of our &#8220;masochistic tendencies&#8221;, but that &#8220;class starts with&#8221; CSS selector syntax we hadn&#8217;t ever used, and is very interesting &#8230;<\/p>\n<p>&lt;style&gt;<br \/>\n<code><br \/>\n.guess* { width: 40px; }    \/\/ thanks to <a target=_blank title='https:\/\/stackoverflow.com\/questions\/13352080\/match-all-elements-having-class-name-starting-with-a-specific-string' href='https:\/\/stackoverflow.com\/questions\/13352080\/match-all-elements-having-class-name-starting-with-a-specific-string'>https:\/\/stackoverflow.com\/questions\/13352080\/match-all-elements-having-class-name-starting-with-a-specific-string<\/a><br \/>\n<\/code><br \/>\n&lt;\/style&gt;<\/p>\n<p> &#8230; let alone what was used (ie. select element name attribute &#8220;starts with&#8221; ^ syntax) and opens up interesting possibilities too &#8230;<\/p>\n<p>&lt;style&gt;<br \/>\n<code><br \/>\n select[name^='guess'] { width: 40px; }  \/\/ <a target=_blank title='https:\/\/stackoverflow.com\/questions\/41832255\/css-class-name-selector-name-starts-with' href='https:\/\/stackoverflow.com\/questions\/41832255\/css-class-name-selector-name-starts-with'>https:\/\/stackoverflow.com\/questions\/41832255\/css-class-name-selector-name-starts-with<\/a><br \/>\n<\/code><br \/>\n&lt;\/style&gt;<\/p>\n<p> &#8230; in <a target=_blank href='https:\/\/www.rjmprogramming.com.au\/PHP\/Geographicals\/diff.php?one=https:\/\/www.rjmprogramming.com.au\/PHP\/DecodingScrambledWords\/decodewords.php--GETME'>the mildly made over<\/a> <a target=_blank href='https:\/\/www.rjmprogramming.com.au\/PHP\/DecodingScrambledWords\/decodewords.php--GETME'>decodewords.php<\/a> <a target=_blank href='https:\/\/www.rjmprogramming.com.au\/PHP\/DecodingScrambledWords\/decodewords.php'>web application<\/a> following on from the recent <a title='PHP\/Javascript Decoding Scrambled Words Game Difficulty Tutorial' href='#php\/jdswgdt'>PHP\/Javascript Decoding Scrambled Words Game Difficulty Tutorial<\/a>.<\/p>\n<p>So, thank you, real CSS styling aficionados out there in the online wooooooooorrrrrrllllllllddddd!<\/p>\n<p><!--p>You can also see this play out at WordPress 4.1.1's <a target=_blank  href='\/\/www.rjmprogramming.com.au\/ITblog\/php\/javascript-decoding-scrambled-words-game-css-tutorial\/'>PHP\/Javascript Decoding Scrambled Words Game CSS Tutorial<\/a>.<\/p-->\n<hr>\n<p id='php\/jdswgdt'>Previous relevant <a target=_blank title='PHP\/Javascript Decoding Scrambled Words Game Difficulty Tutorial' href='\/\/www.rjmprogramming.com.au\/ITblog\/php\/javascript-decoding-scrambled-words-game-difficulty-tutorial\/'>PHP\/Javascript Decoding Scrambled Words Game Difficulty Tutorial<\/a> is shown below.<\/p>\n<div style=\"width: 230px\" class=\"wp-caption alignnone\"><a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/PHP\/DecodingScrambledWords\/\"><img decoding=\"async\" style=\"float:left;border: 15px solid pink;\" alt=\"PHP Decoding Scrambled Words Game Difficulty Tutorial\" src=\"http:\/\/www.rjmprogramming.com.au\/PHP\/DecodingScrambledWords\/decodewords_revisit.jpg\" title=\"PHP\/Javascript Decoding Scrambled Words Game Difficulty Tutorial\"  \/><\/a><p class=\"wp-caption-text\">PHP\/Javascript Decoding Scrambled Words Game Difficulty Tutorial<\/p><\/div>\n<p>We often find it hard coding an online game, working out with an audience where to pitch its &#8220;difficulty value&#8221;.  On revisiting the Decoding Scrambled Letter Game of <a title='PHP\/Javascript Decoding Scrambled Words Game Tutorial' href='#php\/jdswgt'>PHP\/Javascript Decoding Scrambled Words Game Tutorial<\/a> the other day, it took us a while to <sub>re<\/sub>figure out what was going on, and on understanding, realized it is a decoding game and maybe it will be difficult, and it should stay that way.  But then again, if users just give up without trying it, well, that is not very good either.<\/p>\n<p>So we decided to make changes that were optional regarding how the user plays the game, but helped just like hints can help in a game.  Besides, we&#8217;ve been itching to try to involve that game a lot of us played as children &#8230;<\/p>\n<blockquote><p>\nYou&#8217;re getting warmer!\n<\/p><\/blockquote>\n<p> &#8230; when a player is getting closer to the correct answer.  This is a way to help while not exactly &#8220;giving the game away&#8221;, so to speak.<\/p>\n<p>What can hide data from a user who is not interested in Web Inspectors?  Yes, <a target=_blank href='https:\/\/www.w3schools.com\/tags\/att_global_data.asp' title='Global data attributes information from W3schools'>global data attributes<\/a> are a way, and in this new &#8220;Easy&#8221; mode of play for the game, all those dropdown (ie. select) elements are given a <i>data-correct<\/i> global data attribute allowing us, as programmers, to start using new document.body &#8220;onload&#8221; Javascript (function datait) functionality, as below &#8230;<\/p>\n<p><code><br \/>\nfunction datait() {<br \/>\n  var thisword='';<br \/>\n  for (var ii=1; ii&lt;=4; ii++) {<br \/>\n    thisword=document.getElementById('word' + ii + 'of4').value;<br \/>\n    for (var jj=1; jj&lt;=thisword.length; jj++) {<br \/>\n      if (document.getElementById('guess' + ii + '' + jj)) {<br \/>\n       if (document.URL.toLowerCase().indexOf('debug=y') != -1) {<br \/>\n        document.getElementById('lotsofcheck').checked=true;<br \/>\n        document.getElementById('sc').style.display='inline-block';<br \/>\n        document.getElementById('guess' + ii + '' + jj).setAttribute('data-correct', thisword.substring(eval(-1 + jj)).substring(0,1));<br \/>\n       } else if  (document.URL.toLowerCase().indexOf('debug=') != -1) {<br \/>\n        document.getElementById('sc').style.display='inline-block';<br \/>\n        document.getElementById('guess' + ii + '' + jj).setAttribute('data-correct', thisword.substring(eval(-1 + jj)).substring(0,1));<br \/>\n       }<br \/>\n      }<br \/>\n    }<br \/>\n  }<br \/>\n  if (document.URL.toLowerCase().indexOf('debug=') != -1) {<br \/>\n    document.getElementById('defopt').innerText='Easy';<br \/>\n  }<br \/>\n}<br \/>\n<br \/>\nfunction hardvseasy(oselo) {<br \/>\n   if (oselo.value == 'easy' && document.URL.toLowerCase().indexOf('debug=y') == -1) {<br \/>\n     if (document.URL.indexOf('?') == -1) {<br \/>\n       location.href=document.URL.split('#')[0] + '?debug=y';<br \/>\n     } else {<br \/>\n       location.href=document.URL.split('#')[0] + '&debug=y';<br \/>\n     }<br \/>\n   } else if (oselo.value == 'hard' && document.URL.toLowerCase().indexOf('debug=') != -1) {<br \/>\n     if (document.URL.indexOf('?') == -1) {<br \/>\n       location.href=document.URL.split('#')[0].replace(\/debug\/g, 'gubed');<br \/>\n     } else {<br \/>\n       location.href=document.URL.split('#')[0].replace(\/debug\/g, 'gubed');<br \/>\n     }<br \/>\n   }<br \/>\n}<br \/>\n<\/code><\/p>\n<p> &#8230; in <a target=_blank href='https:\/\/www.rjmprogramming.com.au\/PHP\/Geographicals\/diff.php?one=https:\/\/www.rjmprogramming.com.au\/PHP\/DecodingScrambledWords\/decodewords.php-GETME'>the changed<\/a> <a target=_blank href='https:\/\/www.rjmprogramming.com.au\/PHP\/DecodingScrambledWords\/decodewords.php-GETME'>decodewords.php<\/a> <a target=_blank href='https:\/\/www.rjmprogramming.com.au\/PHP\/DecodingScrambledWords\/decodewords.php'>web application<\/a>.<\/p>\n<p><!--p>You can also see this play out at WordPress 4.1.1's <a target=_blank  href='\/\/www.rjmprogramming.com.au\/ITblog\/new-php\/javascript-decoding-scrambled-words-game--difficulty-tutorial\/'>PHP\/Javascript Decoding Scrambled Words Game Difficulty Tutorial<\/a>.<\/p-->\n<hr>\n<p id='php\/jdswgt'>Previous relevant <a target=_blank title='PHP\/Javascript Decoding Scrambled Words Game Tutorial' href='\/\/www.rjmprogramming.com.au\/ITblog\/php\/javascript-decoding-scrambled-words-game-tutorial\/'>PHP\/Javascript Decoding Scrambled Words Game Tutorial<\/a> is shown below.<\/p>\n<div style=\"width: 230px\" class=\"wp-caption alignnone\"><a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/PHP\/DecodingScrambledWords\/\"><img decoding=\"async\" style=\"float:left;border: 15px solid pink;\" alt=\"PHP Decoding Scrambled Words Game Tutorial\" src=\"http:\/\/www.rjmprogramming.com.au\/PHP\/DecodingScrambledWords\/DecodingScrambledWords.jpg\" title=\"PHP\/Javascript Decoding Scrambled Words Game Tutorial\"  \/><\/a><p class=\"wp-caption-text\">PHP\/Javascript Decoding Scrambled Words Game Tutorial<\/p><\/div>\n<p>Do you like word games?  Today&#8217;s game takes four randomly generated words, encodes them, and asks you to decode them &#8230; the words have 4 to 9 characters in them &#8230; mind you, out of them, you&#8217;d <a target=_blank title='Thanks to Google Translate' href='http:\/\/www.translate.google.com'>have<\/a> \u5947\u602a\u7684\u5b57\u7b26 or \u5909\u306a\u6587\u5b57 or \u0432\u0435\u0441\u0435\u043b\u044b\u0435 \u043f\u0435\u0440\u0441\u043e\u043d\u0430\u0436\u0438 or \uc774\uc0c1\ud55c \ubb38\uc790 or \u0645\u0636\u062d\u06a9\u06c1 \u062e\u06cc\u0632 \u062d\u0631\u0648\u0641 or \u5947\u602a\u7684\u5b57\u7b26 or \u0905\u091c\u0940\u092c \u0905\u0915\u094d\u0937\u0930 or \u10e1\u10d0\u10e1\u10d0\u10ea\u10d8\u10da\u10dd \u10d2\u10db\u10d8\u10e0\u10d4\u10d1\u10d8 or \u178f\u17bd\u17a2\u1780\u17d2\u179f\u179a\u178a\u17c2\u179b\u1782\u17bd\u179a\u17b1\u17d2\u1799\u17a2\u179f\u17cb\u179f\u17c6\u178e\u17be\u1785 or \u0bb5\u0bc7\u0b9f\u0bbf\u0b95\u0bcd\u0b95\u0bc8 \u0b8e\u0bb4\u0bc1\u0ba4\u0bcd\u0ba4\u0bc1\u0b95\u0bcd\u0b95\u0bb3\u0bcd or \u0e15\u0e31\u0e27\u0e15\u0e25\u0e01 or \u0627\u0644\u0623\u062d\u0631\u0641 \u0645\u0636\u062d\u0643 or \u05de\u05d0\u05b8\u05d3\u05e0\u05e2 \u05d0\u05d5\u05ea\u05d9\u05d5\u05ea or \u0ab0\u0aae\u0ac2\u0a9c\u0ac0 \u0a85\u0a95\u0acd\u0ab7\u0ab0\u0acb or \u03b1\u03c3\u03c4\u03b5\u03af\u03bf\u03c5\u03c2 \u03c7\u03b1\u03c1\u03b1\u03ba\u03c4\u03ae\u03c1\u03b5\u03c2 or \u0ca4\u0cae\u0cbe\u0cb7\u0cc6\u0caf \u0caa\u0cbe\u0ca4\u0ccd\u0cb0\u0c97\u0cb3\u0cc1 or \u09ae\u099c\u09be\u09b0 \u0985\u0995\u09cd\u09b7\u09b0 or \u0ea5\u0eb1\u0e81\u0eaa\u0eb0\u0e99\u0eb0 funny or \u0432\u044f\u0441\u0451\u043b\u044b\u044f \u043f\u0435\u0440\u0441\u0430\u043d\u0430\u0436\u044b or \u0c39\u0c3e\u0c38\u0c4d\u0c2f \u0c05\u0c15\u0c4d\u0c37\u0c30\u0c3e\u0c32\u0c41  &#8230; we&#8217;re going to call the game <i>&#8220;Decoding Scrambled Words&#8221;<\/i> &#8230; and you score a point for each unscrambled set of words.  It uses English words, based on the dictionary arrangements at its (web) server.   Maybe it would be a good game to learn English vocabulary.<\/p>\n<p>Programmers often use <a target_blank title='Words (unix) information from Wikipedia' href='http:\/\/en.wikipedia.org\/wiki\/Words_%28Unix%29'>Linux dictionary files<\/a> as a means to get a word list, and that list could be in any language, and for ours it is English, so to make it for another language, change the code inside the four file_get_contents() calls in <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/PHP\/DecodingScrambledWords\/decodewords.php_GETME\" title=\"decodewords.php\">decodewords.php<\/a><\/p>\n<p>This <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/PHP\/DecodingScrambledWords\/\" title=\"Decoding Scrambled Words\">game<\/a> has two parts to it for PHP and Javascript to respectively get a word to use and arrange the user interaction.<\/p>\n<p>Hopefully you can figure the rules when you click the picture above for a <a target=_blank title=\"live run\" href=\"http:\/\/www.rjmprogramming.com.au\/PHP\/DecodingScrambledWords\/\">live run<\/a>.<\/p>\n<p>Thank you to <a target=_blank title='The Free Dictionary' href='http:\/\/thefreedictionary.com'>The Free Dictionary<\/a> for its great online presence as a dictionary resource, for the functionality to optionally explain a word&#8217;s dictionary meaning.  The image map &#8220;click parts of the picture&#8221; <a target=_blank title='Pointed at vocabulary tutorials' href='http:\/\/www.rjmprogramming.com.au\/wordpress\/?tag=vocabulary'>vocabulary ESL tutorials<\/a> at this blog use the same resource to explain dictionary information about clicked on &#8220;things&#8221;.<\/p>\n<p>Anyway, see how you go with this game of interest and history!<\/p>\n<p>Anyway, see how you go with this game of logic and tactics!<\/p>\n<p>Maybe a view of <a target=_blank title='Enigma' href='http:\/\/www.youtube.com\/watch?v=pQ1TZLmBm7M'>this<\/a> could inspire you?!<\/p>\n<p>Here is a link to some downloadable PHP (with Javascript) programming code you could rename to <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/PHP\/DecodingScrambledWords\/decodewords.php_GETME\" title=\"decodewords.php\">decodewords.php<\/a><\/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='#d6515' onclick='var dv=document.getElementById(\"d6515\"); dv.innerHTML = \"&lt;iframe width=670 height=600 src=\" + \"http:\/\/www.rjmprogramming.com.au\/wordpress\/?cat=44\" + \"&gt;&lt;\/iframe&gt;\"; dv.style.display = \"block\";'>this<\/a> too.<\/p>\n<div id='d6515' 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='#d62082' onclick='var dv=document.getElementById(\"d62082\"); dv.innerHTML = \"&lt;iframe width=670 height=600 src=\" + \"https:\/\/www.rjmprogramming.com.au\/ITblog\/tag\/difficulty\" + \"&gt;&lt;\/iframe&gt;\"; dv.style.display = \"block\";'>this<\/a> too.<\/p>\n<div id='d62082' 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='#d62094' onclick='var dv=document.getElementById(\"d62094\"); dv.innerHTML = \"&lt;iframe width=670 height=600 src=\" + \"https:\/\/www.rjmprogramming.com.au\/ITblog\/tag\/selector\" + \"&gt;&lt;\/iframe&gt;\"; dv.style.display = \"block\";'>this<\/a> too.<\/p>\n<div id='d62094' style='display: none; border-left: 2px solid green; border-top: 2px solid green;'><\/div>\n","protected":false},"excerpt":{"rendered":"<p>It can be hard for a Javascript DOM aficionado to be restricted to &#8220;just CSS styling&#8221; means by which to give a web application &#8220;a bit of a&#8221; makeover. Yes, &#8220;a bit of a&#8221; is apt. We&#8217;re not going overboard, &hellip; <a href=\"https:\/\/www.rjmprogramming.com.au\/ITblog\/phpjavascript-decoding-scrambled-words-game-css-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":[281,3024,367,3981,2728,652,932,997,1953,4625,1209,1212,1319,1452,1453],"class_list":["post-62094","post","type-post","status-publish","format-standard","hentry","category-elearning","category-event-driven-programming","category-tutorials","tag-css","tag-difficulty","tag-dropdown","tag-global-data-attribute","tag-hint","tag-javascript","tag-php","tag-programming","tag-selector","tag-starts-with","tag-style","tag-styling","tag-tutorial","tag-word","tag-word-game"],"_links":{"self":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts\/62094"}],"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=62094"}],"version-history":[{"count":8,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts\/62094\/revisions"}],"predecessor-version":[{"id":62118,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts\/62094\/revisions\/62118"}],"wp:attachment":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/media?parent=62094"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/categories?post=62094"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/tags?post=62094"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}