Table of Contents

State

Motivation

You want to adopt the finite state machine pattern because your game has many states and it becoming difficult to maintain.

Description

This is one half of the finite state machine pattern. This interface should act as a proxy for each of the methods which contain a lot of state specific code. For example, if you implement a lot of state code in render, update, and onCollision then you should include these methods in the interface defintion as follows:

public interface State {
    /** Initialize the state whenever it is entered. */
    public void enter();
    /** Used by the StateManager. */
    public boolean equals(Object o);
    public void render(Graphics g);
    public void update(int delta);
    public void onCollision(Entity obstacle);
}

Obviously you should identify what methods are relevant for your needs and swap them in.