HTML Square Horizontal Rule Tracing Propogation Tutorial

HTML Square Horizontal Rule Tracing Propogation Tutorial

HTML Square Horizontal Rule Tracing Propogation Tutorial

Yesterday’s HTML Square Horizontal Rule Tracing Game Tutorial continued on with the …

  • HTML hr and div elements made up to be …
    1. lines
    2. vertices

    … only needing the underlying …

  • table cell elements as graphical position markers only (made to have intelligence derived via use of Javascript getBoundingClientRect()), but pretty “dumb” markers at that

… but HTML and Javascript are capable of very sophisticated event propogation, and there is no reason you have to have those underlying table cell elements remaining “dumb” that way. You can, amongst many things, in Javascript, dynamically add …

  • ID on the fly

    var tds=document.getElementsByTagName('td');
    for (var itds=0; itds<tds.length; itds++) {
    tds[itds].id='td' + eval(1 + itds);
    }
  • onclick event logic on the fly

    var lastsquare=-1;
    var tds=document.getElementsByTagName('td');
    for (var itds=0; itds<tds.length; itds++) {
    tds[itds].id='td' + eval(1 + itds);
    tds[itds].onclick=function(event) { lastsquare=eval(('' + this.id).replace('td','')); goes++; if (lastsquare == sqchoice) { score++; } if (('' + location.hash).indexOf('square') != -1) { picksq(); } else if (('' + location.hash).indexOf('grid') != -1) { gridinfo(' in square number ' + lastsquare); } };
    }

We’ve started with some other game ideas using event propogation, with the last one, in today’s changed square_hr_tracing.htm‘s live run game, that now has game options …

  • Chinese Brain Twisters
  • Vertex Pointing Game … just shows vertices and on a set of 4 clicks or touches, will plot a Bezier Curve (thanks to this useful link, thanks)
  • Square Pointing Game … just shows the table and its numbered cells … with a number quiz
  • Grid Pointing Game … shows border lines, and vertices and table cells with their thinner borders … where information is presented, relying on event propogation orders to show information from two hierarchies of event propogation

To differentiate between these forms of game (selected via a new HTML select (dropdown) element) we did not choose to use our usual address bar URL argument (via ? and &) navigation method, but rather use hashtag (via #) address bar URL methods, and in the Javascript (DOM) examine location.hash to know which “game” is applicable to a web application session.

Food for thought, we hope!


Previous relevant HTML Square Horizontal Rule Tracing Game Tutorial is shown below.

HTML Square Horizontal Rule Tracing Game Tutorial

HTML Square Horizontal Rule Tracing Game Tutorial

The first application of the (online web application) line drawing we started with yesterday’s HTML Square Horizontal Rule Tracing Primer Tutorial is today’s online (web application) game version of some of the excellent puzzles in the book “Chinese Brain Twisters” by Baifang (ISBN: 0-471-59505-5). It was the “stick” rearrangement puzzles in this excellent book that were the inspiration to getting together a display and user interaction set of HTML and CSS and Javascript code logics to turn a hardcopy concept into an online game.

Of course, when you start with a “proof of concept” it can need quite a bit of “tweaking” (in this case, fitting it into those concept paradigms we talk about a couple of paragraphs on) when the reality of making it practical for the user comes into play with a project like this. We, at first thought, that …

  • we would display a question (about matches, rather than sticks, because we remember many a holiday game that involved the use of matches (… no, not that way) regarding patterns and counting, and because a match gives us an excuse to add some red colour as per CSS

    <style>
    hr {
    height: 4px;
    border: 2px solid black;
    background: linear-gradient(to right, yellow 80%, rgba(255,0,0,1) 20%);
    }
    </style>

    ) and then with a button controlled by the user, “slap on” the screen the answer … then we had a mild epiphany (you had to be there) …
  • we would display a question and then animate the answer … which can be achieved by “slapping on” that same question, and click/touch the actions of a successful user after 2 second delays between the clicks/touches (via a setTimeout timer controlled set of Javascript calls)

We hope it gives the game a more interactive feel, and a better way to learn perhaps, because geometry can be an “ahhhh haaa” type of thing to learn, when you see graphically the steps involved.

As with many a game we’ve written we again fall back to two tried and true (and very simple) concepts …

  • gather question data into simple (single dimension) arrays, additional complexity controlled within members by web application specific delimitation rules (or more singular dimensioned arrays (such as today, where there are two)) …
  • get the user a randomized question for the game via Javascript code like (where “inquestions” variable below is just such an array) …

    var choice=Math.floor(Math.random() * inquestions.length);

    … leading to “”inquestions[choice]” containing the data required to piece together the question … along with the “inwordings[choice]” of the other such array “inwordings” that contains “Chinese Brain Twisters” instructional text

Another “game chestnut” concept for us is to have some sort of scoring mechanism, which we may attend to in upcoming posts. For now, we’ll let you “cheat in the comfort of your own conscience” when bragging about your “Chinese Brain Twisters” prowess!

Feel free to try out the changed square_hr_tracing.htm‘s live run game, and challenge yourself!

You can also see this play out at WordPress 4.1.1’s HTML Square Horizontal Rule Tracing Primer Tutorial.


Previous relevant HTML Square Horizontal Rule Tracing Primer Tutorial is shown below.

HTML Square Horizontal Rule Tracing Primer Tutorial

HTML Square Horizontal Rule Tracing Primer Tutorial

One sad thing about today’s blog posting title is it gives the game away. We’re tackling a proof of concept web application for a future venture. We want to be able to draw a grid of lines (or you could see them as matches) and we’ll want to …

  • graphically present them (ie. grid square border lines (or matches)) around the edges of each grid square … and …
  • graphically present vertices at match end points and half way between, and well as in the middle of squares … then let the user …
  • click/touch a match … then …
  • click/touch two vertices to reposition that match to the clicked vertex positioning

Now, it seems to me, off the top of the head, you could proceed along the lines of …

  • HTML5 canvas element graphics … or
  • SVG graphics … but we prefer … you guessed it
  • HR (Horizontal Rule) HTML elements, transformed as required, to suit our purposes

Interested?! Why not try the HTML/Javascript/CSS square_hr_tracing.html‘s live run to see what we mean here.

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

Leave a Reply

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

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>