Пример #1
0
 /**
  * Checks which of the two players is the winner. If the game is a draw, the returned player is
  * Player 1 (the one that plays on the botoom part of the screen).
  *
  * @see Player
  * @return the winner of the game.
  */
 public Player checkWinner() {
   if (board.getPlayerCup1Marbles() >= board.getPlayerCup2Marbles()) {
     return player1;
   } else {
     return player2;
   }
 }
Пример #2
0
  /**
   * Returns the names of both of the players and their score as an array. The order of the elements
   * is: The winner's name, his score, other player's name and finally the other player's name.
   *
   * @return array with the 2 players and their respective scores
   */
  public String[] getFinalResults() {
    String winner;
    int winnerScore;
    String loser;
    int loserScore;

    if (checkWinner().equals(player1)) {
      winner = player1.getName();
      winnerScore = board.getPlayerCup1Marbles();
      loser = player2.getName();
      loserScore = board.getPlayerCup2Marbles();
    } else {
      winner = player2.getName();
      winnerScore = board.getPlayerCup2Marbles();
      loser = player1.getName();
      loserScore = board.getPlayerCup1Marbles();
    }

    String[] results = {winner, Integer.toString(winnerScore), loser, Integer.toString(loserScore)};
    return results;
  }