/** end the game but not yet exit, still stay in the game activity */ public static void endGame() { Client.deactivate(); Server.stop(); Client.stop(); ClientGameState.clear(); if (BallCraft.isServer) { ServerGameState.clear(); } GameRenderer.stopRendering(); ServerAdapter.stopBTService(); Intent intent = new Intent(self, EndGameMenu.class); intent.putExtra("selfScore", selfScore); intent.putExtra("enemyScore", enemyScore); self.startActivity(intent); self.finish(); self.overridePendingTransition(android.R.anim.fade_in, android.R.anim.fade_out); }
/** Initialize the main layout of the game view, including buttons, MUD, etc. */ private void initLayout() { this.setContentView(R.layout.game_layout); mGLView = (GLSurfaceView) this.findViewById(R.id.game_activity_gl_surface_view); // here we need to wait for the init data to be sent from the server to create the render // and start drawing while (!Client.isGameInited()) { try { Thread.sleep(100); } catch (Exception e) { } } self.renderer = new GameRenderer(this); mGLView.setRenderer(self.renderer); GameRenderer.startRendering(); int ballSelected = self.getIntent().getIntExtra("ballSelected", BallCraft.Ball.WOOD_BALL); final int[] skills = BallDef.getSkillsById(ballSelected); skill1 = skills[0]; skill2 = skills[1]; skill1Button = (Button) this.findViewById(R.id.game_activity_skill_1_button); skill1Button.setTypeface(MyApplication.getFont()); skill1Button.setBackgroundResource(SkillDef.getButtonById(skill1)); skill1Button.getBackground().setAlpha(180); skill1Button.setText(SkillDef.getSkillNameById(skill1)); skill1Button.setOnClickListener( new OnClickListener() { @Override public void onClick(View v) { Client.castSkill(Skill.getSkill(skill1)); skill1Button.setEnabled(false); skill1Button.setTextColor(Color.GRAY); skill1Button.getBackground().setAlpha(50); skill1CooledDown = false; Message msg = new Message(); msg.what = 1; skillCoolDownHandler.sendMessageDelayed(msg, SkillDef.getCoolDownTimeById(skill1)); } }); skill2Button = (Button) this.findViewById(R.id.game_activity_skill_2_button); skill2Button.setTypeface(MyApplication.getFont()); skill2Button.setBackgroundResource(SkillDef.getButtonById(skill2)); skill2Button.getBackground().setAlpha(180); skill2Button.setText(SkillDef.getSkillNameById(skill2)); skill2Button.setOnClickListener( new OnClickListener() { @Override public void onClick(View v) { Client.castSkill(Skill.getSkill(skill2)); skill2Button.setEnabled(false); skill2Button.setTextColor(Color.GRAY); skill2Button.getBackground().setAlpha(50); skill2CooledDown = false; Message msg = new Message(); msg.what = 2; skillCoolDownHandler.sendMessageDelayed(msg, SkillDef.getCoolDownTimeById(skill2)); } }); loseView = (TextView) this.findViewById(R.id.game_activity_lose_text); loseView.setTypeface(MyApplication.getFont()); loseView.setVisibility(View.INVISIBLE); remainingTimeView = (TextView) this.findViewById(R.id.game_activity_remaining_time_view); remainingTimeView.setTypeface(MyApplication.getFont()); scoreView = (TextView) this.findViewById(R.id.game_activity_score_view); scoreView.setTypeface(MyApplication.getFont()); scoreView.setText("0 : 0"); scoreView.setTextColor(Color.YELLOW); backScreen = (RelativeLayout) this.findViewById(R.id.game_activity_menu); backScreen.setVisibility(View.INVISIBLE); resumeButton = (TextView) this.findViewById(R.id.game_activity_resume_button); resumeButton.setTypeface(MyApplication.getFont()); resumeButton.setOnClickListener( new OnClickListener() { public void onClick(View v) { self.onBackPressed(); } }); exitButton = (TextView) this.findViewById(R.id.game_activity_exit_button); exitButton.setTypeface(MyApplication.getFont()); exitButton.setOnClickListener( new OnClickListener() { public void onClick(View v) { endGame(); } }); }