-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathChessPiece.java
More file actions
70 lines (56 loc) · 1.44 KB
/
ChessPiece.java
File metadata and controls
70 lines (56 loc) · 1.44 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
// ChessPiece SuperClass, has methods such as returning the type of piece, getting the color, returning the row and column, etc
class ChessPiece {
protected int row;
protected int col;
protected char type = '1';
protected char color = '1';
protected ChessPiece data;
public ChessPiece(int r, int c, char type) {
this.row = r;
this.col = c;
this.color = Character.isLowerCase(type) ? 'w' : 'b'; //defines that lower case is white piece, and upper case is black piece
this.type = type;
this.data = data;
}
//returns type of piece
public char getType() {
return this.type;
}
//returns color of piece
public char getColor() {
return this.color;
}
//returns row of piece
public int getRow() {
return this.row;
}
//returna column of piece
public int getCol() {
return this.col;
}
//stores location of piece (row, col)
public int [] getLocation() {
int [] loc = new int [2];
loc[0] = row;
loc[1] = col;
return loc;
}
public void setLocation(int[] loc) {
this.row = loc[0];
this.col = loc[1];
}
//returns either true or false depending on attacking method for each piece
public boolean isAttacking (ChessPiece p) {
return false;
}
public boolean isValidMove(int[] from, int[] to){
return true;
}
//prints type of piece
public String toString() {
return "" + this.getType() + ": (" + this.getColor() + ") - " + this.getRow() + "," + this.getCol();
}
public ChessPiece getData1(){
return this.data;
}
}