This tutorial will guide you through common use of the Binary for Java (B4J) tool. For the needs of this tutorial, you'll be a game developer, working on the first version of "Guess me right", a quizz game for two players.
The first player, Amy, writes the quizz and tries to guess what the second player would answer. The second player, Brian answers questions; for each answer corresponding to Amy guessing, the team scores one point. The final score tells you how well you know each other.
Your mission, if you accept it, is to write the grammar file used by the B4J tool to generate a binary file encoder and the corresponding decoding code in Java. By adding semantic actions as annotations in the grammar file, you will be able to define game actions executed at different steps of decoding.
In a real-life project, your decoding code would not be game actions, but would correspond to game objects construction, during a single loading phase before the game starts.
We suppose Amy has already created the quizz, e.g. through a web form, or using a simple text editor. HERE is the corresponding game data file, which should be encoded, then sent over-the-air to Brian's mobile phone. This is a simple xml file, created using the Windows Notepad with UTF-8 encoding.
By now, Apache Ant (1.6.1 or higher) and Sun Java JDK (1.4 or higher) should be installed, and present in your classpath. Check it typing
ant -versionthen
java -versionon DOS prompt.
Unzip B4J archive and change dir to b4j directory. Typing
antyou should get an overview of available tasks.
Go on to Chapter 2...