-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGrid.java
36 lines (31 loc) · 1.09 KB
/
Grid.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
package com.company;
public class Grid {
// Store the state of the board
String[][] grid = {{" ", " ", " "}, {" ", " ", " "}, {" ", " ", " "}};
boolean endOfGame = false;
boolean p1Turn = true;
boolean validMove;
public void setPosition(int row, int col){
if (!grid[row][col].equals(" ")){
System.out.println("==================\nInvalid move, try again\n==================");
return;
}
String setTo;
if (p1Turn){
setTo = "x";
}
else{
setTo = "o";
}
grid[row][col] = setTo;
p1Turn = !p1Turn;
}
public void printBoard(){
System.out.println(" 1 2 3");
System.out.println("1 " + grid[0][0] + " | " + grid[0][1] + " | " + grid[0][2]);
System.out.println(" =========");
System.out.println("2 " + grid[1][0] + " | " + grid[1][1] + " | " + grid[1][2]);
System.out.println(" =========");
System.out.println("3 " + grid[2][0] + " | " + grid[2][1] + " | " + grid[2][2]);
}
}