@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_game); this.gamePanel = (MainGamePanel) findViewById(R.id.game_panel); username = getIntent().getExtras().getString(MainActivity.INTENT_USERNAME); this.gameClient = new GameClient(this, username); this.clientManager = new ClientCommunicationProxy(this.gameClient); this.gameClient.setGameServer(clientManager); this.gamePanel.setGameClient(this.gameClient); this.updateScreenHandler = new Handler(); upListener = new DirectionButtonListener(Direction.UP, gameClient); this.findViewById(R.id.button_up).setOnTouchListener(upListener); downListener = new DirectionButtonListener(Direction.DOWN, gameClient); this.findViewById(R.id.button_down).setOnTouchListener(downListener); leftListener = new DirectionButtonListener(Direction.LEFT, gameClient); this.findViewById(R.id.button_left).setOnTouchListener(leftListener); rightListener = new DirectionButtonListener(Direction.RIGHT, gameClient); this.findViewById(R.id.button_right).setOnTouchListener(rightListener); timeLeft = (TextView) this.findViewById(R.id.time_left); playerName = (TextView) this.findViewById(R.id.player_name); score = (TextView) this.findViewById(R.id.player_score); playerNumber = (TextView) this.findViewById(R.id.player_number); this.updateScreenRunnable = new Runnable() { @Override public void run() { update(gameClient.getPlayer()); updateScreenHandler.postDelayed(updateScreenRunnable, 1000); } }; this.updateScreenRunnable.run(); }
@Override public void onDestroy() { super.onDestroy(); stopAll(); }
@Override public void onPause() { super.onPause(); gamePanel.stopAll(); }