-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBoardSquare.java
More file actions
77 lines (67 loc) · 1.99 KB
/
BoardSquare.java
File metadata and controls
77 lines (67 loc) · 1.99 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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
/**
* @author John Henry Cooper
* @version 15.0.2
* Includes all methods and properties to construct a BoardSquare object.
* Includes 3 property fields, an overloaded constructor, accessor and mutator methods,
* and an overridden toString method
*/
public class BoardSquare {
protected boolean empty;
protected Piece piece;
protected String squareColor;
/**
* One-parameter constructor for a BoardSquare object
* @param squareColor String squareColor
*/
public BoardSquare(String squareColor){
this.squareColor = squareColor;
empty = true;
}
public Piece getPiece(){
return this.piece;
}
public boolean isEmpty(){
return this.empty;
}
public String getSquareColor(){
return this.squareColor;
}
/**
* sets the piece property of a BoardSquare object and updates the
* empty property to false
* @param piece Piece
*/
public void setPiece(Piece piece){
this.piece = piece;
this.empty = false;
}
/**
* Removes the piece property of a BoardSquare object, updates
* empty to true, and returns the piece that was removed
* @return Piece temp
*/
public Piece removePiece(){
Piece temp = this.piece;
this.piece = null;
this.empty = true;
return temp;
}
/**
* Overridden string method that returns "-------" if the BoardSquare is empty
* or returns the super toString of the piece if the BoardSquare is occupied
* @return String message
*/
@Override
//Extra Modification
public String toString(){
if (this.piece == null){
if (this.squareColor == "Blue"){
return "■■■■■■■";
}
if (this.squareColor == "Yellow"){
return "□□□□□";
}
}
return "-" + this.piece.toString() + "-";
}
}