Example #1
0
 public boolean isEndOfMatch() {
   if (!isEndOfGame()) {
     return false;
   }
   return leftTeam.getWins() == matchLength.getMinGames()
       || rightTeam.getWins() == matchLength.getMinGames();
 }
Example #2
0
  public Commentary checkForGamePoint(Commentary commentary) {
    if (leftTeam.getScore() >= this.getGameLength().getPoints() - 1
        && leftTeam.getScore() - rightTeam.getScore() >= 1) {
      if (isOvertime()) {
        commentary.next("Advantage ").add(leftTeam.getName());
      } else if (leftTeam.getWins() == matchLength.getMinGames() - 1) {
        commentary.next("Match point");
      } else {
        commentary.next("Game point");
      }
    }
    if (rightTeam.getScore() >= this.getGameLength().getPoints() - 1
        && rightTeam.getScore() - leftTeam.getScore() >= 1) {
      if (isOvertime()) {
        commentary.next("Advantage ").add(rightTeam.getName());
      } else if (rightTeam.getWins() == matchLength.getMinGames() - 1) {
        commentary.next("Match point");
      } else {
        commentary.next("Game point");
      }
    }

    return commentary;
  }
Example #3
0
  public void incrementTeamScore(Team.Side side) {
    Team team = getTeam(side);
    log.trace("Increment team: " + team);
    Commentary commentary = new Commentary();

    if (isEndOfMatch()) {
      return;
    }
    if (isEndOfGame()) {
      Team winner = getWinner();
      Team loser = getLoser();
      leftTeam.setScore(0);
      rightTeam.setScore(0);
      server = loser.getSide();
      switchSides();
      return;
    }

    if (server == null) {
      server = side;
      commentary.add(team.getName()).add(" serves first");
    } else {
      team.setScore(team.getScore() + 1);
      histories.add(0, new PointHistory(side, PointHistory.Type.INCREMENT));
      if (!isOvertime() && !isEndOfGame()) {
        commentary.add("Point ").add(team.getName());
      }
      if (isEndOfGame()) {
        Team winner = getWinner();
        Team loser = getLoser();

        winner.setWins(winner.getWins() + 1);

        if (leftTeam.getWins() == matchLength.getMinGames()
            || rightTeam.getWins() == matchLength.getMinGames()) {

          commentary
              .next("Congratulations ")
              .add(winner.getName())
              .next("You have defeated ")
              .add(loser.getName());
        } else {
          commentary
              .add(winner.getName())
              .add(" wins the game")
              .next("Switch sides")
              .next("Losers serve first");
        }
        if (loser.getScore() == 0) {
          commentary.next("Perfect game!", "Perfect, game!");
        } else if (loser.getScore() <= 12 && gameLength == GameLength.TWENTY_ONE) {
          commentary.next("Sorry ").add(loser.getName()).add(", Jacob is not impressed!");
        }
      } else {
        int totalScore = leftTeam.getScore() + rightTeam.getScore();
        // check for o-fer and add to commentary
        if (!isOvertime() && totalScore != 0 && isServerChange()) {
          log.trace("Check for ofer");
          commentary = checkForOfer(team, commentary);
        }

        if (isServerChange()) {
          if (!isOvertime()) {
            commentary.next("Change servers", "Change servers!");
          }
          switchServers();
          // String name = getTeam(server).getName();
        }
        // announce score
        if (!isOvertime()) {
          AnnounceScore announceScore = new AnnounceScore(this);
          commentary.next(announceScore.getScore());
        } else {
          if (leftTeam.getScore() == rightTeam.getScore()) {
            commentary.next("Deuce", "Deuce!");
          }
        }

        // check for gamepoint or matchpoint
        commentary = checkForGamePoint(commentary);
      }
    }

    log.trace(
        "Score: "
            + leftTeam.getName()
            + " "
            + leftTeam.getScore()
            + " to "
            + rightTeam.getName()
            + " "
            + rightTeam.getScore());
    talker.say(commentary);
  }
Example #4
0
 public void incrementTeamVictory(Team.Side side) {
   Team team = getTeam(side);
   if (team.getWins() < matchLength.getMinGames() - 1) {
     team.setWins(team.getWins() + 1);
   }
 }