private void updateScore() { Player p1 = game.getPlayer(Game.PLAYER1); Player p2 = game.getPlayer(Game.PLAYER2); String text; if (game.isActualPlayer(p1)) { text = "<b><u>" + p1.getName() + "</u></b> " + p1.getScore() + scoreText + p2.getScore() + " <b>" + p2.getName() + "</b>"; } else { text = "<b>" + p1.getName() + "</b> " + p1.getScore() + scoreText + p2.getScore() + " <b><u>" + p2.getName() + "</u></b>"; } Spanned htmlText = Html.fromHtml(text); textScore.setText(htmlText); }
/** * * OnClick for the gameBoard's cells * * @param v : View from the cell where the player want to add a piece */ @Override public void onClick(View v) { // Get move from cell ImageView cell = (ImageView) v; Move nextMove = getMoveFromCase(cell); // Play the move in the game game.playMove(nextMove); // Update graphics updateGraphic(); switch (game.getState()) { case Game.NO_MOVE: Tools.Toast( getApplicationContext(), "No possible move for player " + game.getActualPlayer().getName() + ",\nit's " + game.getEnemyPlayer().getName() + " turn"); break; case Game.IMPOSSIBLE_MOVE: Tools.Toast( getApplicationContext(), "Move : " + nextMove.toString() + " is not possible !"); break; case Game.END_GAME: Tools.Toast( getApplicationContext(), "Move : " + nextMove.toString() + " is not possible !"); endGame(); break; } }
@Override public void onDialogResult(MainDialog caller, Bundle result) { Intent intent; switch (result.getInt("newOrEnd")) { case R.id.newGame: game = new Game(game.getMode(), game.getPlayer(Game.PLAYER1), game.getPlayer(Game.PLAYER2)); updateGraphic(); saveGame(false); break; case R.id.quit: intent = new Intent(GameActivity.this, HomeActivity.class); startActivity(intent); break; default: break; } }
private void updateGraphicalBoard() { ImageView imgView; for (int i = 0; i < GameBoard.BOARD_SIZE; i++) { for (int j = 0; j < GameBoard.BOARD_SIZE; j++) { int cellValue = game.getGameBoard().getPlayerIDAtPos(i, j); imgView = getCaseView(i, j); if (GameBoard.NO_COIN != cellValue) { if (GameBoard.BLUE_COIN == cellValue) { imgView.setImageResource(R.drawable.circle_blue); } else if (GameBoard.RED_COIN == cellValue) { imgView.setImageResource(R.drawable.circle_red); } } else { imgView.setImageDrawable(null); } } } }
public Player getNameWinner() { return game.getActualPlayer().getScore() > game.getEnemyPlayer().getScore() ? game.getActualPlayer() : game.getEnemyPlayer(); }
private void saveGame(boolean show) { File file = new File(getFilesDir(), "game_" + game.getMode()); Tools.writeSerializableInFile(this, game, file); if (show) Tools.Toast(this, "Game saved"); }