-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPiece.java
More file actions
46 lines (39 loc) · 1.07 KB
/
Copy pathPiece.java
File metadata and controls
46 lines (39 loc) · 1.07 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
package amazons;
/** The contents of a cell on the board.
* @author JaniceNg
*/
enum Piece {
/* EMPTY: empty square. WHITE and BLACK: pieces, SPEAR: a spear. */
EMPTY("-", null), WHITE("W", "White"), BLACK("B", "Black"),
SPEAR("S", null);
/** A Piece whose board symbol is SYMBOL and that is called NAME in
* messages. */
Piece(String symbol, String name) {
_symbol = symbol;
_name = name;
}
@Override
public String toString() {
return _symbol;
}
/** Return the Piece of opposing color, or null if this is not a
* player piece. */
Piece opponent() {
switch (this) {
case WHITE:
return BLACK;
case BLACK:
return WHITE;
default:
return null;
}
}
/** Return my printed form for use in messages. */
String toName() {
return _name;
}
/** The symbol used for the piece in textual board printouts. */
private final String _symbol;
/** The name in used in messages. */
private final String _name;
}