Numbers Guessing Game Dragover Tutorial
โœ‚๐Ÿƒ๐Ÿพโ€โ™€๏ธ๐Ÿƒ๐Ÿผโ€โ™‚๏ธ
๐Ÿ“–

Numbers Guessing Game Dragover Tutorial

Numbers Guessing Game Dragover Tutorial

Today weโ€™re honing in on โ€ฆ

  • drag and drop methodology โ€ฆ
  • dragover event โ€ฆ value adding where โ€ฆ
  • drop element(s) are cells of an HTML table element (also a drop element)

โ€ฆ as our interest. We scouted around for the best โ€œdesign matchโ€ and came up with the arrangements existing when we presented Numbers Guessing Game Tutorial some time ago now.

And if we succeed with some form of value adding here, we have another idea for the ideas weโ€™re presenting today. Spoiler alert! Yes, it can be made to be useful.

As such weโ€™ve โ€ฆ

Added toggleable โ€œshow where contemplatedโ€ value added border where dragover logic
<?php


$templategame=file_get_contents('./experimental_drag_and_drop.htm');

if (isset($_GET['notice'])) {

$templategame=str_replace('>-</span>', '><a style="text-decoration:none;cursor:pointer;" title="Stop showing where contemplated as well." onclick="location.href=' . "'#no_tice=y'" . ';">-</a><a style="text-decoration:none;cursor:pointer;" title="Show where contemplated as well." onclick="location.href=' . "'#notice=y'" . ';">+</a></span>', $templategame);

} else {

$templategame=str_replace('>-</span>', '><a style="text-decoration:none;cursor:pointer;" title="Show where contemplated as well." onclick="location.href=' . "'#notice=y'" . ';">+</a><a style="text-decoration:none;cursor:pointer;" title="Stop showing where contemplated as well." onclick="location.href=' . "'#no_tice=y'" . ';">-</a></span>', $templategame);

}



?>
Tweaked dragover logic


target.addEventListener("dragover", (ev) => {

if (lastbco) { lastbco.style.backgroundColor='white'; lastbco=null; }

if (ev.target.outerHTML.indexOf('<table') != 0 && ev.target.outerHTML.indexOf(' data-piece="') != -1) {

if (ev.target.outerHTML.split(' data-piece="')[1].substring(0,1) == (itisthiscmove + ev.target.outerHTML.split(' data-piece="')[1].substring(0,1)).substring(0,1)) {

lohfulloh=ev.target.outerHTML;

console.log("LOHfulloh=" + lohfulloh);

}

}

//console.log("dragOver " + ev.target.id + ' ' + ('' + ev.target.style.backgroundColor).replace('white','') + ' ' + document.body.innerHTML.indexOf('tab' + 'lece' + 'llb' + 'c'));

//if (navigator.userAgent.match(/Android|BlackBerry|iPhone|iPad|iPod|Opera Mini|IEMobile/i)) {

// document.title='ev.preventDefault(); //4';

//}

ev.preventDefault();

if (('' + ev.target.id).indexOf('td') == 0 && ('' + ev.target.style.backgroundColor).trim().replace('white','') == '' && document.body.innerHTML.indexOf('Numbe' + 'rs Guessi' + 'ng Ga' + 'me') != -1) {

//document.getElementById(sourceid).style.opacity='0.6';

lastbco=ev.target;

ev.target.style.backgroundColor='pink';

if (document.getElementById('mybut')) {

if (document.getElementById('mybut').innerHTML.indexOf(' .. ') == -1) {

document.getElementById('mybut').innerHTML=document.getElementById('mybut').innerHTML.replace(' Game Game', ' Game');

document.getElementById('mybut').innerHTML+=' .. current guess is ' + ev.target.innerHTML;

} else {

document.getElementById('mybut').innerHTML=document.getElementById('mybut').innerHTML.split(' .. ')[0] + ' .. current guess is ' + ev.target.innerHTML;

}

}

if (document.getElementById('sdropz')) {

if (document.getElementById('sdropz').innerHTML.indexOf(' .. ') == -1) {

document.getElementById('sdropz').innerHTML+=' .. current guess is ' + ev.target.innerHTML;

} else {

document.getElementById('sdropz').innerHTML=document.getElementById('sdropz').innerHTML.split(' .. ')[0] + ' .. current guess is ' + ev.target.innerHTML;

}

}

if (('' + document.URL + decodeURIComponent('' + location.hash)).indexOf('notice=') != -1 && ('' + decodeURIComponent('' + location.hash)).indexOf('no_tice=') == -1) { ev.target.style.border='2px dashed yellow'; }

}

//document.getElementById(sourceid).style.cursor='progress';

//ev.target.style.cursor='progress';

//ev.target.dataTransfer.dropEffect = 'progress';.id)

});

