Exemplo n.º 1
0
 public void introductionCommentary() {
   talker.say(
       new Commentary()
           .add("Today's matchup")
           .next(getTeam(Team.Side.LEFT).getName())
           .add(" versus ")
           .add(getTeam(Team.Side.RIGHT).getName())
           .next("Volley for serve"));
 }
Exemplo n.º 2
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);
  }