Coding the GameState
The GameState
class has exactly the same role as in the previous project. Obviously, however, the details of the state in this project is different. In the previous project we had score, high score lasers and aliens; in this one we have time, multiple fastest times and which level is being played. The GameState
class also takes care of knowing (and sharing) the current state of paused, playing, drawing, thread running, etc.
Create a new class called GameState
and add the member variables and constructor as shown next.
import android.content.Context; import android.content.SharedPreferences; final class GameState { private static volatile boolean mThreadRunning = false; private static volatile boolean mPaused = true; private static volatile boolean mGameOver = true; private static volatile boolean mDrawing = false; private EngineController engineController; private int mFastestUnderground; private int mFastestMountains; ...