-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGame.java
77 lines (67 loc) · 2.1 KB
/
Game.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
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
76
77
import java.io.*;
/**
* Game class that catches null exceptions during the declaration of
* player names at the start of the game and appoints the referee class
* to run the game
*/
public class Game implements Constants {
private Board theBoard;
private Referee theRef;
/**
* Constructor that initializes an instance of the game board
*/
public Game( ) {
setTheBoard(new Board());
}
/**
* Method to appoint referee class, and run the game through
* that class
* @param r: represents referee object
* @throws IOException checks null value
*/
public void appointReferee(Referee r) throws IOException {
theRef = r;
theRef.runTheGame();
}
/**
* Assigns values to players and ref, and receives user inputs
* for player names. Also assigns the predefined constants
* in the Constant class to each character to set up the game initially
* @param args: includes arguments like referee, players, and game state
* @throws IOException checks null value
*/
public static void main(String[] args) throws IOException {
Referee theRef;
Player xPlayer, oPlayer;
BufferedReader stdin;
Game theGame = new Game();
stdin = new BufferedReader(new InputStreamReader(System.in));
System.out.print("\nPlease enter the name of the \'X\' player: ");
String name= stdin.readLine();
while (name == null) {
System.out.print("Please try again: ");
name = stdin.readLine();
}
xPlayer = new Player(name, LETTER_X);
xPlayer.setBoard(theGame.getTheBoard());
System.out.print("\nPlease enter the name of the \'O\' player: ");
name = stdin.readLine();
while (name == null) {
System.out.print("Please try again: ");
name = stdin.readLine();
}
oPlayer = new Player(name, LETTER_O);
oPlayer.setBoard(theGame.getTheBoard());
theRef = new Referee();
theRef.setBoard(theGame.getTheBoard());
theRef.setoPlayer(oPlayer);
theRef.setxPlayer(xPlayer);
theGame.appointReferee(theRef);
}
public Board getTheBoard() {
return theBoard;
}
public void setTheBoard(Board theBoard) {
this.theBoard = theBoard;
}
}