If you want the source code you can download it from Releases or use git
:
git clone https://github.com/SkillSageDev/TicTacToe.git
- then run TicTacTio.exe to start playing
If you only want the game, (the .exe file), you can download it from here.
-
ask player if they wanna play or no.
-
if he choosed to play, the game asks him to choose a symbol, he can only choose 'x' or 'o'.
-
print the board and asks player to choose a number.
for examble: if player choosed 1, the board will change number 1 in the board to the player's symbol, then it will ask player 2 to pick a number
-
the game loops until win or draw happen, then asks player if they wanna restart the game, or quit the game.
you can check it out from here also.
main task: creat, print, and update the board.
- get the player input using
Scanner
class.
- one dimensional array that stores numbers from (1-9) as a char.
- creat a new board.
- print the board using for loop.
- make sure that there is no symbol in the given index.
-
the player picks a number to place his symbol, that number will be stored in
choice
variable. -
symbol
stores player's symbol. -
update the board according to
choice
&symbol
ifisValidMove(choice) == true
.
main task: creat players with different symbols.
- get the player input using
Scanner
class.
- a char variable that stores the player's symbol (x or o).
-
asks the player to choose a symbol, player can only choose (x or o).
-
return
symbol
.
main task: asks player to start, restart, quit the game.
- get the player input using
Scanner
class.
main task: loop the game until win or draw.
- get the player input using
Scanner
class.
- objects from class
Player
.
- list that stores
p1
&p2
.
- an object from class
Menu
.
- an object from class
Board
.
- int variable that stores 0 or 1 to indicate player's turn.
-
runs
board.creatBoard()
to print the board. -
runs
playGame()
method.
-
it change currentPlayer to 1 or 0 by this equation
currentPlayer = 1 - currentPlayer
-
so if
currentPlayer = 0
when you invokeswitchPlayer()
it will becurrentPlayer = 1 - 0
which is 1. -
if you invoked
switchPlayer()
againcurrentPlayer = 1 - 1
which is 0.
-
asks player to pick a number must be from (1-9), then start an infinit loop.
-
start a try
- runs
input.nextInt()
and stores it in anint
variable calledchoice
- checks if
board.updateBoard(choice, players[currentPlayer].symbol) == true
, - if it is
true
it will break. - if it is
false
it will print invalid move and runboard.updateBoard(choice, players[currentPlayer].symbol)
again.
- runs
-
start a catch
- prints invalid choice because the player didn't enter a number between (1-9).
-
-
it got
int
two diminsial array calledwinConditions
, from the name it stores every possible win condition. -
then runs for each loop
for( : )
to store every condition fromwinConditions
to anint
array calledcondition
.-
checks if
board.board[condition[0]] == board.board[condition[1]] && board.board[condition[1]] == board.board[condition[2]]
.-
lets say in the first for loop
int[] condition = {3,4,5}
which means that ifboard.board[3] == board.board[4] == board.board[5]
someone won! -
and you know that
condition[0] = 3
&condition[1] = 4
&condition[2] = 4
. -
so we do
board.board[condition[0]] == board.board[condition[1]] && board.board[condition[1]] == board.board[condition[2]]
to achieve the same result asboard.board[3] == board.board[4] == board.board[5]
.
-
-
return
true
if they are equal. -
return
false
if they are not equal.
-
- runs for each loop
for( : )
inboard.board
and store every char in the board toc
variable. - return
true
ifwinCheck() = false
&c
is a symbol. - return
false
ifwinCheck() = false
&c
is a digit.
-
runs
board.printBoard()
to print the board. -
start an infinit loop
- if
winCheck()
ordrawCheck()
methods equals tofalse
, it will runreplaceSymbol()
&switchPlayer()
methods, then break.
- if
-
start an infinit loop then runs
PlayTurn()
method.-
check if
winCheck()
ordrawCheck()
methods equals totrue
. -
runs
board.printBoard()
to print the board. -
runs
menu.end()
to print end menu and store the return value inchoice
variable. -
then runs another loop to check if
choice == 1
orchoice == 2
only.-
if
choice == 1
it will runrestartGame()
method and set choice to 2,choice = 2
. -
if
choice == 2
it will break twice to get out from first loop and the second loop. -
else runs
menu.end()
to print the end menu and store the input inchoice
variable.
-
-
- runs
players[0].chooseSymbol()
- if
player[0]
choosed 'x' it will setplayer[1]
symbol to 'o' - else it will set
player[1]
symbol to 'x'.
-
runs
menu.main()
that asks player to start or quit game. -
get his input and store it in
choice
variable, then start an infinit loop.-
if
choice == 1
, it runsboard.creatBoard()
to creat a new board, and runssetupPlayers()
&playGame()
methods. -
then set
choice
to 0. -
if
choice == 2
it runsquitGame()
method then break from loop. -
else run
menu.main()
again, then store the input inchoice
.
-
- prints
Thanks for playing!
.