-
Notifications
You must be signed in to change notification settings - Fork 10
/
Space.java
67 lines (56 loc) · 1.51 KB
/
Space.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import javafx.scene.control.Button;
import javafx.scene.image.ImageView;
public class Space extends Button
{
private int x;
private int y;
private Piece piece; // piece currently on space
public Space(boolean light, int x, int y)
{
super();
this.x = x;
this.y = y;
this.piece = null;
this.getStyleClass().add("chess-space");
if (light)
this.getStyleClass().add("chess-space-light");
else
this.getStyleClass().add("chess-space-dark");
}
// returns true if space is occupied
public boolean isOccupied()
{
return (this.piece != null);
}
// removes piece from space
public Piece releasePiece()
{
Piece tmpPiece = this.piece;
setPiece(null);
return tmpPiece;
}
public Piece getPiece()
{
return this.piece;
}
// Sets the piece, draws image of piece on space
public void setPiece(Piece piece)
{
this.piece = piece;
if (this.piece != null)
this.setGraphic( new ImageView ( piece.getImage() ) );
else
this.setGraphic( new ImageView() );
}
public String getPieceColor()
{
if (getPiece() != null)
return getPiece().getColor();
else // space empty
return "";
}
public void setX(int xIn) {this.x = xIn;}
public int getX() {return this.x;}
public void setY(int yIn) {this.y = yIn;}
public int getY() {return this.y;}
}