- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSquare.java
More file actions
Latest commit
58 lines (47 loc) · 1.55 KB
/
Copy pathSquare.java
File metadata and controls
58 lines (47 loc) · 1.55 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
47
48
49
50
51
52
53
54
55
56
57
58
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
packagechess;
publicclassSquare {
privateCoordinatecoordinate;
privatePiecepiece;
publicSquare(Coordinatec) {
this.coordinate = c;
this.piece = null; // No piece is positioned on this square
}
publicSquare(Coordinatec, Piecep) {
this( c );
this.piece = p; // A piece is positioned on this square
}
publicchargetColumn() { returncoordinate.getColumn(); }
publicchargetRow() { returncoordinate.getRow(); }
publicintgetColumnNumber() { returncoordinate.getColumnNumber(); }
publicintgetRowNumber() { returncoordinate.getRowNumber(); }
publicCoordinategetCoordinate() {
returncoordinate;
}
publicPiecegetPiece() {
returnpiece;
}
publicbooleanisOccupied() {
return (piece != null);
}
// Returns previous piece, if the square is currently occupied.
publicPieceaddPiece(PiecenewPiece) {
Pieceprevious = this.piece;
this.piece = newPiece;
returnprevious;
}
publicPiecedeletePiece() {
Pieceprevious = this.piece;
this.piece = null;
returnprevious;
}
@Override
publicStringtoString() {
Stringp = (piece == null) ? " " : piece.toString();
return ("Square"+coordinate.toString()+":"+p);
}
}