**
这导致在这个五子棋游戏中除了获胜移动之外还有一个额外的移动,额外移动之后的 checkForWin 方法是检测胜利的方法,但它应该是相应的 makeMove 方法之后的 checkForWin 方法。
**
import java.io.File;
boolean hasWinner = false;
File gameFile = new File("src/centralGameFile.txt");
do{
//player 1
makeMove(gameFile);
// check for win
if (checkForWin(gameFile)){
hasWinner = true;
break;
}
// player 2
makeMove(gameFile);
// check for win
if (checkForWin(gameFile)){
hasWinner = true;
break;
}
}while(hasWinner == false);
System.out.println("somebody has won the game");
/*this method is located in another class in the same package and is
called from an instance of the class using the access operator */
protected boolean checkForWin(File f){
//return true if the file has a winner in it using scanner to look for it
//this method works correctly when tested with just a file in a test class
}
// 为简洁起见省略了 try/catch 块
/* makeMove(File f) method copies the text from f and over writes
it adding another character; in context this is a gomoku/tic-tac-toe
style game but on a bigger board.
*/