不懂得地方在于不知道user每次输入后那九个数怎么变,求大神解答!!!! Write a Java program that will allow two users to play Tic-Tac-Toe. If you are not familiar with the game refer to the following website for a description: http://en.wikipedia.org/wiki/Tic-tac-toe. Your program should loop as long as the players want to play. Your program keeps track of the total number of games played, as well as the number of games won by each player. The program should: 1) At the beginning of a game display a clean board and prompt player X for the position (from 1 to 9) s/he wishes to mark. The program should make sure that the position entered is a valid position (between 1 and 9). If it is not, the program should prompt the user for a position number until a valid one has been entered. 1 2 3 4 5 6 7 8 9 Player X – Enter the position number you wish to mark: 2) After each move the program displays the changed board and whether there is a winner. “The player who succeeds in placing three respective marks in a horizontal, vertical or diagonal row wins the game” (http://en.wikipedia.org/wiki/Tic-tac-toe). If there is no winner yet, prompt the next player for his/her position. The program should make sure that the position entered is a valid position (between 1 and 9) and that it is unmarked. If it is not, the program should prompt the user for a position number until a valid one has been entered. This continues until there is a winner or the board is full. O 2 X 4 5 6 7 8 9 There is no winner yet! Player O – Enter the position number you wish to mark: 1 That position is not available Player O – Enter the position number you wish to mark: 0 That is not a valid position – must be between 1 and 9 inclusive Player O – Enter the position number you wish to mark: 3) If there is a winner, the program congratulates the winner and reports the total number of games played to date as well as the number of games each player has won: O 2 X 4 X 6 X 8 O --> We have a winner! Congratulations Player X <-- Games played to date 6; Player X has won 1 game(s); Player O has won 2 game(s). 4) If the board is full with no winner, the program sends a message indicating that it is a tie game as well as the total number of games played to date and the number of games won by each player: O O X X O X O X O This game is a tie Games played to date 7; Player X has won 1 game; Player O has won 2 games. 5) When a game is over, the program asks if the players wish to play another game. a) if yes, the board is reset and a new game is played (back to Step 1) b) if no, your program should display the total number of games played, the number of games won by each player, the percentage of games won by each player and the grand champion. Total number of games played 10 Player X has won 3 (30%) games; Player O has won 5 (50%) games. The grand champion is player O!!!
添加回答
举报
0/150
提交
取消