-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGUIPlayer.java
63 lines (53 loc) · 1.53 KB
/
GUIPlayer.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
/* Skeleton Copyright (C) 2015, 2020 Paul N. Hilfinger and the Regents of the
* University of California. All rights reserved. */
package loa;
/** A Player that takes input from a GUI.
* @author P. N. Hilfinger
*/
class GUIPlayer extends Player implements Reporter {
/** A new GUIPlayer that takes moves and commands from GUI. */
GUIPlayer(GUI gui) {
this(null, null, gui);
}
/** A new GUIPlayer playing PIECE under control of CONTROLLER, taking
* moves and commands from GUI. */
GUIPlayer(Piece piece, Game controller, GUI gui) {
super(piece, controller);
_gui = gui;
}
@Override
Player create(Piece piece, Game game) {
return new GUIPlayer(piece, game, _gui);
}
@Override
boolean isManual() {
return true;
}
@Override
String getMove() {
while (true) {
String command;
command = getGame().readLine(false);
if (command == null) {
command = _gui.readCommand();
}
Move move = Move.mv(command);
if (move == null || getBoard().isLegal(move)) {
return command;
}
}
}
@Override
public void reportError(String fmt, Object... args) {
_gui.reportError(fmt, args);
}
@Override
public void reportNote(String fmt, Object... args) {
_gui.reportNote(fmt, args);
}
@Override
public void reportMove(Move unused) {
}
/** The GUI I use for input. */
private GUI _gui;
}