-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMyConnectN.java
More file actions
43 lines (37 loc) · 1.05 KB
/
MyConnectN.java
File metadata and controls
43 lines (37 loc) · 1.05 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
public class MyConnectN {
private Board board;
private User user;
private Input input;
private Computer computerOne;
private Computer computerTwo;
private String[] playerNames = { "Player1", "Computer1", "Computer2" };
private char[] playerSymbols = { 'r', 'y', 'b' };
public MyConnectN() {
input = new Input();
playGame();
}
private void prepareGame(int connectN) {
board = new Board(playerSymbols, connectN);
user = new User(board, playerNames, 0);
computerOne = new Computer(board, playerNames, 1);
computerTwo = new Computer(board, playerNames, 2);
}
private void playGame() {
PrintHelper.showFirstMsg();
int connectN = input.getConnectNInput();
prepareGame(connectN);
board.printBoard();
String winnerName = "";
Player[] playerTurnOrder = { user, computerOne, computerTwo };
while (winnerName == "") {
for (Player player : playerTurnOrder) {
player.putPosition(player);
if (player.hasWinPosition()) {
winnerName = player.getPlayerName();
break;
}
}
}
PrintHelper.showWinMsg(winnerName);
}
}