Code layer: the logic

Coding is an exercise in managing complexity and the basic technique is ‘divide and conquer’. The task is broken down into separated components, which in turn are composed of smaller units and so on. All real programming languages have features to facilitate this - Java uses packages and classes. So the major skill for coding is being able to decompose the task in a way such that each component is able to focus on doing a particular job with minimal (or no) referencing of other components. Described technically as “low coupling, high coherence”.

Other broad techniques are to make use of well established solutions known as “patterns” and to plug-in existing pre-designed components such as libraries and frameworks. Why reinvent the wheel?

The very broad decomposition for zodiac empire is shown here.

The logic component keeps track of everything in the game and makes sure they behave properly e.g. it knows how to move a ship from planet A to planet B.

The GUI handles all the clicks and keypresses from the user and visualises the game objects such as ships. It’s the screen.

The AI part aims to be an effective virtual opponent and actually instruct the ship to move from planet A to planet B.

All of these get broken down into more and more specific parts and they ‘talk’ to each other via a ‘eventbus’. So when the AI wants to move a ship it sends a message on the bus which is picked up by the logic. As the logic changes the ship position it sends a message to the GUI to display the revised location.

The JMonkeyEngine framework is used by the logic to provide some out-the-box abilities. And somewhere in all this has to be woven all the images, text, configuration files, audio and other assets and resources that define things like what a ship actually looks like (and normally have entire art departments to produce them)

As always there is more detail and actual code at the Bitbucket site.