Flag any continued โ€œshow where contemplatedโ€ interest


var secsmore='';

if (('' + document.URL + decodeURIComponent('' + location.hash)).indexOf('notice=') != -1 && ('' + decodeURIComponent('' + location.hash)).indexOf('no_tice=') == -1) { secsmore='ยฌice=y'; }


if (document.URL.indexOf('rjmprogramming-com-au.translate.goog') != -1) {

location.href=document.URL.split('&score=')[0] + '&score=' + score + '&secs=' + secs + secsmore;

} else {

location.href=document.getElementById('callback').value + '?score=' + score + '&secs=' + secs + secsmore;

}

โ€ฆ to, as the user requests, add some table cell border enhancements (as our โ€œvalue addingโ€œ) to ourtweaked thirdโšชdraft PHP game (helped out by thechanged experimental_drag_and_dropโšซhtm Experimental Drag and Drop clientside HTML and Javascript basis), as the user drags the draggable element over the table droppable element and its cohort table cell elements.



Previous relevant Numbers Guessing Game Tutorial is shown below.

Numbers Guessing Game Tutorial

Numbers Guessing Game Tutorial

Weโ€™ve been working on aspects to the genericity of the table that is โ€ฆ

The Drop Zone

โ€ฆ do do โ€ฆ do do โ€ฆ do do โ€ฆ do do โ€ฆ do do do do do do do do do do do do โ€ฆ yesterdayโ€™s threat โ€œnow so yesterdayโ€ being โ€ฆ

  • allow for the number of table cells to be other than 9 (with Animal Mineral Vegetable Game Tutorial where it is 3 in total) โ€ฆ and today โ€ฆ
  • allow the number of cells across in a column not be 3

โ€ฆ in a (very difficult) Numbers Guessing game for numbers from 1 to 99 that regular readers may be familiar with as the (same content (and mentioned at this link โ€ฆ thanks โ€ฆ) as the) Numbers Guessing game at this blog, but presented using a Drag and Drop modus operandi.

Feel free to try our firstโšชdraft PHP game, which leans on achanged experimental_drag_and_dropโšซhtm HTML and Javascript and CSS gameโœ‚web application basis, is also playable below โ€ฆ

Stop Press

On your smaller devices we found the Numbers Guessing Game a bit hard to use. As such, we researched and played around with โ€œdrag and dropโ€ cursor ideas unsuccessfully to end up, instead, not thinking about the cursor (albeit, we find that idea cuter) but rather styling the target table cellโ€™s background colour and informing the user of that up at the top button wording in ourchanged secondโšชdraft PHP game, which leans on ourchanged experimental_drag_and_dropโšซhtm HTML and Javascript and CSS helperโ€ฆ



var lastbco=null;



const target = document.querySelector("#target");

target.addEventListener("dragover", (ev) => {

if (lastbco) { lastbco.style.backgroundColor='white'; lastbco=null; }

console.log("dragOver " + ev.target.id + ' ' + ('' + ev.target.style.backgroundColor).replace('white','') + ' ' + document.body.innerHTML.indexOf('tab' + 'lece' + 'llb' + 'c'));

ev.preventDefault();

if (('' + ev.target.id).indexOf('td') == 0 && ('' + ev.target.style.backgroundColor).trim().replace('white','') == '' && document.body.innerHTML.indexOf('Numbe' + 'rs Guessi' + 'ng Ga' + 'me') != -1) {

//document.getElementById(sourceid).style.opacity='0.6';

lastbco=ev.target;

ev.target.style.backgroundColor='pink';

if (document.getElementById('mybut')) {

if (document.getElementById('mybut').innerHTML.indexOf(' .. ') == -1) {

document.getElementById('mybut').innerHTML=document.getElementById('mybut').innerHTML.replace(' Game Game', ' Game');

document.getElementById('mybut').innerHTML+=' .. current guess is ' + ev.target.innerHTML;

} else {

document.getElementById('mybut').innerHTML=document.getElementById('mybut').innerHTML.split(' .. ')[0] + ' .. current guess is ' + ev.target.innerHTML;

}

}

}


//document.getElementById(sourceid).style.cursor='progress';

//ev.target.style.cursor='progress';

//ev.target.dataTransfer.dropEffect = 'progress';


});


Previous relevant Planet Moon Game Tutorial is shown below.

Planet Moon Game Tutorial

Planet Moon Game Tutorial

Another thing that there is nine of (as contentious as it is regarding Pluto) is Planets in the Solar System, revolving around the Sun. And so, in keeping with a lot of the same design as yesterdayโ€™s Enneagram Type Game Tutorial we have a Planet Moon Game to present for you to play around with today.

Again, PHP uses a framework of Experimental Drag and Drop HTML and Javascript and CSS, mainly via one PHP codeline โ€ฆ

