Exemplo n.º 1
0
  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);
  }
Exemplo n.º 2
0
  /**
   * * 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;
    }
  }
Exemplo n.º 3
0
  @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;
    }
  }
Exemplo n.º 4
0
  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);
        }
      }
    }
  }
Exemplo n.º 5
0
 public Player getNameWinner() {
   return game.getActualPlayer().getScore() > game.getEnemyPlayer().getScore()
       ? game.getActualPlayer()
       : game.getEnemyPlayer();
 }
Exemplo n.º 6
0
  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");
  }