-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHumanPlayer.java
44 lines (35 loc) · 1019 Bytes
/
HumanPlayer.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
/* Skeleton Copyright (C) 2015, 2020 Paul N. Hilfinger and the Regents of the
* University of California. All rights reserved. */
package loa;
/** A Player that prompts for moves and reads them from its Game.
* @author Heming Wu
*/
class HumanPlayer extends Player {
/** A new HumanPlayer with no piece or controller (intended to produce
* a template). */
HumanPlayer() {
this(null, null);
}
/** A HumanPlayer that plays the SIDE pieces in GAME. It uses
* GAME.getMove() as a source of moves. */
HumanPlayer(Piece side, Game game) {
super(side, game);
}
@Override
String getMove() {
Game cGame = getGame();
if (cGame.fromCommand()) {
return cGame.readLine(true);
} else {
return cGame.readLine(false);
}
}
@Override
Player create(Piece piece, Game game) {
return new HumanPlayer(piece, game);
}
@Override
boolean isManual() {
return true;
}
}