2

Basically what I am trying to achieve is this; I have an android Activity that executes a game class (built on the libgdx framework) and I need to run a check to see if the game is over by calling a method from within the game class.

Is it possible to run this check multiple times (until the game is over) so that the android Activity can then move on to a different activity when the game is over?

I hope I made myself clear enough, Thanks for the help :)

4

2 回答 2

2

使用 BroadcastReceiver 和 LocalBroadcastManager。创建并注册一个 BroadcastReceiver 来捕捉和处理游戏结束。然后,当游戏结束时

LocalBroadcastManager.getInstance(context).sendBroadcast(gameOverIntentFilter);
于 2012-10-16T18:31:28.830 回答
1

为什么不将委托模式与接口一起使用。

class Game {   
     private OnGameOverListener mListener;
     public void setOnGameOverListener(OnGameOverListener listener) {
          mListener = listener;
     }

    public interface OnGameOverListener{
         public void onGameOver()
    }

    someFunction(..) { 
        listener.onGameOver();// call when game is over
    }


}

然后在 Activity 中实现 OnGameOverListener 并在覆盖的 onGameOver 方法中调用 finish()

于 2012-10-16T18:36:10.733 回答