2013-03-14 51 views
0

我是Android的新手,在線教程後,我遇到了TicTacToe遊戲的touchListener代碼塊問題。關於touchlistener的代碼錯誤 - Android

我不斷收到的錯誤是:

操作& &未定義的參數類型布爾,無效

下面的代碼位於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

我會非常感謝任何幫助。

非常感謝,

貝絲·安·

回答

2

在您鏈接到PDF,setMove()有一個布爾返回類型(第5頁,上圖):

private boolean setMove(char player, int location) { 
    if (mGame.setMove(player, location)) { 
     mBoardView.invalidate(); // Redraw the board 
     if (player == TicTacToeGame.HUMAN_PLAYER) 
      mHumanMediaPlayer.start(); 
     else 
      mComputerMediaPlayer.start(); 
     return true; 
    } 
    return false; 
} 
+0

我已經修改setMove()來boolean: – 2013-03-14 21:02:46

+0

private boolean setMove(char player,int location){ if(mGame.setMove(player,location)){ mBoardView.invalidate(); //重畫板 返回true; } return false; } – 2013-03-14 21:03:23

+0

它仍然沒有工作 – 2013-03-14 21:38:20