Package vrampal.connectfour.core

Examples of vrampal.connectfour.core.ConnectFourException


  @Override
  public void begin() {
    if (status != GameStatus.INIT) {
      String message = "begin operation is not allowed in status: " + status;
      log.error(message);
      throw new ConnectFourException(message);
    }

    status = GameStatus.ONGOING;

    if (log.isInfoEnabled()) {
View Full Code Here


  @Override
  public int dropDisc(int colIdx) {
    if (status != GameStatus.ONGOING) {
      String message = "dropDisc operation is not allowed in status: " + status;
      log.error(message);
      throw new ConnectFourException(message);
    }

    Player currentPlayer = getCurrentPlayer();
    int rowIdx = board.dropDisc(currentPlayer, colIdx);
    turnNumber++;
View Full Code Here

  @Override
  public void drawGame() {
    if (status != GameStatus.ONGOING) {
      String message = "drawGame operation is not allowed in status: " + status;
      log.error(message);
      throw new ConnectFourException(message);
    }

    status = GameStatus.FINISHED;
    winner = null;
View Full Code Here

  @Override
  public void victory(Player winPlayer) {
    if (status != GameStatus.ONGOING) {
      String message = "victory operation is not allowed in status: " + status;
      log.error(message);
      throw new ConnectFourException(message);
    }

    status = GameStatus.FINISHED;
    winner = winPlayer;
View Full Code Here

  /**
   * Create a board with custom size.
   */
  BoardImpl(int width, int height) {
    if (width <= 0) {
      throw new ConnectFourException("Invalid width: " + width);
    }
    if (height <= 0) {
      throw new ConnectFourException("Invalid height: " + height);
    }

    this.width = width;
    this.height = height;
    content = new Player[width * height];
 
View Full Code Here

  private void checkColIdx(int colIdx) {
    if ((colIdx < 0) || (colIdx >= getWidth())) {
      String message = "Invalid column id: " + colIdx;
      log.error(message);
      throw new ConnectFourException(message);
    }
  }
View Full Code Here

  private void checkRowIdx(int rowIdx) {
    if ((rowIdx < 0) || (rowIdx >= getHeight())) {
      String message = "Invalid row id: " + rowIdx;
      log.error(message);
      throw new ConnectFourException(message);
    }
  }
View Full Code Here

   */
  int dropDisc(Player player, int colIdx) {
    if (player == null) {
      String message = "Null is not a valid player";
      log.error(message);
      throw new ConnectFourException(message);
    }
    if (player == EMPTY_PLAYER) {
      String message = "Empty player not allowed to play";
      log.error(message);
      throw new ConnectFourException(message);
    }
    // isColumnFull() also perform checkColIdx() no need to to it twice.
    if (isColumnFull(colIdx)) {
      String message = "Column is full";
      log.error(message);
      throw new ConnectFourException(message);
    }

    int rowIdx = getHeight() - 1;
    while ((rowIdx > 0) && (getCellFast(colIdx, rowIdx - 1) == null)) {
      rowIdx--;
View Full Code Here

TOP

Related Classes of vrampal.connectfour.core.ConnectFourException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.