Can someone help me what I am doing wrong with this code?
-
Hey Guys, I am making a TicTacToe Game in Java and I am having someone difficulty figuring out what I am doing Wrong.
-
I made a tic tic toe board which look something like this.
Hide Copy Code
System.out.println(" | | );
System.out.println( 0 | 1 | 2 );
System.out.println( | | );
System.out.println( -------------------------------);
System.out.println( | | );
System.out.println( 3 | 4 | 5 );
System.out.println( | | );
System.out.println( -------------------------------);
System.out.println( | | );
System.out.println( 6 | 7 | 8 );
System.out.println( | | ); -
I asked the user for a number between 0-8 and the number they choose will be Replaced by X.
Say they choose number 5. This is how it will look like.
Hide Copy Code
System.out.println(" | | );
System.out.println( 0 | 1 | 2 );
System.out.println( | | );
System.out.println( -------------------------------);
System.out.println( | | );
System.out.println( 3 | 4 | X );
System.out.println( | | );
System.out.println( -------------------------------);
System.out.println( | | );
System.out.println( 6 | 7 | 8 );
System.out.println( | | );- I don't know how to create a loop which will keep asking the user for a number until it reaches to all the 8 numbers. Also, how do I check if the number is taken or not.
IT WILL BE GREAT IF YOU CAN HELP ME.
-
-
Hey Guys, I am making a TicTacToe Game in Java and I am having someone difficulty figuring out what I am doing Wrong.
-
I made a tic tic toe board which look something like this.
Hide Copy Code
System.out.println(" | | );
System.out.println( 0 | 1 | 2 );
System.out.println( | | );
System.out.println( -------------------------------);
System.out.println( | | );
System.out.println( 3 | 4 | 5 );
System.out.println( | | );
System.out.println( -------------------------------);
System.out.println( | | );
System.out.println( 6 | 7 | 8 );
System.out.println( | | ); -
I asked the user for a number between 0-8 and the number they choose will be Replaced by X.
Say they choose number 5. This is how it will look like.
Hide Copy Code
System.out.println(" | | );
System.out.println( 0 | 1 | 2 );
System.out.println( | | );
System.out.println( -------------------------------);
System.out.println( | | );
System.out.println( 3 | 4 | X );
System.out.println( | | );
System.out.println( -------------------------------);
System.out.println( | | );
System.out.println( 6 | 7 | 8 );
System.out.println( | | );- I don't know how to create a loop which will keep asking the user for a number until it reaches to all the 8 numbers. Also, how do I check if the number is taken or not.
IT WILL BE GREAT IF YOU CAN HELP ME.
You have already posted this in QA, and received an answer: Can someone help me what I am doing wrong with this code?[^]
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer
-
-
Hey Guys, I am making a TicTacToe Game in Java and I am having someone difficulty figuring out what I am doing Wrong.
-
I made a tic tic toe board which look something like this.
Hide Copy Code
System.out.println(" | | );
System.out.println( 0 | 1 | 2 );
System.out.println( | | );
System.out.println( -------------------------------);
System.out.println( | | );
System.out.println( 3 | 4 | 5 );
System.out.println( | | );
System.out.println( -------------------------------);
System.out.println( | | );
System.out.println( 6 | 7 | 8 );
System.out.println( | | ); -
I asked the user for a number between 0-8 and the number they choose will be Replaced by X.
Say they choose number 5. This is how it will look like.
Hide Copy Code
System.out.println(" | | );
System.out.println( 0 | 1 | 2 );
System.out.println( | | );
System.out.println( -------------------------------);
System.out.println( | | );
System.out.println( 3 | 4 | X );
System.out.println( | | );
System.out.println( -------------------------------);
System.out.println( | | );
System.out.println( 6 | 7 | 8 );
System.out.println( | | );- I don't know how to create a loop which will keep asking the user for a number until it reaches to all the 8 numbers. Also, how do I check if the number is taken or not.
IT WILL BE GREAT IF YOU CAN HELP ME.
Why are you constantly posting same question in two different forums? I have already posted the answer to your problem on your question, Can someone help me what I am doing wrong with this code?[^]. Read that thread.
The shit I complain about It's like there ain't a cloud in the sky and it's raining out - Eminem ~! Firewall !~
-
-
Hey Guys, I am making a TicTacToe Game in Java and I am having someone difficulty figuring out what I am doing Wrong.
-
I made a tic tic toe board which look something like this.
Hide Copy Code
System.out.println(" | | );
System.out.println( 0 | 1 | 2 );
System.out.println( | | );
System.out.println( -------------------------------);
System.out.println( | | );
System.out.println( 3 | 4 | 5 );
System.out.println( | | );
System.out.println( -------------------------------);
System.out.println( | | );
System.out.println( 6 | 7 | 8 );
System.out.println( | | ); -
I asked the user for a number between 0-8 and the number they choose will be Replaced by X.
Say they choose number 5. This is how it will look like.
Hide Copy Code
System.out.println(" | | );
System.out.println( 0 | 1 | 2 );
System.out.println( | | );
System.out.println( -------------------------------);
System.out.println( | | );
System.out.println( 3 | 4 | X );
System.out.println( | | );
System.out.println( -------------------------------);
System.out.println( | | );
System.out.println( 6 | 7 | 8 );
System.out.println( | | );- I don't know how to create a loop which will keep asking the user for a number until it reaches to all the 8 numbers. Also, how do I check if the number is taken or not.
IT WILL BE GREAT IF YOU CAN HELP ME.
public class tictok {
private int OO = 1; private int XX = -1; public int arr\[\] = new int\[10\]; public int getArrPos(int i,int j) { if (i==1) { return j == 4?1:j==15?2:j==26?3:-1; } if (i==5) { return j == 4?4:j==15?5:j==26?6:-1; } if (i==9) { return j == 4?7:j==15?8:j==26?9:-1; } return -1; } public void printMap() { for(int i=0;i<11;i++) { for(int j=0;j<32;j++) { if (i==3 || i==7) { System.out.print("-"); continue; } if (j==10 || j==21) { System.out.print("|"); continue; } if(getArrPos(i, j)!=-1){ if (arr\[getArrPos(i, j)\]== OO) { System.out.print("O"); }else if (arr\[getArrPos(i, j)\]==XX) { System.out.print("X"); }else { System.out.print(getArrPos(i, j)); } continue; } System.out.print(" "); } System.out.println(); } } public void play(int n,boolean isO) { if (n>9) { System.out.println("silly B"); return; } arr\[n\]= isO?1:-1; } public static void main(String\[\] args) { tictok tt = new tictok(); tt.play(8, true); tt.play(6, false); tt.printMap(); }
}
is it useful?
-