Test your maths skills at the MathDOJO!

Anoth­er pro­duc­tive week­end bares fruit for anoth­er mini game! This time I’ve put togeth­er a dojo-themed mini game whose sole pur­pose is to test your abil­i­ty to do sim­ple (well, most­ly) arith­metic cal­cu­la­tions in your head and your tol­er­ance for my sense of humour (which is not so bad I hope ;-) ).

Screenshots

Here’s some screen­shots tak­en from the game:

image

image

image

image

image

image

image

As you can see, the main game loop is sim­ple: see some dia­logue from your oppo­nent, he asks a ques­tion, you answer, if you answer cor­rect­ly with­in time then your oppo­nent los­es health point, when the opponent’s HP is deplet­ed then you’ve defeat­ed him and move onto the next oppo­nent.

So far there’re 7 oppo­nents in the game, each with his own set of dia­logues and ques­tions become pro­gres­sive­ly hard­er, your score is tracked and you can get a big bonus in score if you answer the ques­tions quick­ly (and cor­rect­ly of course!) and man­age to string togeth­er a suc­ces­sion of cor­rect answers! As the oppo­nents become tougher, their ques­tions will yield greater scores too, and not to men­tion they’ll be hard­er to beat as they have a high­er HP val­ue which means you have more chance to bet­ter your all-time top score!

Game Flow

With­out going through all the steps of mak­ing the game (maybe I’ll do that at a lat­er date), the basic flow of the game goes some­thing like this:

image

The tricky thing is then how do you con­trol this flow eas­i­ly so that depend­ing on the state you’re in the right action is trig­gered when the play press­es the ENTER key.

In the end I set­tled for a mech­a­nism where the DOM’s onkey­down event is han­dled by this bit of code:

   1: // hook up the onkeydown event to execute the 'next' action whatever it might be

   2: document.onkeydown = function(event) {

   3:     if (event.keyCode == 13) {

   4:         nextAction();

   5:     }

   6: };

The nex­tAc­tion vari­able is updat­ed at each step of the game loop so that when the play­er press­es the ENTER key the game does the right thing. The only devi­a­tion from this pat­tern is when I try to get the answer from a play­er, because there’s a time restric­tion on answer­ing the ques­tions I need­ed to set up a timer so that when it times out it’ll trig­ger the state tran­si­tion as well.

Play

You can play the game at:

http://mathdojo.theburningmonk.com

or via the short­ened link:

http://LNK.by/fgzcu

Enjoy! Do let me know if you have any sug­ges­tions, dif­fi­cul­ty lev­el, etc. etc.