Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a program in Java(Tic-Tac-Toe Using GUI) Program Functionality 1.1 Program Steps 1. Display the current board state (Graphical User Interface). 2. Choose a position

Write a program in Java(Tic-Tac-Toe Using GUI)

Program Functionality

1.1 Program Steps

1. Display the current board state (Graphical User Interface).

2. Choose a position on the board for the users move.

a) If the user enters a position that already has an X or an O, then tell the user that the position is occcupied.

Start over from step 2.

b) If the user enters a valid, unoccupied position, this should be considered the users move.

i. Display the board, now updated with the players move

ii. If the users move results in a win, tell the user that she has won.

Terminate the program.

iii. If the users move results in a tie (cat), tell the user that the game has ended in a tie (cat).

Terminate the program.

v. Display the board, now updated with the computers move

vi. If the computers move results in a win, tell the user that the computer has won.

Terminate the program.

Possible Object Design

1. Board - An object representing a tic-tac-toe board a) Attributes

gameBoard An array of buttons representing the board

b) Methods

i. Constructors

a. Board() - Initializes the board to an empty board

b. Board(JButton [] inBoard) - Initializes the board to inBoard

ii. Accessors

a. boolean submitMove(String move, char player) - adds the move to the board, and returns true if the space specified in the move is not taken. If the space is taken, do not add the move and return false.

b. boolean isWinner(char player) - Returns true if the player whose marker is passed as a parameter has won the game, false otherwise.

c. boolean isCat() - Returns true if there is a CAT(tie), false otherwise

. d. boolean isMoveValid(String move) - Returns true if the parameter is a move on the board, otherwise it returns false

2. Player An object representing a player of the tic-tac-toe game

a) Attributes

char marker - Character representing whether this player is using X or O as her marker

boolean isHuman - Boolean indicating if the player is a human player or a computer playe

b) Methods

i. Constructors

a. Player() - Initializes the marker to X and isHuman to true

b. Player(boolean inIsHuman) - Initializes isHuman to inIsHuman and if inIsHuman is true, marker to X, otherwise marker to O

c. Player(boolean inIsHuman, char inMarker) - Initializes isHuman to inIsHuman and marker to X if inMarker is X or x, otherwise marker to O

ii. Accessors

a. char getMarker() - Returns the players marker

b. boolean getIsHuman() - Returns whether the player is human or not

c. String getPlayerMove() - Returns the move from the player (either from human or computer).

d. StringgetHumanMove() - Prompts the user for a move, retreieves input from the keyboard, and returns it.

e. String generateComputerMove() - Returns a move randomly generated.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Select Healthcare Classification Systems And Databases

Authors: Katherine S. Rowell, Ann Cutrell

1st Edition

0615909760, 978-0615909769

More Books

Students also viewed these Databases questions