Esempio n. 1
0
 /**
  * Check for game end conditions (without time) and end the game if they are satisified. Otherwise
  * do nothing.
  */
 private void checkForGameEnd() {
   if (mNpcContainer.getDemonCount() <= 0) {
     end(GameEndReason.ALL_DEMONS_DEAD);
   } else if (mNpcContainer.getHumanCount() <= 0) {
     end(GameEndReason.ALL_HUMANS_DEAD);
   }
 }
Esempio n. 2
0
 /**
  * Update all game elements. Consider update methods execution dependencies. Currently there are
  * none.
  */
 @Override
 public void update() {
   if (getGameState() == GameState.RUNNING) {
     updateTime();
     mBackground.update();
     mDeathEffectContainer.update();
     mNpcContainer.update();
   }
 }
Esempio n. 3
0
 /**
  * On touch remove top touched npc and create a death effect on the touched spot. Trigger
  * GameState.END if the last Demon or Human was killed
  *
  * @param touchX
  * @param touchY
  * @return enum value that shows if some game element was actually touched or not
  */
 public TouchedElement onTouchEvent(float touchX, float touchY) {
   TouchedElement result = TouchedElement.NONE;
   if (mGameState == GameState.RUNNING) {
     Npc touchedNpc = mNpcContainer.removeTopTouchedNpc(touchX, touchY);
     if (touchedNpc != null) {
       boolean isDemon = touchedNpc.getNpcType().isEnemy();
       updateScore(touchedNpc);
       // Create a new death effect at the location of the killed npc
       mDeathEffectContainer.createDeathEffect(
           touchedNpc.getCenterX(), touchedNpc.getCenterY(), isDemon);
       if (isDemon) {
         result = TouchedElement.DEMON;
       } else {
         result = TouchedElement.HUMAN;
       }
     }
     checkForGameEnd();
   }
   return result;
 }
Esempio n. 4
0
 /**
  * Save state of Score and NPCs. Ignore the death effects since they are too short to matter
  *
  * @param outState
  */
 public void saveState(Bundle outState) {
   mNpcContainer.saveState(outState);
   outState.putInt(SCORE, mScore);
   outState.putInt(TIME, mTimeLeftInSeconds);
   outState.putLong(TIME_MILLIS, mTimeLeftInMilliseconds);
 }
Esempio n. 5
0
 /**
  * Render all game elements. Order of rendering affects the order on the Z axis. First things
  * rendered are on the back. Last things rendered are on the front.
  */
 @Override
 public void render(Canvas canvas) {
   mBackground.render(canvas);
   mDeathEffectContainer.render(canvas);
   mNpcContainer.render(canvas);
 }