SampleConfig

sample.xml
In addition to your game code, you will need to create a game definition file which is what the Game Gardens system will use to match-make and start your game. Here is the sample configuration:

 sample

com.whomever.sample.client.SampleController com.whomever.sample.server.SampleManager

2 4 2

  

It is mainly self-explanatory with the items in bold being the things that absolutely must be customized. The match-making configuration also requires a bit more explanation. Each entry in the section provides a configurable parameter to the person creating your game. Three types of parameters are currently provided:


 * range: allows an integer value to be chosen from a specified range.
 * choice: allows a single choice to be selected from a list of choices.
 * toggle: a simple on/off boolean toggle.

The values chosen by the player during the match-making phase are communicated to the game code via the ToyBoxGameConfig class. Here's an excerpt from SkirmishManager to show how this is used:

// documentation inherited protected void gameWillStart {       super.gameWillStart;

// get a casted reference to our game configuration _skonfig = (ToyBoxGameConfig)_config;

// generate the game board int size = (Integer)_skonfig.params.get("board_size"); int featureDensity = (Integer)_skonfig.params.get("feature_density"); _skobj.setBoard(SkirmishBoard.generateBoard( size, size, featureDensity));

// start the vessels in the center of the "board" int dx = size/2-3, dy = size/2-3;

// ...   }

As you can see, the configuration values will never be null. They will either be the default value provided in your game configuration or some customized value provided by the user when configuring your game. This allows you to avoid duplicating the default values from your game configuration in your game manager.

sample.properties
The Narya system provides a mechanism for localizing your game that is based on Sun's localization facilities. It is not a requirement that you use this system except to provide translations for your game configuration parameters.

This is accomplished by adding entries to the properties file: rsrc/i18n/sample.properties.

The configuration shown above would use the following translations:

m.range_board_size = Board size: m.choice_rules = Rules: m.choice_standard = Standard m.choice_hand_of_three = Hand of three m.toggle_monkeys = Include Monkeys?

A forthcoming article on how to actually use the localization services will explain where to put localized versions of your properties files and how to access those translations from within the game. The sample games make use of the localization services so in the meanwhile that's a good place to look.

Back to tutorial.