// play game until game Over is true start with player 'X' while (!gameOver) { // get current player choice, and update board value // display the updated board // switch player 'X' -> '0' or '0' -> 'X' // check for winner, draw or game is not over yet } tasks: =========== You need to complete the following methods receiveUserChoice () isGameOver()

EBK JAVA PROGRAMMING
9th Edition
ISBN:9781337671385
Author:FARRELL
Publisher:FARRELL
Chapter9: Advanced Array Concepts
Section: Chapter Questions
Problem 19RQ
icon
Related questions
icon
Concept explainers
Question

Tic tac game in JAVA

Using one dimensional array to implement Tic-Tac-Toe Game.
Tic-Tac-Toe Game Outline:
=========
// play game until game Over is true
start with player 'X'
while (!gameOver) {
// get current player choice, and update board value
// display the updated board
=======
// switch player 'X' -> '0' or '0' -> 'X'
// check for winner, draw or game is not over yet
}
tasks:
===========
You need to complete the following methods
receiveUserChoice ()
isGameOver()
Transcribed Image Text:Using one dimensional array to implement Tic-Tac-Toe Game. Tic-Tac-Toe Game Outline: ========= // play game until game Over is true start with player 'X' while (!gameOver) { // get current player choice, and update board value // display the updated board ======= // switch player 'X' -> '0' or '0' -> 'X' // check for winner, draw or game is not over yet } tasks: =========== You need to complete the following methods receiveUserChoice () isGameOver()
write a program that will allow two users to play
tic-tac-toe. The program should ask for moves alternately from player X and player O. The program displays the game
positions as follows:
1
1
4
7
4
1
4
7
4
1
7
1
X's turn (enter position number):
Once X enters (in this case 2), then the board displays X at that position and asks for next input (from O):
1
3
2
4
5
4
8
7
4
7
X
5
8
7
Your program should check if the user entered a valid position. A position can be invalid if:
1)
User enters a number less than 1 or greater than 10 i.e., the position number does not exist
2) A user has already selected the position. For example in the above case, selecting 2 would be invalid after X's
move because X selected 2 in the first round.
X
5
O's turn (enter position number):
The player O enters 3, then it will show like below;
1
In both these cases, the program should ask the user to enter a valid position. For example, say you have this
board:
8
X
5
7 8
8
X
X
3
X's turn (enter position number): 2
Invalid position. Enter a valid position.
X's turn (enter position number):
6
X
9
X
6
9
X
X
O
X
6
9
Program ends when there is no place to enter, or a winner is decided. A winner is someone who has 3 places
in a row (horizontally, vertically, or diagonally). Your program should check if there is a winner after each user's
input and announces a winner when it detects one.
O's turn (enter position number):
0
6
9
O
6
X's turn (enter position number): 8
9
8 9
0
O
0
6
9
***** X WINS !!! *****
Transcribed Image Text:write a program that will allow two users to play tic-tac-toe. The program should ask for moves alternately from player X and player O. The program displays the game positions as follows: 1 1 4 7 4 1 4 7 4 1 7 1 X's turn (enter position number): Once X enters (in this case 2), then the board displays X at that position and asks for next input (from O): 1 3 2 4 5 4 8 7 4 7 X 5 8 7 Your program should check if the user entered a valid position. A position can be invalid if: 1) User enters a number less than 1 or greater than 10 i.e., the position number does not exist 2) A user has already selected the position. For example in the above case, selecting 2 would be invalid after X's move because X selected 2 in the first round. X 5 O's turn (enter position number): The player O enters 3, then it will show like below; 1 In both these cases, the program should ask the user to enter a valid position. For example, say you have this board: 8 X 5 7 8 8 X X 3 X's turn (enter position number): 2 Invalid position. Enter a valid position. X's turn (enter position number): 6 X 9 X 6 9 X X O X 6 9 Program ends when there is no place to enter, or a winner is decided. A winner is someone who has 3 places in a row (horizontally, vertically, or diagonally). Your program should check if there is a winner after each user's input and announces a winner when it detects one. O's turn (enter position number): 0 6 9 O 6 X's turn (enter position number): 8 9 8 9 0 O 0 6 9 ***** X WINS !!! *****
Expert Solution
steps

Step by step

Solved in 4 steps with 8 images

Blurred answer
Knowledge Booster
Control Structure
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT