-
Notifications
You must be signed in to change notification settings - Fork 0
/
playTicTacToe.java
68 lines (64 loc) · 1.57 KB
/
playTicTacToe.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
68
import java.util.Scanner;
//Ken Schroeder
// August 2nd, 2015, 1101
// Starbucks, 5th Ave Portland, OR
// TicTacToe
// PlayTicTacToe.java
public class playTicTacToe {
static String YES = "y";
static CPUPlayer CPU;
static int[] rowCol = new int[2];
public static void main(String[] args){
ticTacToe game = new ticTacToe();
CPU = new CPUPlayer(game);
game.welcome();
Scanner console = new Scanner(System.in);
int piece;
String yn = YES;
int row;
int col;
boolean won = false;
boolean another = true;
while(another){
while(!won){
System.out.println("\n\n");
game.displayBoard();
if(game.getTurn() == game.getXMove()){
piece = game.getXMove();
System.out.println("\nPlease enter which row you'd like to use: ");
row = console.nextInt();
System.out.println("\nPlease enter which column you'd like to use: ");
col = console.nextInt();
System.out.println("\n\n");
game.placePiece(game.getTurn(), row,col);
won = game.gameOver(piece);
if (game.isWinner()){
System.out.println("You've won!");
}
}
else{
piece = game.getOMove();
CPU.getMove();
won = game.gameOver(piece);
if (game.isWinner()){
System.out.println("The Computer won :(");
}
}
}
game.gameStats();
game.displayBoard();
System.out.print("Would you like to play another? [y/n]: ");
yn = console.next();
if(yn.equals(YES)){
game.resetBoard();
won = false;
}else{
another = false;
game.displayBoard();
game.gameStats();
}
}
game.goodBye();
console.close();
}
}