Another pro­duc­tive week­end bares fruit for another mini game! This time I’ve put together a dojo-themed mini game whose sole pur­pose is to test your abil­ity to do sim­ple (well, mostly) 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 ;-) ).

Screen­shots

Here’s some screen­shots taken 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­rectly within time then your oppo­nent loses health point, when the opponent’s HP is depleted then you’ve defeated him and move onto the next opponent.

So far there’re 7 oppo­nents in the game, each with his own set of dia­logues and ques­tions become pro­gres­sively harder, your score is tracked and you can get a big bonus in score if you answer the ques­tions quickly (and cor­rectly of course!) and man­age to string together 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 harder to beat as they have a higher HP value 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 later 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­ily so that depend­ing on the state you’re in the right action is trig­gered when the play presses 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 updated at each step of the game loop so that when the player presses 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 player, because there’s a time restric­tion on answer­ing the ques­tions I needed 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­culty level, etc. etc.

Share

Leave a Reply