-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApp.java
More file actions
75 lines (65 loc) · 2.55 KB
/
App.java
File metadata and controls
75 lines (65 loc) · 2.55 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import ticatactoe.Board;
import ticatactoe.BoardRepository;
import ticatactoe.MoveRepository;
public class App {
public static void main(String[] args) throws Exception {
BoardRepository boardRepository = new BoardRepository();
MoveRepository moveRepository = new MoveRepository();
Board board = new Board();
boardRepository.render(board);
boolean gameResult = false;
while (gameResult == false) {
boolean validMoveResult = false;
int moveXY = 0;
int moveXX = 0;
while (validMoveResult == false) {
moveXY = moveRepository.getMove("X", "Y");
moveXX = moveRepository.getMove("X", "X");
validMoveResult = moveRepository.validateMove(board, moveXY, moveXX);
if (validMoveResult == false) {
System.out.println("");
System.out.println("Invalid move, try again");
System.out.println("");
}
}
board = moveRepository.makeMove(board, moveXY, moveXX, "X");
boardRepository.render(board);
gameResult = boardRepository.getWinner(board, "X");
if (gameResult == true) {
System.out.println("X wins");
return;
}
gameResult = boardRepository.anyMoveLeft(board);
if (gameResult == true) {
System.out.println("Draw");
return;
}
validMoveResult = false;
int moveOY = 0;
int moveOX = 0;
while (validMoveResult == false) {
moveOY = moveRepository.getMove("O", "Y");
moveOX = moveRepository.getMove("O", "X");
validMoveResult = moveRepository.validateMove(board, moveOY, moveOX);
if (validMoveResult == false) {
System.out.println("");
System.out.println("Invalid move, try again");
System.out.println("");
}
}
board = moveRepository.makeMove(board, moveOY, moveOX, "O");
gameResult = boardRepository.getWinner(board, "O");
boardRepository.render(board);
if (gameResult)
{
System.out.println("O wins");
return;
}
gameResult = boardRepository.anyMoveLeft(board);
if (gameResult) {
System.out.println("Draw");
return;
}
}
}
}