TicTacToe 게임을 만들려고 시도하면서이 코드를 추가했습니다. 처음에는 게임이 한 턴 동안 만 진행되었지만 플레이어가 게임을 끝내면 끝내는 방법이 필요했습니다. 하지만 코드를 실행했을 때 턴을 플레이하지 않았습니다. 나는 간단한 방법으로 (a> 3) {/ play turn/a ++;}을 테스트했으며 루프가 제대로 끝나지 않았고 점점 가늘어지고 수동으로 종료하도록 강요했다. 내 터미널.while 루프로 내 게임 끝내기 -
http://hastebin.com/iziselusex.tex
당신이 그것을
http://hastebin.com/isoxifufeq.axapta
요구 때문에 내 회전 방법입니다 그리고 이것은 초기화 방법뿐만 아니라 턴에 언급 된 방법
int[][] anArray = new int[3][3];
aBoard.initialize();
int end = 0;
int t = 0;
while(end != 1){ //so long as end isn't reached, the game will still play
while(t < 4){ //there are a total of 4 turns that can take place before the board is filled up. 5 if you include the last piece, but i wasn't sure about including it.
anArray = this.turns(anArray);//this starts the turn
if((anArray[0][0] == anArray[1][1]) && (anArray[1][1] == anArray[2][2])){
end = 1;
}else if((anArray[0][2] == anArray[1][1]) && (anArray[1][1] == anArray[2][0])){
end = 1;
}else if((anArray[0][0] == anArray[0][1]) && (anArray[0][1] == anArray[0][2])){
end = 1;
}else if((anArray[1][0] == anArray[1][1]) && (anArray[1][1] == anArray[1][2])){
end = 1;
}else if((anArray[2][0] == anArray[2][1]) && (anArray[2][1] == anArray[2][2])){
end = 1;
}else if((anArray[0][0] == anArray[1][0]) && (anArray[1][0] == anArray[2][0])){
end = 1;
}else if((anArray[0][1] == anArray[1][1]) && (anArray[1][1] == anArray[2][1])){
end = 1;
}else if((anArray[0][2] == anArray[1][2]) && (anArray[1][2] == anArray[2][2])){
end = 1;
}else{
end = 0;
}//this checks for possible victories that could have been made during the last turn
t++; //starts the next cycle over again
}
end = 1; //once all the turns are exhausted, the game ends
if(end == 1){
aView.println("The game is finished!");
System.exit(0);
}
}
을 기능을 포함
편집 : 마지막에 exit 함수를 추가하고 두 번째 while 루프 문제 (더 이상 t> 4)를 수정했습니다.
내가 있음을 누락 바보 같은 느낌,하지만 난 그것을 테스트 후, 내가있어 코드가 점점 가늘어지고 끝내기를 거부하는 똑같은 문제. 나는 심지어 System.exit (0)을 추가하려고 시도했다. [예제에서 추가 할 것이다] 그리고 그것을 변경하지 않았다. –
회전을 붙이고 함수를 초기화 할 수 있겠는가? 그게 "테이퍼"라는게 무슨 소리 야? –
턴을 게시하고 기능을 초기화하면 적어도 50 줄의 코드를 제공해야합니다. 내가 생각하는 어떤 것이 옳지 않습니다. 아마도 나는 그것을 서둘러야 할까? 테이퍼로, 내 말은,이 말은 : 나의 맥 터미널을 사용하여 코드를 실행한다. 일반적으로 코드가 끝나면 기본 줄 ~ Java [insert name here]로 돌아갑니다. 대신 코드가 여전히 "활성화되어"있지만 아무 일도 일어나지 않고 화면에 표시됩니다. 입력하고 입력하고 아무 것도 입력하지 마십시오. –