Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Tic-Tac-Toe Using GUI in java Project Description The goal of this project is to test your ability to use the knowledge of Java that you
Tic-Tac-Toe Using GUI in java
Project Description
The goal of this project is to test your ability to use the knowledge of Java that you have
obtained in the course. The focus of this project is to use Graphical User Interface (GUI)
together with object-oriented programming. The goal is to create a tic-tac-toe game based
on a well-designed interface. The user will be playing against a computer opponent that will
pick an open spot on the board.
It is worth noting that you should respect the following decomposition of
classes and methods together with their appropriate graphical user interface.
Any project doesn`t follow the below decomposition of classes/methods will be
rejected.
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.
iv. The computer opponent should then randomly choose an open spot on the
board.
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.
Dr. Ahmad Ahmad-Kassem Fall 2023
2
1.2 Details
The board should be represented by an array of buttons.
The computers moves should be completely random at the least. If you want to do
more intellegent move making, you may recieve extra points.
In my example, the user goes first. If you want to randomly select which player goes
first, this is also acceptable and will get you bonus points.
All the normal rules to tic-tac-toe apply to this game. If you do not know the rules of
tic-tac-toe, or have a specific question on the rules, feel free to ask the instructor.
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 player
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. String getHumanMove() - Prompts the user for a move, retreieves
input from the keyboard, and returns it.
Dr. Ahmad Ahmad-Kassem Fall 2023
3
e. String generateComputerMove() - Returns a move randomly
generated.
Concluding Remarks
You may use your own design of objects for this project, but you are required to write at least
two classes as well as a graphical user interface, and your program should follow object-
oriented programming principles. Bonus points will be given if you allow the option for two
computer players to play each other, two human players to play each other, a human going
first against a computer player, or a human going second against a computer player.
Your program should be easy to use and understand. I highly suggest giving the user
instructions when the program starts and gently reminding her when she inputs something
invalid. You are required to have sufficient internal documentation for your program as
discussed in class.
This is meant to be AN INDIVIDUAL ASSIGNMENT. Also, taking large segments of code
from other sources without citing is plagiarism. The majority of this assignment should be
YOUR OWN ORIGINAL WORK.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started