Requirement 4 – the game's output

A few outputs should be added to let the players know the current status of the game.

We want feedback when either an event or an error occurs within the game. The output shows the status of the board after every move.

No output channel is specified. To make it easier, we decided to use the system standard output to print an event when it occurs. A few lines have been added on every action to let the user know about the status of the game:

... 
private static final String DELIMITER = "|";
 
private void switchPlayer() {
  if (Color.RED == currentPlayer) {
    currentPlayer = Color.GREEN;
  } else {
    currentPlayer = Color.RED;
  }
  System.out.println("Current turn: " + currentPlayer);
}

public void printBoard() {
  for (int row = ROWS - 1; row >= 0; --row) {
    StringJoiner stringJoiner =
new StringJoiner(DELIMITER, DELIMITER, DELIMITER); for (int col = 0; col < COLUMNS; ++col) { stringJoiner.add(board[col][row].toString()); } System.out.println(stringJoiner.toString()); } } public void putDisc(int column) { if (column > 0 && column <= COLUMNS) { int numOfDiscs = getNumberOfDiscsInColumn(column - 1); if (numOfDiscs < ROWS) { board[column - 1][numOfDiscs] = currentPlayer; printBoard(); switchPlayer(); } else { System.out.println(numOfDiscs); System.out.println("There's no room " + "for a new disc in this column"); printBoard(); } } else { System.out.println("Column out of bounds"); printBoard(); } } ...
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.227.111.208