我的tic tac toe游戏在第一轮之后工作,但是当游戏结束并且我点击了重启按钮时,下一轮我突然无法点击任何东西,一切都冻结,玩家功能线程保持睡眠状态甚至在我点击GUI上的一个按钮后(它应该停止while循环)。重启按钮的功能是重启每个变量以进行下一轮的使用,并将游戏流程重定向回Execute()函数(控制游戏的顺序)。我的GUI上的播放器功能等待播放器通过在while循环上创建一个线程来进行移动。我想知道问题是关于每个按钮的GUI动作侦听器和我的Player函数的while循环之间的关系吗?请帮助这是我的代码。
void Execute(){
//Declaration
//Initialization
//Execution
if(int_info == 0){
this.int_turn = Object_GUI.setTurn(); //who makes the first turn?
}//if
while(bool_game == true){
if(int_info == 1){
Object_State.whoseTurn(this.int_turn); //the first turn player
makes his move and checked if the move is not yet taken
}//if
if(int_info == 2){
Object_GUI.placeMove(int_turn); //the move of the player will be
placed on the GUI depending on its coordinates
}//if
if(int_info == 3){
Object_Rules.whoWins(); //Checks if theres a winner
}//if
if(int_info == 4){
Object_State.nextTurn(int_turn); //sets the table for the next
player
}//if
if(int_info == 5){
reset(); //resets the variables for the next player
}//if
}//while(bool_game == true)
//Return
}//void Execute()
void reset(){
//Declaration
//Initialization
int_info = 1;
//Execution
Object_GUI.reset(); //Variables reset: String move
Object_State.reset(); //Variables reset: String_move, playerDone
Object_Algorithm.reset(); //Variables reset: String move
Object_Log.reset(); //Variables reset: NONE
//Return
}//void reset
void reboot(){
//Declaration
//Initialization
int_turn = 0;
int_info = 0;
Object_GUI.reboot();
Object_State.reboot();
Object_Rules.reboot();
Object_Algorithm.reboot();
Object_Log.reboot();
//Execution
//Return
}//void reset()
void restart(){
//Declaration
//Initialization
//Execution
reboot();
bool_game = true;
Execute();
//Return
}//void restart()
}//public class System_Manager
这是我的GUI java文件(同一个软件包)我只是包含我认为会导致问题的位。
void placeMove(int placeMove_currTurn){
//Declaration
//Initialization
//Execution
split = String_move.split(",");
if(X == placeMove_currTurn){ //If the first turner is equal to the
player on the current turn
if(split[0].equals("0") && split[1].equals("0")){
_00.setText("X");
}//if
else if(split[0].equals("0") && split[1].equals("1")){
_01.setText("X");
}//else if
else if(split[0].equals("0") && split[1].equals("2")){
_02.setText("X");
}//else if
else if(split[0].equals("1") && split[1].equals("0")){
_10.setText("X");
}//else if
else if(split[0].equals("1") && split[1].equals("1")){
_11.setText("X");
}//else if
else if(split[0].equals("1") && split[1].equals("2")){
_12.setText("X");
}//else if
else if(split[0].equals("2") && split[1].equals("0")){
_20.setText("X");
}//else if
else if(split[0].equals("2") && split[1].equals("1")){
_21.setText("X");
}//else if
else if(split[0].equals("2") && split[1].equals("2")){
_22.setText("X");
}//else if
}//if
else{
if(split[0].equals("0") && split[1].equals("0")){
_00.setText("O");
}//if
else if(split[0].equals("0") && split[1].equals("1")){
_01.setText("O");
}//else if
else if(split[0].equals("0") && split[1].equals("2")){
_02.setText("O");
}//else if
else if(split[0].equals("1") && split[1].equals("0")){
_10.setText("O");
}//else if
else if(split[0].equals("1") && split[1].equals("1")){
_11.setText("O");
}//else if
else if(split[0].equals("1") && split[1].equals("2")){
_12.setText("O");
}//else if
else if(split[0].equals("2") && split[1].equals("0")){
_20.setText("O");
}//else if
else if(split[0].equals("2") && split[1].equals("1")){
_21.setText("O");
}//else if
else if(split[0].equals("2") && split[1].equals("2")){
_22.setText("O");
}//else if
}//else
Object_System_Manager.getInfo(3);
//Return
}//void placeMove()
我的动作听众......
_00.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent ae) {
System.out.println("0,0");
Object_State.State_String_move = "0,0";
Object_State.playerDone = true;
}//void actionPerformed
});
播放器功能
void Player(){
//Declaration
//Initialization
//Execution
System.out.println("Player's Turn");
while(playerDone == false){
try {
Thread.sleep(200);
} catch(InterruptedException e) {
}//catch
}//while
//Return
}//void Player()