-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtictactoe.java
67 lines (53 loc) · 1.53 KB
/
tictactoe.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import java.util.Scanner;
import java.util.Arrays;
class tictactoe {
ticBoard boardToPlayOn = new ticBoard();
AITic computer = new AITic();
String playerPiece;
String computerPiece;
public void boardOutput() {
Scanner input = new Scanner(System.in);
for (String[] row : boardToPlayOn.ticTacToeBoard) {
System.out.println(Arrays.toString(row));
}
}
public void gameStart() {
while (computer.winner == false) {
Scanner input = new Scanner(System.in);
boardOutput();
System.out.println("Choose the row: ");
int row = input.nextInt();
System.out.println("\nChoose the column: ");
int column = input.nextInt();
boardToPlayOn.setterFunc(row, column, this.playerPiece);
computer.checker(this.boardToPlayOn.ticTacToeBoard, this.playerPiece);
}
if (computer.winner = true) {
boardOutput();
}
}
public void pieceSelection() {
if ((this.playerPiece).equals("X")) {
computer.piece = "O";
gameStart();
} else {
computer.piece = "X";
gameStart();
}
}
public void startGame() {
Scanner input = new Scanner(System.in);
System.out.println("What do you want to play as (X/O)? ");
this.playerPiece = input.nextLine();
if (!this.playerPiece.equals("X") && !this.playerPiece.equals("O")) {
System.out.println("Invalid input.");
startGame();
} else {
pieceSelection();
}
}
public static void main(String[] args) {
tictactoe newGame = new tictactoe();
newGame.startGame();
}
}