-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBoard.java
More file actions
35 lines (32 loc) · 1.14 KB
/
Copy pathBoard.java
File metadata and controls
35 lines (32 loc) · 1.14 KB
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
public static void main(String[] args) {
char[][] gameBoard = {
{' ','|',' ','|',' '},
{'-','+','-','+','-'},
{' ','|',' ','|',' '},
{'-','+','-','+','-'},
{' ','|',' ','|',' '}
};
printGameBoard(gameBoard);
while(true){
Scanner sc = new Scanner(System.in);
System.out.println("Play Your Move (1-9):");
int playerPos = sc.nextInt();
while(playerPositions.contains(playerPos)|| PCPositions.contains(playerPositions)){
System.out.println("Position taken! Enter a correct Position");
}
placePiece(gameBoard,playerPos,"player");
Random rd = new Random();
int PCpos = rd.nextInt(9)+1;
while(playerPositions.contains(PCpos)|| PCPositions.contains(PCpos)){
System.out.println("Position taken! Enter a correct Position");
PCpos = rd.nextInt(9)+1;
}
placePiece(gameBoard,PCpos,"PC");
printGameBoard(gameBoard);
result = checkWinner();
if(result.length()>0){
System.out.println(result);
break;
}
}
}