Respiratory System Quiz Game Primer Tutorial
โœ‚๐Ÿƒ๐Ÿพโ€โ™€๏ธ๐Ÿƒ๐Ÿผโ€โ™‚๏ธ
๐Ÿ“–

Respiratory System Quiz Game Primer Tutorial

Respiratory System Quiz Game Primer Tutorial

The previous Body Systems Quiz Game Primer Tutorial shares many commonalities with todayโ€™s Respiratory System quiz, two major commonalities being โ€ฆ

  • the source for the quiz knowledge โ€ฆ thanks to HLTAAP001 Recognise healthy body systems TAFE NSW
  • both quizzes have a single image as a reference point but neither use (or need) HTML map nor canvas elements

โ€ฆ and today, for the first time that we can remember we set our image as the background image to an HTML โ€ฆ

  • form element โ€ฆ
  • action=[hereโ€™sLookingAtYouKid]
  • method=GET
  • style=โ€™width:640px;height:480px;background: URL(respiratory_system.jpg) no-repeat;โ€˜
  • comprised of input type=text textboxes and one type=submit button overlayed into specific positions masking the image at points where that image would have given the answer away, as per โ€ฆ


    <input placeholder='What is this?' type=text style='position:absolute;left:108px;top:142px;' name=fld1 id=fld1 value=''></input>

    <input placeholder='What is this?' type=text style='position:absolute;left:458px;top:108px;' name=fld2 id=fld2 value=''></input>

    <input placeholder='What is this?' type=text style='position:absolute;left:458px;top:158px;' name=fld3 id=fld3 value=''></input>

    <input placeholder='What is this?' type=text style='position:absolute;left:458px;top:223px;' name=fld4 id=fld4 value=''></input>

    <input placeholder='What is this?' type=text style='position:absolute;left:458px;top:312px;' name=fld5 id=fld5 value=''></input>

    <input placeholder='What is this?' type=text style='position:absolute;left:458px;top:410px;' name=fld6 id=fld6 value=''></input>

    <input id='sb' type=submit style='background-color:yellow;position:absolute;left:458px;top:460px;' value='Check Answers'></input>

โ€ฆ and this is where you may have cried out โ€œHow did you get good values for top and left positions, given you are not using an HTML map element?โ€. Well, we temporarily put the flowchartโšชbits you can further read about at Flowchart Colours Tutorial (and our own bits, temporarily) โ€ฆ



function recxy(event) {

var isok=true;

//if (document.getElementById('dpf')) {

// if (('' + document.getElementById('dpf').style.display).toLowerCase().indexOf('block') != -1) { alert('cliCk ' + wording + ' ' + bodyclick); }

//}

if (event.touches) { // thanks to https://stackoverflow.com/questions/24567441/how-do-i-detect-two-fingers-at-touchstart-in-javascript

if (event.touches.length > 1) { isok=false; }

}

if (isok) {

if (x == 0 && y == 0 && lastx == 0 && lasty == 0) {



if (event.clientX || event.clientY) {

x = event.clientX; // - elemLeft;

y = event.clientY; // - elemTop;

} else {

x = event.pageX; // - elemLeft;

y = event.pageY; // - elemTop;

}

lastx=x;

lasty=y;

//if (document.getElementById('dpf')) {

// if (('' + document.getElementById('dpf').style.display).toLowerCase().indexOf('block') != -1) { alert('Click ' + wording + ' ' + bodyclick); }

//}

setTimeout(xthen, 2000);

setTimeout(andthen, 1000);

} else {




if (event.clientX || event.clientY) {

if (x != event.clientX || y != event.clientY) {

lastx=x;

lasty=y;

//if (document.getElementById('dpf')) {

// if (('' + document.getElementById('dpf').style.display).toLowerCase().indexOf('block') != -1) { alert('ClIck ' + wording + ' ' + bodyclick); }

//}

setTimeout(xthen, 2000);

setTimeout(andthen, 1000);

//} else {

//document.title+=' ! ';

}

} else {

if (x != event.pageX || y != event.pageY) {

lastx=x;

lasty=y;

//if (document.getElementById('dpf')) {

// if (('' + document.getElementById('dpf').style.display).toLowerCase().indexOf('block') != -1) { alert('clicK ' + wording + ' ' + bodyclick); }

//}

setTimeout(xthen, 2000);

setTimeout(andthen, 1000);

//} else {

//document.title+=' ? ';

}

}



if (event.clientX || event.clientY) {

x = event.clientX; // - elemLeft;

y = event.clientY; // - elemTop;

} else {

x = event.pageX; // - elemLeft;

y = event.pageY; // - elemTop;

}

}

//alert('x=' + x + ' and y=' + y);

}


alert('x=' + x + ' and y=' + y);

}

