Repository navigation
Expand file tree
/
Copy pathPiece.java
More file actions
58 lines (50 loc) · 1.65 KB
/
Copy pathPiece.java
File metadata and controls
58 lines (50 loc) · 1.65 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
import java.awt.Graphics;
public abstract class Piece {
/**
* Indicates this is a black or
* white piece
*/
protected boolean isBlack;
public int X,Y;
/**
* creates a piece
* @param isBlack the piece becomes black if true
*/
public Piece(boolean isBlack){
this.isBlack = isBlack;
}
public boolean getColor(){
return this.isBlack;
}
/**
*
* @return type of the object as a string
*/
public abstract String getName();
/**
* Draws this piece to the screen using the given
* graphics object at the given location on the screen knowing that
* it should fit inside a square with given width.
* @param g graphics object to use
* @param positionX x of the top-left corner of the square
* @param positionY y of the top-left corner of the square
* @param squareWidth width of the square.
*/
public abstract void drawYourself(Graphics g, int positionX, int positionY, int squareWidth);
/**
* indicates whether this piece can move on the board in a single step
* by given x and y values (relative to its current position, not absolute)
* @param x horizontal component of the movement
* @param y vertical component of the movement
* @return true if the piece can move by x and y squares in one step
*/
public abstract boolean canMove(int x, int y);
/**
* indicates whether this piece can capture another piece on the board with
* given x and y values (relative to its current position, not absolute)
* @param x horizontal distance of the piece to capture
* @param y vertical distance of the piece to capture
* @return true if the piece can capture
*/
public abstract boolean canCapture(int x, int y);
}