首页 文章

Java:连接4,二进制运算符错误的坏操作数类型

提问于
浏览
-2

我得到一些奇怪的坏操作数错误,我似乎无法解决 .

public class Model {

// Keep track of whether a move animation is currently playing.
// When a move animation is busy then no new moves are allowed.
private boolean moveInProgress = false;
private int[][] pieces = new int[7][7];
private boolean gameOver = false;


public void checkGameOver() {
    // TODO (step 3): implement this correctly.
    gameOver = true;
}

/**
 * Check if a new disk can be inserted in the current column.
 * @param column
 * @return true if and only if a move in this column is allowed.
 */
public boolean playableMove(int column) {
    // No new moves are allowed when an animation is busy.
    if (getMoveInProgress()) {
        return false;
    }
    // TODO (step 3) No moves are allowed when the game is over.
    if (gameOver) {
        return false;
    }
    // TODO: Check if this move is playable.
    if (pieces[column] > 6) {
        return false;
    }
    return true;
}

/**
 * Compute the final destination row of a candidate move.
 * @param column
 * @return the row.
 */
public int moveDestination(int column) {
    // TODO: implement this method properly.
    int positie = 6 - pieces[column];
    return positie;
}

/**
 * Commit the insertion of a new disk in a given column.
 * @param column
 */
public void playMove(int column) {
    // TODO: Verify the following preconditions:
    // assert (isGameOver() == false);
    // assert (playableMove(column) == true);

    // TODO: Update the model to reflect the new move.

    // TODO (step 3): Also check for termination conditions.

    // TODO (step 3): Notify subscribers about important model changes.

    if (!gameOver && playableMove(column)) {

        pieces[column]++;
    }
}
}

错误发生在

(76,28)二元运算符的错误运算符'>'第一类型int []第二类型int

相同的错误重复4次 .

谁能帮我这个

2 回答

  • 0

    你定义了 private int[][] pieces = new int[7][7]; . 因此,当您使用 pieces[column] 访问它时,您将're left with an array, so you can'与 int 进行比较 .

    你可能意味着 pieces[column].length

  • 0

    如果要对数组的每个元素执行任何算术运算,则必须明确地执行此操作 .

    例如,

    if (!gameOver && playableMove(column)) {
        for (int i=0; i < pieces[column].length; i++) {
            pieces[column][i]++;
        }
    }
    

    关于其他检查( 6 - pieces[column] ,这意味着产生一个整数和 pieces[column] > 6 ,这使得它不清楚这个条件是否适用于所有元素或至少一个)我不能帮助你由于未知的前提条件 .

相关问题