</script>

</head>

<body onclick='recxy(event);' onload='checkanswers();' style='background-color:yellow;'>

โ€ฆ just for the period writing the web application, and then we ended up with this very pared back respiratory_systemโšซhtml with its associated liveโœ‚run link for you to test out your Respiratory System knowledge.



Previous relevant Body Systems Quiz Game Primer Tutorial is shown below.

Body Systems Quiz Game Primer Tutorial

Body Systems Quiz Game Primer Tutorial

โ€œRegionalโ€ click (or touch) web application functionality doesnโ€™t have to be always done via an HTML map element thangthing. Today, as an alternative methodology, we โ€ฆ

  • start with a useful โ€œBody Systemsโ€ image โ€ฆ thanks to HLTAAP001 Recognise healthy body systems TAFE NSW
  • set it up as the document.body background: url(โ€˜body_systems.jpgโ€™) no-repeat; background image
  • โ€œoverlayโ€ a โ€ฆ
    1. position:absolute property
    2. z-index
    3. background-color:transparent

    โ€ฆ HTML table element โ€œgridโ€ on top

  • add HTML table elementโ€™s cellsโ€™ onclick event logics that work on the scoring for the โ€œBody Systems Quizโ€ game we have for you today
  • an HTML select โ€œdropdownโ€ element gets randomly selected with a โ€œBody Partโ€ for which the user then (and features the use of data attributes to store associated data items) โ€ฆ
  • clicks (or touches) (a โ€œBody Systemโ€ arrowhead representing) one of the HTML table elementโ€™s cells (but looks to the user as the original background image showing โ€œBody Systemsโ€), triggering the scoring analysis logic for todayโ€™s โ€œBodyโœ‚Systems (of Body Parts) Gameโ€ whose HTML and Javascript and bit of CSS source code body_systemsโšซhtml is there for your perusal

You may wonder, from this, whereโ€™s the relationship among โ€ฆ

  • Body System
  • Body Part
  • Grid Reference (ie. HTML table elementโ€™s cellsโ€™ IDs)

โ€ฆ established? Again, as you may be really sick of by now with us, nothing more complicated data structure wise, than a โ€œBody System:Body Parts List (comma separated):Grid Reference List (comma separated)โ€ array, as exemplified by the snippet โ€ฆ



var b_s=["Cardiovascular:heart,blood,vessels:3_2,3_3,5_2",

...

];

When taking a look at todayโ€™s HTML and Javascript and bit of CSS source code body_systemsโšซhtml you may notice โ€œthe bit of CSSโ€, literally โ€ฆ



<style>

td { width: 10%; height: 10%; border: 0px inset red; }

</style>

โ€ฆ and wonder, whatโ€™s the go with the 0px bit of โ€œborder: 0px inset red;โ€? Well, itโ€™s a reminder back to how we โ€œdebuggedโ€ the โ€œGrid Referenceโ€ array data we collected. When developing this web application, we had, for debugging purposes, this CSS as โ€ฆ



<style>

td { width: 10%; height: 10%; border: 1px inset red; }

</style>

โ€ฆ and just during that period we had a way to tell in which HTML table elementโ€™s cell a โ€œBody Systemโ€ arrowhead would fall. It may not be to your liking to leave such โ€œkludgesโ€ in live code, and often weโ€™d agree, but if something is such an obvious code โ€œattention seekerโ€, we actually find leaving such โ€œpeccadillosโ€ in instructive into future revisits of such code.

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, Games, Tutorials and tagged , , , , , , , , , . Bookmark the permalink.

Leave a Reply

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