Hello, I am doing a project on tictactoe game using java without using arrays or anything else, but listing the win combinations. Although I'm done that, this next part is confusing me and I don't know how to start it. Could you start me up with few lines of code and how to properly execute it?
I am required to this: Option #3 sets every location on the board to 'b' and then inputs the location of players' moves until the letter 'Q' is entered. Then, the board is displayed.
Note: The program should assume that x always goes first
Here's an example of Option #3...
--- Input --- --- Expected output---
3
TL
TR
BR
Q xbo
bbb
bbx
3
TM
MM
BM
TL
BL
Q
oxb
bob
xxb
I will also paste my code and whatever I have so far, and option 3 starts all the way below I have set a boolean and a while statement but idk what to put inside that:
import java.util.Scanner;
public class tictactoe{
public static void main(String[]args){
Scanner keyboard = new Scanner(System.in);
int option = keyboard.nextInt();
String TL = keyboard.next();
String TM = keyboard.next();
String TR = keyboard.next();
String ML = keyboard.next();
String MM = keyboard.next();
String MR = keyboard.next();
String BL = keyboard.next();
String BM = keyboard.next();
String BR = keyboard.next();
if (option == 1){
System.out.print(TL);
System.out.print(TM);
System.out.print(TR);
System.out.print("\n"+ML);
System.out.print(MM);
System.out.print(MR);
System.out.print("\n"+BL);
System.out.print(BM);
System.out.print(BR);
}
else if (option == 2){
System.out.print(TL);
System.out.print(TM);
System.out.print(TR);
System.out.print("\n"+ML);
System.out.print(MM);
System.out.print(MR);
System.out.print("\n"+BL);
System.out.print(BM);
System.out.print(BR);
if (TL.equals(TM) && TL.equals(TR) && TL.equals(TR) && !TL.equals("b")){
System.out.println("\n"+TL +" "+"wins");
}
else if (ML.equals(MM) && ML.equals(MR) && !ML.equals("b")){
System.out.println("\n"+ML +" "+"wins");
}
else if (TL.equals(ML) && TL.equals(BL) && !TL.equals("b")){
System.out.println("\n"+TL +" "+"wins");
}
else if (BL.equals(BM) && BL.equals(BR) && !BL.equals("b")){
System.out.println("\n"+BM +" "+"wins");
}
else if (TM.equals(MM) && TM.equals(BM) && !TM.equals("b")){
System.out.println("\n"+TM +" "+"wins");
}
else if (TR.equals(MM) && TR.equals(BL) && !TR.equals("b")){
System.out.println("\n"+TR +" "+"wins");
}
else if (TR.equals(MR) && TR.equals(BR) && !TR.equals("b")){
System.out.println("\n"+TR +" "+"wins");
}
else if (TL.equals(MM) && TL.equals(BR) && !TL.equals("b")){
System.out.println("\n"+TL +" "+"wins");
}
else{
System.out.println("\n"+"No Winner");
}
}
else if (option == 3){
TL = "b";
TM = "b";
TR = "b";
ML = "b";
MM = "b";
MR = "b";
BL = "b";
BM = "b";
BR = "b";
boolean go = true;
while (go){
}
}
}
}
What I have tried:
The above code is what i tried