<?php


$templategame=file_get_contents('./experimental_drag_and_drop.htm');


?>

โ€ฆ and, perhaps, your curiosity that we have not โ€œpassedโ€ data via $_GET[] or $_POST[] arguments, but rather just the simple act of โ€ฆ

  • moulding and manipulating (eg. arranging โ€œcallbackโ€ logic means, as used below) that $templategame โ€œtemplateโ€ for our purposes โ€ฆ nga ha ha ha ha ha ha ha ha โ€ฆ but we digress โ€ฆ
  • simply โ€ฆ
    <?php


    echo $templategame;


    ?>
    โ€ฆ outputs a webpage โ€ฆ
  • and on the way back to play again, we use $_GET[โ€˜scoreโ€™] and $_GET[โ€˜secsโ€™] (in experimental_drag_and_dropโšซhtml HTML and Javascript and CSS gameโœ‚web application) to keep the ball rolling back to the game specific PHP we use โ€ฆ


    location.href=document.getElementById('callback').value + '?score=' + score + '&secs=' + secs;

โ€ฆ in our firstโšชdraft PHP game, which leans on achanged experimental_drag_and_dropโšซhtml HTML and Javascript and CSS gameโœ‚web application basis, is also playable below โ€ฆ

Stop Press

We fully concur with any adage that goes โ€ฆ

You learn most from your mistakes

โ€ฆ just as weโ€™re curious about โ€œthe things that go wrongโ€, and not having them repeat! Same with pooches!

Take our firstto secondโšชdraft PHP game (to the opera, would be preferable). We wondered why, occasionally, with the โ€œfirst draftโ€ it would hang. It took us a half day to realize, as you could yourself have tweaked to a lot quicker if you had followed the adage โ€ฆ



Hanging issues mostly team up with code within a loop

The situation, weโ€™ve reasoned, is that we had that PHP $badlist variable store a comma separated list of planets with either zero moons or more than one moon randomly selected representing it. Weโ€™d assumed, yesterday, not that weโ€™d put it in words, but in logic, that this list would not (have the same length or) be the same as a (new $goodlist variable) list of planets with either zero moons or selected while collecting the random list of Moon/Planet combinations โ€ฆ ie. we assumed in the list would be a Planet with only one of its Moons randomly selected โ€ฆ mistake!!! Better is โ€ฆ

<?php


$goodlist=',Mercury,Venus,';

$badlist=',Mercury,Venus,';




while (strlen($goodlist) == strlen($badlist)) {

$goodlist=',Mercury,Venus,';


$badlist=',Mercury,Venus,';



$correctans=rand(0,8);

$sofar=';';

for ($i=0; $i<9; $i++) {

$j=rand(0, (-1 + sizeof($wikidesignations)));

if ($crandlist == '') {

$crandlist='' . $j;

$sofar.=$wikidescriptions[$j] . ';';

if (strpos($goodlist, $wikidescriptions[$j]) === false) { $goodlist.=$wikidescriptions[$j] . ','; }

} else if (strpos((',' . $crandlist . ','), (',' . $j . ',')) !== false) { // || strpos($sofar, ';' . $wikidescriptions[$j] . ';') !== false) {

while (strpos((',' . $crandlist . ','), (',' . $j . ',')) !== false) { // || strpos($sofar, ';' . $wikidescriptions[$j] . ';') !== false) {

$j=rand(0, (-1 + sizeof($wikidesignations)));

}

$crandlist.=',' . $j;

$sofar.=$wikidescriptions[$j] . ';';

if (strpos($goodlist, $wikidescriptions[$j]) === false) { $goodlist.=$wikidescriptions[$j] . ','; }

} else {

if (strpos($sofar, ';' . $wikidescriptions[$j] . ';') !== false) { $badlist.=$wikidescriptions[$j] . ','; }

$crandlist.=',' . $j;

$sofar.=$wikidescriptions[$j] . ';';

if (strpos($goodlist, $wikidescriptions[$j]) === false) { $goodlist.=$wikidescriptions[$j] . ','; }

}

}

}


?>


Previous relevant Enneagram Type Game Tutorial is shown below.

Australian Street Type Game Tutorial

Enneagram Type Game Tutorial

A lot of us wonder what goes towards making up our personalities. We remember doing a Myers-Briggs test for some job as part of the vetting process. We thought weโ€™d write another experimental drag and drop game, like yesterdayโ€™s Australian Street Type Game Tutorial, regarding โ€ฆ

Enneagram Types

โ€ฆ of human personalities, and we found a webpage linking these categorizations to Hollywood Movie Stars for you to get the gist of the ideas. We also thank Wikipedia as our source for Movie Star images.

It being a topic โ€ฆ

  1. beyond our ken
  2. outside our usual subject matter

