Test-Driven Java Development(Second Edition)
上QQ阅读APP看书,第一时间看更新

Implementation

This implementation should be similar to the previous one. We already have horizontal verification and now we need to do the same vertically:

private boolean isWin() {
  int playerTotal = lastPlayer * 3;
  for (int i = 0; i < SIZE; i++) {
    if (board[0][i] + board[1][i] + board[2][i] == playerTotal) {
      return true;
    } else if (board[i][0] + board[i][1] + board[i][2] == playerTotal) {
      return true;
    }
  }
  return false;
}