HTML Square Horizontal Rule Tracing Game Tutorial

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!


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.

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 *