-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGame.java
More file actions
56 lines (46 loc) · 1.67 KB
/
Game.java
File metadata and controls
56 lines (46 loc) · 1.67 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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
public class Game {
private String [][] board = {{"-","-","-"},{"-","-","-"},{"-","-","-"}};
private int row, collumn, tooty;
private String turn;
private String winner;
public Game() {
row = 0;
collumn = 0;
winner = "";
turn = "X";
tooty = 1;
}
public void change(int rx, int cx) {
row = rx; collumn = cx;
board[row-1][collumn-1] = turn;
if(turn.equals("X")) {turn = "O";} else {turn = "X";}
if(gameEnd()) {
if(winner.equals("X")) {tooty=1;}else if(winner.equals("O")) {tooty=2;}else {tooty=3;}
reset f = new reset();
f.twist(tooty);
}
}
public boolean gameEnd() {
for(int r = 0; r < 3; r++) {
if(board[r][0].equals(board[r][1]) && board[r][0].equals(board[r][2]) && !(board[r][0].equals("-")) && !(board[r][1].equals("-")) && !(board[r][2].equals("-"))){
winner = board[r][0];
return true;
}
if(board[0][r].equals(board[1][r]) && board[0][r].equals(board[2][r]) && !(board[0][r].equals("-")) && !(board[1][r].equals("-")) && !(board[2][r].equals("-"))){
winner = board[0][r];
return true;
}
}
if(board[0][0].equals(board[1][1]) && board[0][0].equals(board[2][2]) && !(board[0][0].equals("-")) && !(board[1][1].equals("-")) && !(board[2][2].equals("-"))) {winner = board[0][0]; return true;}
if(board[0][2].equals(board[1][1]) && board[0][2].equals(board[2][0]) && !(board[0][2].equals("-")) && !(board[1][1].equals("-")) && !(board[2][0].equals("-"))) {winner = board[0][2]; return true;}
for(int r = 0; r < 3; r++) {
for(int c = 0; c < 3; c++) {
if(board[r][c].equals("-")) {
return false;
}
}
}
winner = "draw";
return true;
}
}