0
 **

これにより、この五目並べゲームで勝利の動きを超える追加の動きが発生し、余分な動きの後の 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.
*/
4

2 に答える 2

2
checkForWin works correctly when tested with just a file in a test class

コードの一部:

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");

checkForWinが返される場合true、メソッドは でハングしている必要がありますmakeMove(gameFile)。これは、何らかの無限ループに陥っている可能性があります。

于 2013-08-11T01:58:56.263 に答える