-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBoardSpace.java
More file actions
137 lines (128 loc) · 2.97 KB
/
Copy pathBoardSpace.java
File metadata and controls
137 lines (128 loc) · 2.97 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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
public class BoardSpace{
private Checker data;
private BoardSpace above;
private BoardSpace below;
private BoardSpace right;
private BoardSpace left;
private boolean isDark;
private int upLeftX;
private int upLeftY;
public BoardSpace(Checker data, BoardSpace above, BoardSpace below,BoardSpace right,BoardSpace left,String shade,int xCoord, int yCoord){
this.data=data;
this.above=above;
this.below=below;
this.right=right;
this.left=left;
if(shade!=null){
if(shade.toLowerCase().equals("dark")){
isDark=true;
}else{
isDark=false;
}
}else{
//default set to dark, will correct if necessary
isDark=true;
}
upLeftX=xCoord;
upLeftY=yCoord;
}
public BoardSpace(){
this(null,null,null,null,null,null,0,0);
}
//getters
public BoardSpace getAbove(){
return above;
}
public BoardSpace getBelow(){
return below;
}
public BoardSpace getRight(){
return right;
}
public BoardSpace getLeft(){
return left;
}
public Checker getChecker(){
return data;
}
public int getXCoord(){
return upLeftX;
}
public int getYCoord(){
return upLeftY;
}
public boolean isDark(){
return isDark;
}
public boolean isLight(){
return !isDark;
}
public boolean isOccupied(){
if(data!=null){
return true;
}else{
return false;
}
}
//setters
public void setAbove(BoardSpace toSet){
above=toSet;
if (toSet!=null) toSet.setBelow(this,"stop");
}
public void setBelow(BoardSpace toSet){
below=toSet;
if (toSet!=null) toSet.setAbove(this,"stop");
}
private void setBelow(BoardSpace toSet, String stop){
below=toSet;
}
private void setAbove(BoardSpace toSet, String stop){
above=toSet;
}
public void setRight(BoardSpace toSet){
right=toSet;
if(toSet!=null) toSet.setLeft(this,"stop");
}
public void setLeft(BoardSpace toSet){
left=toSet;
if(toSet!=null) toSet.setRight(this,"stop");
}
private void setRight(BoardSpace toSet, String stop){
right=toSet;
}
private void setLeft(BoardSpace toSet, String stop){
left=toSet;
}
public void setDark(){
isDark=true;
}
public void setLight(){
isDark=false;
}
public void setOccupied(Checker resident){
if(data==null||resident==null){
data=resident;
}else{
throw new IllegalArgumentException("This space is already occupied by a "+data.getColor()+" checker");
}
}
public void setCoords(int x,int y){
upLeftY=y;
upLeftX=x;
}
public String toString(){
String toReturn="";
if(data!=null){
toReturn=data.toString();
}else{
toReturn="Empty ";
if(isDark){
toReturn+= "dark ";
}else{
toReturn+= "light ";
}
toReturn+="space";
}
return toReturn;
}
}