โ€ฆ you may be wondering how we stumbled upon the idea? We let Google autocomplete our โ€ฆ



nine types of

โ€ฆ search textbox typing, fully expecting โ€œCarolโ€? to be at the top of the list when we saw โ€ฆ



nine types of enneagram

โ€ฆ to flesh out a family of โ€œgame interestโ€, we hope?!

Our firstโšชdraft PHP game is also playable below โ€ฆ


Previous relevant Australian Street Type Game Tutorial is shown below.

Australian Street Type Game Tutorial

Australian Street Type Game Tutorial

The experimental drag and drop theme continues on today, after Experimental Drag and Drop Game Tutorialโ€˜s debut game application, with a Wikipedia inspired โ€œAustralian Street Typeโ€ game today.

Huh?! Well, you know those street names that baffle? Or are we easily baffleable?! Anyway, you had to be there. And if you ever feel youโ€™re alone with an interest, just look it up in Wikipedia or Google and youโ€™re almost sure to find out โ€ฆ

you are not alone

Yes, our Wikipedia page mentioned Australian Street Type Designations with their lawyerly Australian Street Type Descriptions. Who could ask for more? Well?!

To make this happen we wrote some PHP, which leans on achanged experimental_drag_and_dropโšซhtml HTML and Javascript and CSS gameโœ‚web application basis, or template, to mould and bend towards our purpose โ€ฆ nga ha ha!

Our firstโšชdraft PHP game is also playable below โ€ฆ


Previous relevant Experimental Drag and Drop Game Tutorial is shown below.

Experimental Drag and Drop Game Tutorial

Experimental Drag and Drop Game Tutorial

It can be interesting turning a โ€œconceptโ€ (or even a โ€œproof of conceptโ€ web application) into an, on the side, โ€œgameโ€ web application, and that way, learn whatโ€™s possible via user action. This is how we felt about yesterdayโ€™s Experimental Drag and Drop Primer Tutorial and that teamed with the wonder about how we could add some useful complexity to our โ€œExperimental Drag and Dropโ€ web applicationโ€™s โ€ฆ

Drop Zone

Can โ€œinheritanceโ€ be harnessed to make it work for some complexity of nested HTML elements inside that โ€œDrop Zoneโ€ element when the document.bodyโ€™s onload event happens? We wondered whether a Brady Bunch style 3ร—3 table could be the go? And whether the nine cells could have a โ€œscoreโ€ associated with them, and that set of scores be changing over time to make the game more challenging and interesting? Well โ€ฆ

Yes

โ€ฆ is the answer regardingmaking a game out of a proof of concept with our experimental_drag_and_dropโšซhtml HTML and Javascript and CSS gameโœ‚web application (also shown below) using these techniques, about which we think some of you readers will be interested?!


Previous relevant Experimental Drag and Drop Primer Tutorial is shown below.

Experimental Drag and Drop Primer Tutorial

Experimental Drag and Drop Primer Tutorial

Weโ€™ve added the word experimental into todayโ€™s blog posting title, mainly because our first of two inspirational webpage sources (last modified on 23/02/2023) regarding somewhat alternative โ€œDrag and Dropโ€ functionalities told us, regarding the DataTransfer object informational โ€œDataTransferโ€ webpage โ€ฆ

Experimental: This is an experimental technology
Check the Browser compatibility table carefully before using this in production.

โ€ฆ but our testing of the methodologies on various platforms hasnโ€™t totally failed yet on any of the several desktop and mobile platform scenarios weโ€™ve tried. On mobile, we just held on for a sustained touch (down) to make it possible. So maybe the industry has caught up with the ideas? Weโ€™re hoping so, because โ€œdrag and dropโ€ is a kind of natural thing online users think of to do, and people associate it with โ€œgetting things doneโ€ we reckon.

Anyway, we relied on the great source code of the second of two inspirational webpages DataTransfer: setData() method, thanks โ€ฆ

The DataTransfer.setData() method sets the drag operationโ€™s drag data to the specified data and type. If data for the given type does not exist, it is added at the end of the drag data store, such that the last item in the types list will be the new type. If data for the given type already exists, the existing data is replaced in the same position. That is, the order of the types list is not changed when replacing data of the same type.

โ€ฆ to getus going with our โ€œproofโšชof conceptโ€ webโœ‚application (also shown below) using these techniques, about which we think some of you readers will be interested?!

If this was interesting you may be interested in this too.


If this was interesting you may be interested in this too.


If this was interesting you may be interested in this too.


If this was interesting you may be interested in this too.


If this was interesting you may be interested in this too.


If this was interesting you may be interested in this too.


If this was interesting you may be interested in this too.

This entry was posted in eLearning, Event-Driven Programming, Tutorials and tagged , , , , , , , , , , , , , , , , , , , , , , , , , . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *