SampleConfig
From Gardenwiki
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:
<?xml version="1.0" standalone="yes"?>
<game>
<!-- the string identifier for this game; this is used to name our jar -->
<!-- file and to name other internal bits -->
<ident>sample</ident>
<!-- The controller and manager used for our game. -->
<controller>com.whomever.sample.client.SampleController</controller>
<manager>com.whomever.sample.server.SampleManager</manager>
<!-- Herein we define how the game is matchmade and configured. -->
<match type="table">
<!-- Properties configure the match maker, in this case: table. -->
<min_seats>2</min_seats>
<max_seats>4</max_seats>
<start_seats>2</start_seats>
</match>
<!-- Parameters define values that the user can customize when -->
<!-- creating a game and which are passed on to the game itself -->
<!-- to customize the gameplay. -->
<params>
<range ident="board_size" minimum="16" maximum="48" start="32"/>
<choice ident="rules" choices="standard,hand_of_three" start="standard"/>
<toggle ident="monkeys" start="false"/>
</params>
</game>
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 <params> 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.

