在发现启动新意图可能不是通知GameOver用户的正确方法后,我现在正在使用runOnUiThread,Runnable和对话框。
问题:我如何以及在何处实施Dialog.show()来通知用户游戏已经结束?我正在实施一场铁路比赛。在这场比赛中发生火车碰撞时我想在这里展示对话。
我已经尝试过runOnUiThread,Runnable和Async线程。无法弄清楚。 我想在MainGamePanel的碰撞发生方法中显示对话框。
我有一个游戏。活动AndroidGameActivity:
private static final String TAG = AndroidGame.class.getSimpleName();
public static Vibrator v;
private GameDatabaseOperations gameDatabaseOperations;
private int currentDate;
private int todayDate;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
try{
currentDate = Calendar.getInstance().get(Calendar.DATE);
gameDatabaseOperations = new GameDatabaseOperations(this);
gameDatabaseOperations.createWriteModeDatabase();
Cursor crDate = gameDatabaseOperations.fetchTodayDate();
startManagingCursor(crDate);
if(crDate!= null && crDate.getCount() >0){
crDate.moveToFirst();
todayDate = crDate.getInt(0);
}
if(currentDate != todayDate ){
gameDatabaseOperations.updateTodayDefaultScore(0);
gameDatabaseOperations.updateTodayDate(currentDate);
Cursor cr1Date = gameDatabaseOperations.fetchTodayDate();
startManagingCursor(cr1Date);
if(cr1Date!= null && cr1Date.getCount() >0){
cr1Date.moveToFirst();
todayDate = cr1Date.getInt(0);
}
}
gameDatabaseOperations.closeDatabase();
}
catch(Exception e){
e.printStackTrace();
}
FrameLayout fl = new FrameLayout(this);
setContentView(fl);
LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
LinearLayout pause = (LinearLayout) inflater.inflate(
R.layout.pausebutton, null);
fl.addView(new MainGamePanel(this));
fl.addView(pause);
v = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
}
答案 0 :(得分:0)
你有没有考虑像这样实现你的游戏引擎:
while (!collision)
{
playGame();
doAnimation();
checkCollision();
}
dialog.show();
performAction(determineNextGameState());
将所有游戏代码放入playGame()中,然后在用户死亡时修改碰撞字段?