so im trying to program a simple tic tac toe program in java that uses 2 dimensional arrays, that also has a simple GUI that looks like whats shown in the image and i wouldnt know where to begin or how to code this. I know stuff like for and while loops, if else statements and the regular syntax so this isnt my first time working for java
#Help with a Java project
1 messages · Page 1 of 1 (latest)
<@&987246399047479336> please have a look, thanks.
cant read the GUI
@dire ridge Hi there!
From my own experience GUI work can get quite frustrating if you get too locked in on it.
So first look to the functionality of the game, even if it's just in the terminal and text based, focus on the rules for taking turns, winning/losing and deciding a draw
the text doesnt matter its more the buttons that are the problem
you just need help with the GUI, or the logic/data representation, or both?
both
for logic, you basically want:
// 0 - unmarked
// 1 - marked with X
// 2 - marked with O
int[3][3] boardState
void mark(int mark, int x, int y);
boolean checkForWinner();
ive seen some people state that java.util.scanner helps a lot with this
I dont see hwo
well i wouldnt even know what scanner is useful for
so
i assume its to scan the board
you'd need a Scanner for input from stdin
since you have a GUI your users input will just be directly from the buttons in the GUI
I dont quite understand your problem, can you ask a specific question? otherwise its hard to help
alright lets start with my first problem i guess
i wouldnt know how to program tictactoe in java
infact i dont even know how to use arrays all too well
so id need help figuring out what to even code
best way to tackle those problems is to break the task down
so for example inorder to play tic tac toe you need a 2D array as already mentioned above
then you need a function that checks if someone has won. So you need to check if any of the combinations (diagonal, horizontal,etc) are given and a player has won
you can do all that without user input first, so just test it with an array you define
then you probably want to create a function that takes an enum/string and places a cross/circle at the given enum/string position
etc
just tiny baby steps, try to break down your problems into small tasks you can tackle individually
and thats all prograamming is really about