GameManager.java :  » Game » ihcibombgame » cs525 » proj » BombGame » Android Open Source

Android Open Source » Game » ihcibombgame 
ihcibombgame » cs525 » proj » BombGame » GameManager.java
package cs525.proj.BombGame;

public class GameManager
{
  public enum GameState
  {
    BEGINNING, BOMB_DANGER, BOMB_SAFE, BOMB_EXPLODE
  }

  private final GameState mState;
  private ButtonManager mButMgr;
  private RenderManager mRenderMgr;
  private SecureTimer mSecureTimer;
  private DeliverTimer mDeliverTimer;
  private SafetyZone mSafeZone;
  private Bomb mBomb;

  public GameManager()
  {
    mState = GameState.BEGINNING;
  }

  public void Update()
  {
    switch (mState)
    {
      case BEGINNING:
        // Update sub nodes: RenderManager, ButtonManager
        // We should have: a button

        // If the button is touched
        if (mButMgr.oneTouch())
        {
          mState = GameState.BOMB_DANGER;
        }
        break;
      case BOMB_DANGER:
        // Update sub nodes: RenderManager, ButtonManager, SecureTimer,
        // SafetyZone, Bomb
        // We should have: a button (pressed), a bomb, a safety zone, a
        // text timer

        if (mSecureTimer.timeout() || !mButMgr.oneTouch(userx, usery))
        {
          mState = GameState.BOMB_EXPLODE;
        } else if (mSafeZone.liesIn(mBomb))
        {
          mState = GameState.BOMB_SAFE;
        }
        break;
      case BOMB_SAFE:
        // Update sub nodes: RenderManager, ButtonManager,
        // SecureTimer(cool it), SafetyZone, Bomb
        // We should have: two buttons, a bomb in a safety zone, a text timer
        
        if(!mButMgr.oneTouch(userx, usery) || mDeliverTimer.timeout())
        {
          mState = GameState.BOMB_EXPLODE;
        }else if(mButMgr.twoTouch(userx1, usery1, userx2, usery2) || mSafeZone.liesIn(mBomb))
        {
          mState = GameState.BOMB_DANGER;
          //Need to keep the location of the bomb in BOMB_DANGER state
        }
        break;
      case BOMB_EXPLODE:
        // Update sub nodes: RenderManager (explosion),
        // Reset: ButtonManager, SecureTimer, SafetyZone, Bomb, DeliverTimer
        // We should have: an explosion (sound, picture, vibration)
        
        if(SystemTimer > 5 secs)
        {
          mState = GameState.BEGINNING;
        }
        break;
    }
  }
}
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.