我是 Android 的新手,我在使用在线教程后的 TicTacToe 游戏的 touchListener 代码块时遇到了问题。
我不断收到的错误是:
运算符 && 未定义参数类型 boolean, void
以下代码位于 MainActivity.java 中。我在下面用星号突出显示的行上收到此错误:
// Listen for touches on the board
private OnTouchListener mTouchListener = new OnTouchListener() {
public boolean onTouch(View v, MotionEvent event) {
// Determine which cell was touched
int col = (int) event.getX() / mBoardView.getBoardCellWidth();
int row = (int) event.getY() / mBoardView.getBoardCellHeight();
int pos = row * 3 + col;
if (!mGameOver && setMove(TicTacToeGame.HUMAN_PLAYER, pos)) { //*****************
// If no winner yet, let the computer make a move
int winner = mGame.checkForWinner();
if (winner == 0) {
mInfoTextView.setText(R.string.turn_computer);
setMove(TicTacToeGame.COMPUTER_PLAYER, pos);
winner = mGame.checkForWinner();
}
}
return false;
}
};
我认为这是因为 setMove() 在 TicTacToeGame.java 中是无效的:
public void setMove(char player, int location) {
if (location >= 0 && location < BOARD_SIZE &&
mBoard[location] == OPEN_SPOT) {
mBoard[location] = player;
}
}
我完全按照教程http://www.harding.edu/fmccown/classes/comp475-s10/tic-tac-toe-graphics.pdf
我将非常感谢任何帮助。
非常感谢,
贝丝安